msvcrt: Fix bugs in math.c

Piotr Caban piotr.caban at
Sun Mar 22 10:45:18 CDT 2015

On 03/22/15 15:02, Kevin Chan wrote:
>     Why don't you add an isnan() check? Is there any reason for
>     returning "signbit(num) ? -num : num" instead of returning num?
> Linux and Windows treats NAN differently and I am not quite sure which I
> should follow here, so I just leave it for now...
The goal is to make _copysign behave as on windows. The signbit function 
is not available in Visual Studio.

> I think the _copysignf() is supposed to return a (-num) when (num < 0 &&
> sign >0), so I think this "signbit(num) ? -num : num" might be right.
Sorry, I've misread it earlier. This part looks good.

>     It would be nice to also change signbit definition on systems that
>     doesn't support it, so it at least works for normal numbers.
> The signbit() function is actually part of C99, not my implementation,
> so I think it should be supported on most systems? Though I am not quite
> sure...
It's not available when compiled with Visual Studio. There's following 
code in math.c:
     #ifndef signbit
     #define signbit(x) 0
I think it would be better if it's at least changed to something like:
#define signbit(x) ((x)<0 ? 1 : 0)
It will not work correctly for -NAN or -0 but it will not break the 
cases where old implementation was working.


More information about the wine-devel mailing list