[android-developers] Re: Strange bug found when subtracting a float from another float, or a double from another double

2009-07-20 Thread Streets Of Boston
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,

[android-developers] Re: Strange bug found when subtracting a float from another float, or a double from another double

2009-07-20 Thread fadden
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

[android-developers] Re: Strange bug found when subtracting a float from another float, or a double from another double

2009-07-20 Thread f_heft
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

[android-developers] Re: Strange bug found when subtracting a float from another float, or a double from another double

2009-07-20 Thread Streets Of Boston
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