What's the fastest way to compare sign on a double
?
I know that a double
has a "sign bit" but I'm not sure if the way I'm "looking for it" in its binary rep is a good idea or not.
Barring "portability" issues, can someone tell me what's going on with this code in MSVC++?
#include <stdio.h>
int main()
{
double z = 5.0 ;
__int64 bitSign ;
__int64 *ptr ;
ptr = (__int64*)&z ;
for( __int64 sh = 0 ; sh < 65 ; sh++ )
{
bitSign = 1L << sh ; // Weird. it doesn't do 1.
printf( "Bit# %d (%llx): %lld\n",
sh, bitSign, ( (*ptr) & bitSign) ) ;
}
}
First, why is starting at bit 32, even though I only shifted by one bit?
Second, is it ok for me to check the 64th bit of a double
to check its sign on MSVC++?