diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2021-01-23 15:53:56 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2021-01-23 15:53:56 +0100 |
commit | 6d012d2df00d742329a05aed46f657f439023fee (patch) | |
tree | 01b049f1ab923e7f55fb67d1d52ceac1566d1d76 | |
parent | b5c7158f39e448d70052076b83d04ef22d794e5a (diff) | |
download | plan9front-6d012d2df00d742329a05aed46f657f439023fee.tar.xz |
ape: apply infinite recursion in fmod() fix (thanks jxy and ality)
Apply changeset 2880:cab2b9d13a73 to ape's fmod() implementation.
Remove the unused math/fmod.c copy.
-rw-r--r-- | sys/src/ape/lib/ap/math/fmod.c | 27 | ||||
-rw-r--r-- | sys/src/ape/lib/ap/plan9/frexp.c | 13 |
2 files changed, 11 insertions, 29 deletions
diff --git a/sys/src/ape/lib/ap/math/fmod.c b/sys/src/ape/lib/ap/math/fmod.c deleted file mode 100644 index 876c64c39..000000000 --- a/sys/src/ape/lib/ap/math/fmod.c +++ /dev/null @@ -1,27 +0,0 @@ -/* 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; -} diff --git a/sys/src/ape/lib/ap/plan9/frexp.c b/sys/src/ape/lib/ap/plan9/frexp.c index 0d81f52c7..2e814dd19 100644 --- a/sys/src/ape/lib/ap/plan9/frexp.c +++ b/sys/src/ape/lib/ap/plan9/frexp.c @@ -73,6 +73,16 @@ modf(double d, double *ip) Cheat x; int e; + x.d = d; + e = (x.ms >> SHIFT) & MASK; + if(e == MASK){ + *ip = d; + if(x.ls != 0 || (x.ms & 0xfffffL) != 0) /* NaN */ + return d; + /* ±Inf */ + x.ms &= 0x80000000L; + return x.d; + } if(d < 1) { if(d < 0) { f = modf(-d, ip); @@ -82,8 +92,7 @@ modf(double d, double *ip) *ip = 0; return d; } - x.d = d; - e = ((x.ms >> SHIFT) & MASK) - BIAS; + e -= BIAS; if(e <= SHIFT+1) { x.ms &= ~(0x1fffffL >> e); x.ls = 0; |