Float subtraction problem
Damn, ive seen some weird stuff, but this bug takes the cake.
Im using C++, compiler is Studio.NET.
i have two variables of type float x and y.
with the following values (values are loaded from a file)
x = 34.635418
y = 34.635422
if i subtract them i get:
float res = x - y;
wait for it..... res =
-3.8146973e-006
WTF?! THE ANSWER SHOULD NOT BE -3!!!!
I have tried different compilers, all get the same result.
PLEASE HELP - i bet its something really simple too....
Paul
[Edited by - felisandria on September 19, 2004 3:15:12 PM]
Welcome to scientific notation. You may have heard of it in all the high-school physics lectures you skipped.
Err, it says the answer is -0.000038146973, or -3.8146973 * pow(10, -6), which is correct. 34.635418 - 34.635422 is -0.00003
Edit: Heh, love how when I started typing there were no messages, but when I post there's 2 more.
Edit: Heh, love how when I started typing there were no messages, but when I post there's 2 more.
I think he should just uninstall his compiler and come back when he can handle basic math.
Quote:Original post by RavuyaROOFLELOLROTFLMAOHAHALOL!!!!1~
Welcome to scientific notation. You may have heard of it in all the high-school physics lectures you skipped.
High school physics was useless anyway.
hey u guys, leave him alone.
he might be (like me) a young programmer who hasn't yet
done that math in school
he might be (like me) a young programmer who hasn't yet
done that math in school
Quote:Original post by jjac7212
hey u guys, leave him alone.
he might be (like me) a young programmer who hasn't yet
done that math in school
Yes, but that does not justify swearing in the post topic, and one is much less likely to receive constructive help/comments if people do not approve of your post language.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement