mIRC Home    About    Download    Register    News    Help

Print Thread
#18281 06/04/03 01:52 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline OP
Hoopy frood
OP Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
$calc(110017 * 40146.48) returns "4416795290.160001" instead of the correct "4416795290.16".
This isn't happening with $calc(11001.7 * 401464.8) or $calc(1100.17 * 4014648)

Specs: WinXP pro, Athlon XP 2200+


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#18282 06/04/03 06:09 AM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Welcome to floating point, home of non-exact calculations. Thats not a bug, it's a limitation of how computers calculate decimals.

#18283 08/04/03 09:43 AM
Joined: Dec 2002
Posts: 62
Babel fish
Offline
Babel fish
Joined: Dec 2002
Posts: 62
This has been posted before, however, I'm still baffled by it.
If it is due to limitations of how computers calculate decimals, why is it that $calc in mIRC 6.03 shows 4416795290.160001 but "Calculator" in windows shows the perfect 4416795290.16? I seek enlightenment. smile

#18284 08/04/03 09:43 PM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Well on second thought, maybe mIRC's calculation system is just messed up.

$calc(340282366920938463500000000000000000000*2)

That works fine, but

$calc(340282366920938463500000000000000000000+2)

that doesn't. Although a rounding error like the one above CAN be normal, it appears mIRC's $calc() is just broken.

#18285 10/04/03 02:16 PM
Joined: Dec 2002
Posts: 39
V
Ameglian cow
Offline
Ameglian cow
V
Joined: Dec 2002
Posts: 39
Hmm, as much as this might still be a mIRC bug, that isn't a good indication. Floating point numbers are able to represent certain but not every number. Generally, when you have huge numbers you lose precision, so your result is perfectly normal. There're a lot less extreme numbers that can't be represented, what happens if you try 1.00001 (can't test, not on a a Win system atm)? In matlab on this machine it comes out as 1.0.

As for the Windows calculator, it might not use floating point numbers at all but rather some unlimited precision library instead, which makes the problem go away. It might also simply use a different precision than mIRC does, there're several available on x86 systems.


Link Copied to Clipboard