mIRC Home    About    Download    Register    News    Help

Print Thread
division by zero #87177 17/06/04 05:44 AM
Joined: Sep 2003
Posts: 5
A
AviN456 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Sep 2003
Posts: 5
$calc(N/0) should return an error message, not 0

mIRC 6.15 (and all others AFAIK)

Re: division by zero #87178 17/06/04 10:28 AM
Joined: May 2004
Posts: 95
W
wiebe Offline
Babel fish
Offline
Babel fish
W
Joined: May 2004
Posts: 95
$calc(a + b) also gives 0

would indeed be nice if it gives an error

Re: division by zero #87179 24/06/04 02:36 AM
Joined: Feb 2003
Posts: 810
C
cold Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
I don't think so. To be consistent, identifiers should only halt the script with an error if there's wrong syntax. In all other cases, it depends on what the identifier does and what's the kind of parameters entered. $calc(1/0) deals with numbers, so I can't see a problem with it returning 0 in this case.

What I don't like are identifiers like $calc(), $int() and $abs() that return 0 when not only numbers are entered. In this case, I think they should return $null, since there should be no place for anything other than numbers (and operators, in $calc()'s case). For example, $calc(a/0) should return $null, in my opinion.

Last edited by cold; 24/06/04 02:43 AM.

* cold edits his posts 24/7
Re: division by zero #87180 24/06/04 08:06 PM
Joined: Oct 2003
Posts: 313
S
Sais Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 313
I agree. It might be nice to get a warning rather than an error (i.e. the script isn't halted, it just (optionally?) prints something to the status). I can't remember if there is anything else like this in mIRC already.

The onus should be on the scripter to make sure his/her script does not cause an error - they should make the effort to avoid such conditions as division by zero. If it were reported as an error it might help in debugging.



Sais
Re: division by zero #87181 24/06/04 08:46 PM
Joined: Mar 2004
Posts: 130
T
tsoglanos Offline
Vogon poet
Offline
Vogon poet
T
Joined: Mar 2004
Posts: 130
see it from thy other site

if you run you Microsoft calculator

you can not add any text the are only Numbers from 0 to 9

0 is the error msg (a + b is 0) (1 + 2 is 3) , =)

Re: division by zero #87182 24/06/04 11:19 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Personally I think division by 0 or any operation on invalid input should simply return $false. That way those who don't want to treat it differently from 0 can use if ($calc(whatever)) without any change and those that want to check can use if ($calc(whatever) != $false). However it should still behave the same with things like $calc(123abc) returning '123' since it's great to use as a $parseNum().


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: division by zero #87183 06/07/04 12:23 PM
Joined: Sep 2003
Posts: 5
A
AviN456 Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Sep 2003
Posts: 5
Quote:
0 is the error msg (a + b is 0) (1 + 2 is 3) , =)



in that case, think of a and b as variables
mathematically, until a variable is assigned a value, it has a value of zero.