When a NAN is fed as input, return it as-is without mangling it through the calculation (which e.g. loses the sign of the input value).
This fixes a regression in a testcase of mine, after switching to the internal implementation of these functions.
Signed-off-by: Martin Storsjo martin@martin.st --- As these routines are imported from musl, I guess I should try to upstream the same fix to them too. --- dlls/msvcrt/math.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c index ecf5fdce4d8..2a12c02a4f5 100644 --- a/dlls/msvcrt/math.c +++ b/dlls/msvcrt/math.c @@ -1139,6 +1139,9 @@ float CDECL coshf( float x ) UINT32 ui = *(UINT32*)&x; float t;
+ if (isnan(x)) + return x; + /* |x| */ ui &= 0x7fffffff; x = *(float*)&ui; @@ -1676,6 +1679,9 @@ float CDECL sinhf( float x ) UINT32 ui = *(UINT32*)&x; float t, h, absx;
+ if (isnan(x)) + return x; + h = 0.5; if (ui >> 31) h = -h; @@ -1877,6 +1883,9 @@ float CDECL tanhf( float x ) int sign; float t;
+ if (isnan(x)) + return x; + /* x = |x| */ sign = ui >> 31; ui &= 0x7fffffff; @@ -2769,6 +2778,9 @@ double CDECL cosh( double x ) UINT32 w; double t;
+ if (isnan(x)) + return x; + /* |x| */ ux &= (uint64_t)-1 / 2; x = *(double*)&ux; @@ -4035,6 +4047,9 @@ double CDECL sinh( double x ) UINT32 w; double t, h, absx;
+ if (isnan(x)) + return x; + h = 0.5; if (ux >> 63) h = -h; @@ -4322,6 +4337,9 @@ double CDECL tanh( double x ) int sign; double t;
+ if (isnan(x)) + return x; + /* x = |x| */ sign = ui >> 63; ui &= (UINT64)-1 / 2;