Compare sign of two doubles
Posted
by bobobobo
on Stack Overflow
See other posts from Stack Overflow
or by bobobobo
Published on 2010-05-06T15:16:08Z
Indexed on
2010/05/06
15:18 UTC
Read the original article
Hit count: 361
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++? Or is there a more preferred way?
© Stack Overflow or respective owner