0 / 0 = 0.

%sent = 0 | %total = 0
echo - You sent $calc(%sent / %total * 100) $+ % of the file

Pick one:

You sent 100% of the file
You sent NA% of the file
You sent 0% of the file

Only one of them is accurate. How much of a file have you sent if you've sent no files? None of it-- 0%. Makes sense to me.

Similarly:

I am opped on $calc($chan(0,o) / $chan(0) * 100) of the channels I'm on

Pick one:
I am opped on 100% of the channels I'm on
I am opped on NA% of the channels I'm on
I am opped on 0% of the channels I'm on

Once again, 100% would mean "all", and if you're not on any, you're not opped on any-- intuitively the answer is "none", or "0%".

If you want to be pedantic, you could argue that "all of the channels" is just as meaningful as "none of the channels"-- in which case you would be admitting that 0 is *equally* valid an answer as 1-- so please, make that claim.

Of course, the result 1 does fit into this scenario:

%sent = 0 | %timediff = 0
I am sending data at a rate of $calc(%sent / %timediff) bytes per second

Pick one:

I am sending data at a rate of 1 bytes per second
I am sending data at a rate of NA bytes per second
I am sending data at a rate of 0 bytes per second

In this case, the winner is once again 0. 1 isn't even sensical here. You could claim that NA is valid in this case-- it is the most valid of the above examples. However it's important to realize that in *all* scenarios described above 0 is a reasonable value. 1 works sometimes and fails miserably other times. NA works decently but makes the result seem more ambiguous than a scripter would desire-- forcing them to handle the 0/0 case when they usually don't need or want to. This is likely why 0 was chosen over 1 or NaN/NA.. it almost always makes a good amount of sense.


These are but few of the examples. The theoretical meaning of 0/0 does not apply to the semantic meaning in practical situations. Khaled designed $calc to be easy to use in a case where most scripters who use mIRC are not familiar with programming or mathematics and most likely don't even care what "NaN" means or why 0/0 is not truly 0. To them it makes sense. It is done intentionally to reduce the amount of input handling someone would need to do in the majority case while giving reasonable results. Most scripters don't want to handle exceptions. That's why they're scripting in mIRC and not some other language. This simplicity is seen not just in $calc, but all across mIRC. This is absolutely *not* against the fundamentals of the language-- in fact it is quite at the core of the purpose of the language.