Doubles and floats have a limited precision.
The extra -0.0019 you have in your result is a precision error.
You'll find this behavior on any machine that implements floats and
doubles according to the most prevailing spec:
http://en.wikipedia.org/wiki/IEEE_754-2008
On Jul 18, 7:41 am,
On Jul 20, 11:07 am, Streets Of Boston flyingdutc...@gmail.com
wrote:
Doubles and floats have a limited precision.
The extra -0.0019 you have in your result is a precision error.
You'll find this behavior on any machine that implements floats and
doubles according to the most prevailing
The most important thing you should remember about float operations:
never '==' compare them.
---
if (floatNumber == 0) {}
---
will mostly fail because of the limited precision.
So you'd better do comparisons like that:
---
if (Math.abs(floatNumber) 0.001) {} // with a tolerance of your
choice
That depends...
You can do floatNumber == 0 in many cases or floatNumber1 ==
floatNumber2.
But you have to remember that precision-errors could be a problem.
It depends on how floatNumber(1/2) has been assigned and what you're
using it for.
But to say 'never', that's a bit too strong. :-)
On
4 matches
Mail list logo