Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumWiring HardwareTroubleshooting › Float mulitiplication with negatives error

Page Index Toggle Pages: 1
Float mulitiplication with negatives error (Read 3364 times)
12/23/08 at 21:32:27

arakourchians   Offline
YaBB Newbies
._ ._. ._
Los Angeles

Posts: 29
*
 
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??
 
IP Logged
 
Reply #1 - 12/25/08 at 09:39:51

Titus   Offline
Full Member
Wiring Soccer Robot!
Amsterdam

Posts: 176
***
 
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
 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #2 - 12/26/08 at 03:18:55

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
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.
 
IP Logged
 
Page Index Toggle Pages: 1