Skip to main content

Timeline for How to overcome inaccuracy in Java

Current License: CC BY-SA 3.0

8 events
when toggle format what by license comment
Mar 5, 2014 at 5:41 comment added Hungry Blue Dev I guess you're right... I must live with it. :-) So, I guess in certain specific cases, we must return expected values, rather than the seemingly-wrong-but-very-close calculated values
Mar 5, 2014 at 5:39 vote accept Hungry Blue Dev
Mar 5, 2014 at 5:34 comment added yshavit No, because there's just no way to represent π/2 exactly with a float or double. If you had a library that took degrees (rather than radians), you could do that -- since it is possible to represent 90.0 exactly. But afaik, StrictMath doesn't do that.
Mar 5, 2014 at 5:32 history edited yshavit CC BY-SA 3.0
added 1031 characters in body
Mar 5, 2014 at 5:25 comment added Hungry Blue Dev So, what if I change my representation system to Radians and not degrees? will it help?
Mar 5, 2014 at 5:24 comment added yshavit @ambigram_maker Again, you have to pick some "large-enough" number at which you say "okay, close enough to infinity". Doubles actually can store infinity, but you don't get that result because StrictMath.toRadians(90) returns a number really close to, but not exactly pi/2 (which you can't represent in a finite number of bits).
Mar 5, 2014 at 5:20 comment added Hungry Blue Dev Well, that's solved the _0.5 stored as ` 0.49999999999999994` problem. What do I do about infinity?
Mar 5, 2014 at 5:18 history answered yshavit CC BY-SA 3.0