Microblaze FPU and IEEE754 single precision number format

Nov 07, 2006 1 Replies

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



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-

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required