Floating point intitialization errors

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am working with an atxmega256a3b. I am trying to initialize a floating point value to be true 0. My code looks like this

float DCM_Matrix[3][3]= {
{
1,0.0F,0.0F }
,{
0.0F,1,0.0F }
,{
0.0F,0.0F,1 }
};

The values in the matrix are being set to a decimal values that are very close to 0 but not exactly. for instance, DCM_Matrix[0][1] = -0.00060707104 and DCM_Matirix[0][2] 0.00060707104

However, it has no problem initializing the 1 values to exactly 1.

Is there some error occurring that causes these float values to not be set to 0?
Does anyone now how I can declare the matrix so that the values will be true 0?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

praxjoe wrote:
I am working with an atxmega256a3b. I am trying to initialize a floating point value to be true 0. My code looks like this

float DCM_Matrix[3][3]= {
  {
    1,0.0F,0.0F }
  ,{
    0.0F,1,0.0F  }
  ,{
    0.0F,0.0F,1 }
}; 

The values in the matrix are being set to a decimal values that are very close to 0 but not exactly. for instance, DCM_Matrix[0][1] = -0.00060707104 and DCM_Matirix[0][2] 0.00060707104

However, it has no problem initializing the 1 values to exactly 1.

Is there some error occurring that causes these float values to not be set to 0?
Does anyone now how I can declare the matrix so that the values will be true 0?


Why not initialise with 0 rather than 0.0F ?
The Compiler knows that every expression is a float anyway.

Are you really sure about those f-p values? That is considerably greater than one significant bit in the mantissa.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which C compiler? I just tried this with avr-gcc in AVR Studio 4 and got exactly the expected result. In SRAM you can see the 0x3F800000 values representing 1.0 and 0x00000000 representing 0.0 (this is IEEE754 format):

Attachment(s):