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.
This commit is contained in:
cinap_lenrek 2021-01-23 15:53:56 +01:00
parent b5c7158f39
commit 6d012d2df0
2 changed files with 11 additions and 29 deletions

View file

@ -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;
}

View file

@ -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;