Mercurial > cpython-lru_cache-weakref
annotate Python/fmod.c @ 6:fc6fcd7df4f7 legacy-trunk
Initial revision
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sun, 14 Oct 1990 12:07:46 +0000 |
| parents | |
| children | 853b736a6a9e |
| rev | line source |
|---|---|
| 6 | 1 /* Portable fmod(x, y) implementation for systems that don't have it */ |
| 2 | |
| 3 #include <math.h> | |
| 4 #include <errno.h> | |
| 5 | |
| 6 extern int errno; | |
| 7 | |
| 8 double | |
| 9 fmod(x, y) | |
| 10 double x, y; | |
| 11 { | |
| 12 double i, f; | |
| 13 | |
| 14 if (y == 0.0) { | |
| 15 errno = EDOM; | |
| 16 return 0.0; | |
| 17 } | |
| 18 | |
| 19 /* return f such that x = i*y + f for some integer i | |
| 20 such that |f| < |y| and f has the same sign as x */ | |
| 21 | |
| 22 i = floor(x/y); | |
| 23 f = x - i*y; | |
| 24 if ((x < 0.0) != (y < 0.0)) | |
| 25 f = f-y; | |
| 26 return f; | |
| 27 } |
