msvcrt: Use the fmod()/fmodf() implementation from the bundled musl library.
This commit is contained in:
parent
ec31d30ec0
commit
b5bc026798
3 changed files with 5 additions and 136 deletions
|
@ -1084,74 +1084,6 @@ float CDECL expf( float x )
|
|||
return y;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* fmodf (MSVCRT.@)
|
||||
*
|
||||
* Copied from musl: src/math/fmodf.c
|
||||
*/
|
||||
float CDECL fmodf( float x, float y )
|
||||
{
|
||||
UINT32 xi = *(UINT32*)&x;
|
||||
UINT32 yi = *(UINT32*)&y;
|
||||
int ex = xi>>23 & 0xff;
|
||||
int ey = yi>>23 & 0xff;
|
||||
UINT32 sx = xi & 0x80000000;
|
||||
UINT32 i;
|
||||
|
||||
if (isinf(x)) return math_error(_DOMAIN, "fmodf", x, y, (x * y) / (x * y));
|
||||
if (yi << 1 == 0 || isnan(y) || ex == 0xff)
|
||||
return (x * y) / (x * y);
|
||||
if (xi << 1 <= yi << 1) {
|
||||
if (xi << 1 == yi << 1)
|
||||
return 0 * x;
|
||||
return x;
|
||||
}
|
||||
|
||||
/* normalize x and y */
|
||||
if (!ex) {
|
||||
for (i = xi << 9; i >> 31 == 0; ex--, i <<= 1);
|
||||
xi <<= -ex + 1;
|
||||
} else {
|
||||
xi &= -1U >> 9;
|
||||
xi |= 1U << 23;
|
||||
}
|
||||
if (!ey) {
|
||||
for (i = yi << 9; i >> 31 == 0; ey--, i <<= 1);
|
||||
yi <<= -ey + 1;
|
||||
} else {
|
||||
yi &= -1U >> 9;
|
||||
yi |= 1U << 23;
|
||||
}
|
||||
|
||||
/* x mod y */
|
||||
for (; ex > ey; ex--) {
|
||||
i = xi - yi;
|
||||
if (i >> 31 == 0) {
|
||||
if (i == 0)
|
||||
return 0 * x;
|
||||
xi = i;
|
||||
}
|
||||
xi <<= 1;
|
||||
}
|
||||
i = xi - yi;
|
||||
if (i >> 31 == 0) {
|
||||
if (i == 0)
|
||||
return 0 * x;
|
||||
xi = i;
|
||||
}
|
||||
for (; xi>>23 == 0; xi <<= 1, ex--);
|
||||
|
||||
/* scale result up */
|
||||
if (ex > 0) {
|
||||
xi -= 1U << 23;
|
||||
xi |= (UINT32)ex << 23;
|
||||
} else {
|
||||
xi >>= -ex + 1;
|
||||
}
|
||||
xi |= sx;
|
||||
return *(float*)ξ
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* logf (MSVCRT.@)
|
||||
*
|
||||
|
@ -2748,74 +2680,6 @@ double CDECL exp( double x )
|
|||
return scale + scale * tmp;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* fmod (MSVCRT.@)
|
||||
*
|
||||
* Copied from musl: src/math/fmod.c
|
||||
*/
|
||||
double CDECL fmod( double x, double y )
|
||||
{
|
||||
UINT64 xi = *(UINT64*)&x;
|
||||
UINT64 yi = *(UINT64*)&y;
|
||||
int ex = xi >> 52 & 0x7ff;
|
||||
int ey = yi >> 52 & 0x7ff;
|
||||
int sx = xi >> 63;
|
||||
UINT64 i;
|
||||
|
||||
if (isinf(x)) return math_error(_DOMAIN, "fmod", x, y, (x * y) / (x * y));
|
||||
if (yi << 1 == 0 || isnan(y) || ex == 0x7ff)
|
||||
return (x * y) / (x * y);
|
||||
if (xi << 1 <= yi << 1) {
|
||||
if (xi << 1 == yi << 1)
|
||||
return 0 * x;
|
||||
return x;
|
||||
}
|
||||
|
||||
/* normalize x and y */
|
||||
if (!ex) {
|
||||
for (i = xi << 12; i >> 63 == 0; ex--, i <<= 1);
|
||||
xi <<= -ex + 1;
|
||||
} else {
|
||||
xi &= -1ULL >> 12;
|
||||
xi |= 1ULL << 52;
|
||||
}
|
||||
if (!ey) {
|
||||
for (i = yi << 12; i >> 63 == 0; ey--, i <<= 1);
|
||||
yi <<= -ey + 1;
|
||||
} else {
|
||||
yi &= -1ULL >> 12;
|
||||
yi |= 1ULL << 52;
|
||||
}
|
||||
|
||||
/* x mod y */
|
||||
for (; ex > ey; ex--) {
|
||||
i = xi - yi;
|
||||
if (i >> 63 == 0) {
|
||||
if (i == 0)
|
||||
return 0 * x;
|
||||
xi = i;
|
||||
}
|
||||
xi <<= 1;
|
||||
}
|
||||
i = xi - yi;
|
||||
if (i >> 63 == 0) {
|
||||
if (i == 0)
|
||||
return 0 * x;
|
||||
xi = i;
|
||||
}
|
||||
for (; xi >> 52 == 0; xi <<= 1, ex--);
|
||||
|
||||
/* scale result */
|
||||
if (ex > 0) {
|
||||
xi -= 1ULL << 52;
|
||||
xi |= (UINT64)ex << 52;
|
||||
} else {
|
||||
xi >>= -ex + 1;
|
||||
}
|
||||
xi |= (UINT64)sx << 63;
|
||||
return *(double*)ξ
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* log (MSVCRT.@)
|
||||
*
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include "libm.h"
|
||||
|
||||
double __cdecl fmod(double x, double y)
|
||||
{
|
||||
|
@ -13,6 +14,8 @@ double __cdecl fmod(double x, double y)
|
|||
/* float load/store to inner loops ruining performance and code size */
|
||||
uint64_t uxi = ux.i;
|
||||
|
||||
if (isinf(x))
|
||||
return math_error(_DOMAIN, "fmod", x, y, (x * y) / (x * y));
|
||||
if (uy.i<<1 == 0 || isnan(y) || ex == 0x7ff)
|
||||
return (x*y)/(x*y);
|
||||
if (uxi<<1 <= uy.i<<1) {
|
||||
|
|
|
@ -11,6 +11,8 @@ float __cdecl fmodf(float x, float y)
|
|||
uint32_t i;
|
||||
uint32_t uxi = ux.i;
|
||||
|
||||
if (isinf(x))
|
||||
return math_error(_DOMAIN, "fmodf", x, y, (x * y) / (x * y));
|
||||
if (uy.i<<1 == 0 || isnan(y) || ex == 0xff)
|
||||
return (x*y)/(x*y);
|
||||
if (uxi<<1 <= uy.i<<1) {
|
||||
|
|
Loading…
Add table
Reference in a new issue