mIRC Homepage

7.45.663: $calc returns wrong result

Posted By: Ook

7.45.663: $calc returns wrong result - 14/07/16 04:50 PM

When doing a simple addition like: $calc(0.1 + 84)
instead of the expected answer 84.1 we get 84.09999999999999

7.45 gives the expected 84.1
Posted By: Khaled

Re: 7.45.663: $calc returns wrong result - 15/07/16 06:40 AM

Thanks for your bug report. It looks like the beta has extended float precision to the point where rounding fails for some numbers. This is due to the fact that 0.1 does not actually exist in floating point. The next beta will decrease the precision to 12 digits, which is still double that of v7.45.
Posted By: WKN

Re: 7.45.663: $calc returns wrong result - 18/07/16 03:51 PM

Hi,

you cannot win this game trying to make business conform calculations with the use of float or double, this is a well known issue. That simply because it is not possible to store decimal value exactly in binary form which is used in float and double. So to fix this issue at all, you have to create your own numeric class with all methods and operations like add or multiply on it. All other is only working on the sympthoms to minimiue their occurences.

The question for me here in Mirc is: Where do you need those exact calculations for operating with the program? MSL was designed for Mirc internal programming, not for using is elsewhere.

BR
WKN
Posted By: Khaled

Re: 7.45.663: $calc returns wrong result - 19/07/16 05:23 PM

This topic has already been discussed extensively here. This bug report relates to a change in the beta that extends floating point precision in $calc() for those scripters that need it.
© 2021 mIRC Discussion Forums