|
|
1.1 ! root 1: /* floating-point mod function without infinity or NaN checking */ ! 2: #include <math.h> ! 3: #include <errno.h> ! 4: ! 5: extern int errno; ! 6: ! 7: double ! 8: fmod (x, y) ! 9: double x, y; ! 10: { ! 11: int sign = 0, yexp; ! 12: double r, yfr, ldexp(), frexp(); ! 13: ! 14: if (y == 0) ! 15: return x; ! 16: ! 17: if (y < 0) ! 18: y = -y; ! 19: ! 20: yfr = frexp (y, &yexp); ! 21: ! 22: if (x < 0) { ! 23: sign = 1; ! 24: r = -x; ! 25: } else ! 26: r = x; ! 27: ! 28: while (r >= y) { ! 29: int rexp; ! 30: double rfr = frexp (r, &rexp); ! 31: r -= ldexp (y, rexp - yexp - (rfr < yfr)); ! 32: } ! 33: ! 34: if (sign) ! 35: r = -r; ! 36: return r; ! 37: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.