Hi Piotr,
2015-03-22 23:45 GMT+08:00 Piotr Caban
<piotr.caban@gmail.com>:
On 03/22/15 15:02, Kevin Chan wrote:
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.
Understood. Thank you :)
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
#endif
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.
Sorry I didn't notice my program in VS was linked to the C++ lib for this signbit() function.
"#define signbit(x) ((x)<0 ? 1 : 0)" Looks good to me, I will submit a patch. Thanks for the advice :)
Maybe we could rewrite this three-line code to "(signbit(sign) &&
signbit(num)) ? num : -num"? It seems more efficient, but it also seems
the code become not very easy-to-read...
I would stick with more readable code.
Great! Me, too.