Menu

#315 Long.MIN_VALUE multiplied by 1.1f returns wrong value

undecided
closed-invalid
nobody
artihmetic (1)
5
2014-09-14
2010-06-02
Jag
No

(This is possibly a duplicate post from one I just tried to make)

-9223372036854775808(Long) multiplied by 1.1(Float) = -1.0145709460442579E19(Double)

The result should be -10145709240540253388.8 using the ArithmeticEngine.CONSERVATIVE_ENGINE.

I suspect that when widening the Float you call floatValue() instead of toString().

Discussion

  • Dániel Dékány

    • labels: Object wrapping --> artihmetic
    • status: open --> closed-invalid
    • Group: --> undecided
     
  • Dániel Dékány

    That result is as precise as it can get without working with BigDecimal-s, which is the point of CONVERSATIVE_ENGINE. In fact, it's still more precise than Java/C, because those would do the multiplication with float precision, while the CONVERSATIVE_ENGINE does it with double precision. Also, note that 1.1f (the input) is already an approximation, as 1.1 can't be expressed precisely in a 2-based number system, so you have already lost the hope for getting the real result there.

    (Of course, BIGDECIMAL_ENGINE, which is the default, gives the exact result, assuming 1.1 wasn't given in floating point form, which thus would be already imprecise.)

     

Log in to post a comment.