Problems assigning a negative float value

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
ToVa_285016
Level 5
Level 5
100 replies posted 50 replies posted 50 questions asked

Hi,

   

I am having trouble assigning a negative value to a float variable.  The first problem happens here assigning one variable value to another:

   

testAvg = atan2(yAccum / avgCount,xAccum / avgCount) * 180.0f / M_PI;
        directAvg = testAvg;

   

testAvg = -112.5

   

directAvg value is -82.5

   

Secondly, directly trying to assign a value:

   

directAvg = -112.5f;

   

directAvg value is 0

   

I am missing something very basic here.  Thank you for your help.

   

Regards,

   

Tom

0 Likes
1 Reply
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Well, Tom, I think you can imagine that assigning negative values to a float variable does certainly work. So the bug lures on a different place, not the assignment.

   

How do you get knowledge of the actual value? Debugger output?? sprintf()???

   

When sprintf() make sure Buffer large enough, heap size set to 0x0200 and newlib nano float formatting enabled.

   

Can you verify (by setting an address breakpoint) that no write access happens unwanted to your variables?

   

 

   

Bob

0 Likes