Consider the following:
#include <stdio.h>
#include <string.h>
#include <math.h>
void printdbl( double x )
{
long long unsigned hexValue;
memcpy( &hexValue, &x, sizeof( hexValue ) );
printf( "x = %.5g ; hex = %016llx \n", x, hexValue );
}
void showasinh( double x )
{
printdbl( x );
printdbl( asinh( x ) );
}
int main()
{
showasinh( 0.0 );
return 0;
}
Output:
x = 0 ; hex = 0000000000000000
x = -0 ; hex = 8000000000000000
Expected output:
x = 0 ; hex = 0000000000000000
x = 0 ; hex = 0000000000000000
As far as I can tell this is simply becasue the implementation of asinh mimics copysign using
return ( x > 0.0 ? z : -z);
so I think the fix would be to just use
return ( x >= 0.0 ? z : -z);
+1. We experience this problem with https://github.com/micropython/micropython , where it breaks our testsuite. Ditto for https://sourceforge.net/p/mingw-w64/bugs/516/
You could try the latest GCC (i.e 6.1.0)
x = 0 ; hex = 0000000000000000
x = 0 ; hex = 0000000000000000
I don't think
return ( x >= 0.0 ? z : -z);would be correct, since it would then give0.0forasinh(-0.0)(it should give-0.0, which it currently does). (I think atanh is coded per the suggestion, and gives the incorrect0.0foratanh(-0.0)).Isn't it possible to just use copysign?
Fair point, should indeed likely just use copysign.
This should have been fixed by https://sourceforge.net/p/mingw-w64/mingw-w64/ci/66ba5f3221c786de24f5fc4b9c0236b704c2d31d/ and https://sourceforge.net/p/mingw-w64/mingw-w64/ci/021dffb8a482eb9d1b39569cd1ea42b87226fdf7/.