decalre a union with one double value and char array of 8 bytes.
in Little Endian format , always the sign will be MSB.
so take 7th array, and perform AND operation with 1(char) left shifted 7 times.
and return the resultant value.
NOTE: the returned value is not 1 here but is 128 in case of -Ve.
not sure its efficient.
AND ing with 0X8000000000000000 is good idea but bit wise operations on float value is not valid.
Please correct me if i am wrong.
i'm too eager to know, other efficient methods.
below code is just an example .
int getsign( );
union sign {
double d1;
char d[8];
}u;
int main()
{
u.d1 = -16.32;
if(getsign())
printf("\n %lf is -Ve\n",u.d1);
else
printf("\n %lf is +Ve\n",u.d1);
u.d1 = 16.32;
if(getsign())
printf("\n %lf is -Ve\n",u.d1);
else
printf("\n %lf is +Ve\n",u.d1);
return 0;
}
int getsign(double d1)
{
char m=1;
return m<<7 & u.d[7];
}