Microblaze FPU and IEEE754 single precision number format

Hi All, I started using a microblaze design that included the FPU. As a test that the FPU is working I created a small application that devided the number 3.0 with 6.0 for a result of .5 and then displayed the result on a hyperterminal window. I was hoping to see a result of

0x3F000000 for a single precision 32 bit value but instead I see a result of 0x3FE00000. This would be correct (with an extra 8 zeros) if I was using a double precision 64bit FPU. I then decided to create a float variable with its value initialized to 0.5 and displayed it. The result was the same leading me to believe that the problem lies elsewhere?

float x = 0.5; putnum (x); // this displays 3FE00000

Can someone enlighten me... I'm a tad bit confused...

Thanks

Reply to
Aaron Curtin
Loading thread data ...

Hi Aaron,

Where is putnum() declared? What is its argument type? Most likely the compiler does not know that putnum takes a 32-bit float argument and is passing the value of x by converting it to 64-bit double. Try

union { float f; unsigned int i; } x;

x.f = 0.5; putnum(x.i);

...and see if that prints the correct value. A union is the only truly safe way to re-interpret a bit pattern from one type to another in C.

Cheers,

-Ben-

Reply to
Ben Jones

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.