Hello guys I am trying to implement the new frexp function by hand. To be able to do this I used Union data type. I can find the exponent correctly but my problem is about the mantis part. I cannot find the correct value for mantisa part. It gives me really big number but when . I tried to shift the binary but it also didn't help me. Do you have any idea how I can find the mantis from this binary. Thank you. (This is for double floating unit and I assumed double is 64 bit)
P.s. There is one more thing I didn't get. To be able to find the right exponent value, I suppose to decrease that value 1023 in theory (bias property), but in this example I needed to decrease 1022 to find the right value. Is something wrong?
typedef union {
double f;
struct {
unsigned long mantisa : 52;
unsigned long exponent : 11;
unsigned long sign : 1;
} parts;
} double_cast;
double myfrexp(double number, int *exp)
{
double_cast d1;
d1.f = number;
unsigned long dd;
printf("\n %x \n", d1.parts.exponent);
*exp = d1.parts.exponent - 1022;
printf("\n%d\n\n", *exp);
printf("\n %lf \n", (double)d1.parts.mantisa);
return d1.parts.mantisa;
}
Thank you