unexpected float result

I am trying to add two float variables, but gives me incorrect result:

1
2
3
4
float a = -1.5031407940568897e-07;
float b = 1.7952352979704175e-15;
	
std::cout << a + b;


printed: -1.50314e-07

The result should be around 0,3. If I remove the "e-07" and "e-15" part from the values it gives me correct result. What causing this ?
Last edited on
The result should be around 0,3

That's incorrect.


a = -0.000000150314079405688970000000000
b =  0.000000000000000017952352979704175

a + b =
-0.000000150314079405688970000000000 +
 0.000000000000000017952352979704175


which is -0.000000150314 (and some more decimal places after that)
which is -1.50314e-07

Do you understand what "e-07" and "e-15" mean?


Last edited on
Yeah that was the problem I tought "e-x" means something like repeat, but I looked it up what is that and that value is correct indeed.
Last edited on
Topic archived. No new replies allowed.