diff options
author | Ori Bernstein <ori@eigenstate.org> | 2021-01-23 20:03:07 -0800 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2021-01-23 20:03:07 -0800 |
commit | f76e28cb71fd7f45eda35f68c89a6ba151625313 (patch) | |
tree | e5bc61d6723fb84b87e3f3111dc3820b13768910 /sys/src/ape/lib/ap/math/fmod.c | |
parent | 988bdd05a326687daa1852c9ff395230743b30d8 (diff) |
ape/libm: add back fmod, remove modf
We removed the wrong file. Put it back.
Diffstat (limited to 'sys/src/ape/lib/ap/math/fmod.c')
-rw-r--r-- | sys/src/ape/lib/ap/math/fmod.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/sys/src/ape/lib/ap/math/fmod.c b/sys/src/ape/lib/ap/math/fmod.c new file mode 100644 index 000000000..876c64c39 --- /dev/null +++ b/sys/src/ape/lib/ap/math/fmod.c @@ -0,0 +1,27 @@ +/* floating-point mod function without infinity or NaN checking */ +#include <math.h> +double +fmod (double x, double y) +{ + int sign = 0, yexp; + double r, yfr; + + if (y == 0) + return 0; + if (y < 0) + y = -y; + yfr = frexp (y, &yexp); + if (x < 0) { + sign = 1; + r = -x; + } else + r = x; + while (r >= y) { + int rexp; + double rfr = frexp (r, &rexp); + r -= ldexp (y, rexp - yexp - (rfr < yfr)); + } + if (sign) + r = -r; + return r; +} |