From f76e28cb71fd7f45eda35f68c89a6ba151625313 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Sat, 23 Jan 2021 20:03:07 -0800 Subject: ape/libm: add back fmod, remove modf We removed the wrong file. Put it back. --- sys/src/ape/lib/ap/math/fmod.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 sys/src/ape/lib/ap/math/fmod.c (limited to 'sys/src/ape/lib/ap/math/fmod.c') 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 +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; +} -- cgit v1.2.3