mIRC Home    About    Download    Register    News    Help

Print Thread
7.45.663: $calc returns wrong result #258504 14/07/16 04:50 PM
Joined: Sep 2003
Posts: 30
O
Ook Offline OP
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Sep 2003
Posts: 30
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

Re: 7.45.663: $calc returns wrong result [Re: Ook] #258505 15/07/16 06:40 AM
Joined: Dec 2002
Posts: 4,538
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,538
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.

Re: 7.45.663: $calc returns wrong result [Re: Khaled] #258516 18/07/16 03:51 PM
Joined: Feb 2009
Posts: 20
W
WKN Offline
Ameglian cow
Offline
Ameglian cow
W
Joined: Feb 2009
Posts: 20
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

Re: 7.45.663: $calc returns wrong result [Re: WKN] #258517 19/07/16 05:23 PM
Joined: Dec 2002
Posts: 4,538
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,538
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.