I know there are problem with numbers like 0.3 which cannot be expressed using floating point numbers so they generate floating point errors.
What about the numbers that can be represented? like 0.5, 0.75, etc… can I trust floating point arithmetic to be error free if I’m dealing with numbers that are negative powers of two and numbers composed from them?
I know there are problem with numbers like 0.3 which cannot be expressed using
Share
Assuming you have an IEEE754 architecture, and if you are only performing addition, subtraction and multiplication, and if the result fits, then it should be correct. Division can only be used if the resulting denominator is a power of two. Any other built-in maths functions like exp and log cannot possibly be correct (due to Lindemann-Weierstrass); ditto for non-natural powers (though there isn’t even a built-in power function in most CPUs anyway).