Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Wiring Hardware >> Troubleshooting >> Float mulitiplication with negatives error
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1230067947

Message started by arakourchians on 12/23/08 at 21:32:27

Title: Float mulitiplication with negatives error
Post by arakourchians on 12/23/08 at 21:32:27
Hello,

I've ran across a very weird phenomena...

say I have a float with the value 0.05, if I multiply it by -1, it results in -1.95!!

float a = 0.05;
Serial.print(a*(-1));

this results in -1.95 !!!

Can anyone explain why and how to fix this??

Title: Re: Float mulitiplication with negatives error
Post by Titus on 12/25/08 at 09:39:51
I'm definitely going to dig into this;
float a=-0,5
Serial.print(a); prints -1,95 aswell!?

and Serial.print(-0,05) gives overload xD

Strange things going on:

void loop()
{
 float a = 0.05; // 0.05
 float b = 1-a; //  0.95
 float c = 0-b; //-0.05
Serial.println( c );
delay(1000);
}
b prints out as 0,95 just fine
c prints -1,04(minus one dot zero four, that's just impossible!)
If I do 0+b, it does print out as 0,95, correctly.

So the problem is either in
1)printing values
2)things below zero
3)subtractions

I don't have a clue, sorry

Barragan?

Titus

Title: Re: Float mulitiplication with negatives error
Post by barragan on 12/26/08 at 03:18:55
hi there, sorry, I am out of town, I will check that too, one place to start might be in the WPrint.cpp http://wiring.uniandes.edu.co/source/trunk/wiring/core/WPrint.cpp?revision=488&view=markup in the printFloat method, perhaps the error is there.
IŽll look into it as soon as possible.

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.