Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • Well, that's solved the _0.5 stored as ` 0.49999999999999994` problem. What do I do about infinity? Commented Mar 5, 2014 at 5:20
  • @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).
    – yshavit
    Commented Mar 5, 2014 at 5:24
  • So, what if I change my representation system to Radians and not degrees? will it help? Commented Mar 5, 2014 at 5:25
  • 1
    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.
    – yshavit
    Commented Mar 5, 2014 at 5:34
  • 1
    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 Commented Mar 5, 2014 at 5:41