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,5Serial.print(a); prints -1,95 aswell!?and Serial.print(-0,05) gives overload xDStrange things going on:void loop(){  float a = 0.05; // 0.05  float b = 1-a; //  0.95  float c = 0-b; //-0.05Serial.println( c );delay(1000);}b prints out as 0,95 just finec 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 in1)printing values2)things below zero3)subtractionsI don't have a clue, sorryBarragan?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.