Re: Indeterminate math
On Tuesday, October 15, 2002, at 07:05 AM, Michael G Schwern wrote: > This came up at YAPC::Europe. Someone [1] wanted to know if 1/0 would > produce a divide by zero error in Perl 6, or if it would return a value > representing an indeterminate result (undef?) It would make more sense > for > Perl, upon being given a simple bit of impossible math, to return undef > (like other functions do on failure) than to generate an error. The > error > seems a throwback to earlier days of hardwired calculators. Well, if you're an exceptions guy like me, you'd *much* rather have it produce an error than a zero, which I assume undef would still evaluate to. NaN is another option, following some standard or other. > [2] Discussion of divide by zero and why it's not infinity [3] > http://mathforum.org/dr.math/faq/faq.divideby0.html > > [3] I was always taught it's infinity. Positive or negative infinity? (it's a trap!) -Ken
Re: Indeterminate math
On Wednesday, October 16, 2002, at 04:44 AM, Jonathan Scott Duff wrote: > People have used the terms "error" and "exception" interchangably in > this disucssion. To me, an "error" is something that stops program > execution while an "exception" may or may not stop execution depending > on what the user decides to do about exceptions. Agreed. I've meant "exception" in my comments, in the trappable sense of the term. I don't see much need for a true untrappable error - one man's error is another man's case. > 1/0 could throw an exception, yet continue execution. Somewhere I > expect we should be able to define a policy for what to do in these > situations. > > use Policy DivideByZero => Nan; > use Policy DivideByZero => Inf; > use Policy DivideByZero => DivideByZeroException; > > I'm sure someone else can pick a better syntax than I. I don't think there are going to be many real situations when people would want Inf or Undef (99% of the rare cases where people think they might want it, they're probably wrong ;-), but NaN or Exception could indeed be common needs. -Ken