mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Sep 2003
Posts: 35
O
Ook Offline OP
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Sep 2003
Posts: 35
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

Joined: Dec 2002
Posts: 5,411
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,411
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.

Joined: Feb 2009
Posts: 25
W
WKN Offline
Ameglian cow
Offline
Ameglian cow
W
Joined: Feb 2009
Posts: 25
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

Joined: Dec 2002
Posts: 5,411
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,411
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.


Link Copied to Clipboard