Commit b5bc0267 authored by Alexandre Julliard's avatar Alexandre Julliard

msvcrt: Use the fmod()/fmodf() implementation from the bundled musl library.

parent ec31d30e
......@@ -1085,74 +1085,6 @@ float CDECL expf( float x )
}
/*********************************************************************
* 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*)&xi;
}
/*********************************************************************
* logf (MSVCRT.@)
*
* Copied from musl: src/math/logf.c src/math/logf_data.c
......@@ -2749,74 +2681,6 @@ double CDECL exp( double x )
}
/*********************************************************************
* 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*)&xi;
}
/*********************************************************************
* log (MSVCRT.@)
*
* Copied from musl: src/math/log.c src/math/log_data.c
......
#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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment