On Feb 28, 2005, at 7:55 PM, Eric Wilhelm wrote:

# The following was supposedly scribed by
# David Golden
# on Monday 28 February 2005 07:07 pm:

Which would you prefer?

    $ perl -le '$x=1/0; print $x+1'    
    Illegal division by zero at -e line 1.

or

    $ perl -le '$x=1/0; print $x+1'    
    1

I like the one where you get the mathematically-correct (or at least mathematically-useful) infinity.

  $perl -le 'use bigint; $x = 1/0; print $x+1'
  inf

  $perl -le 'use bigint; $x = 1/0; print 1/$x'
  0

So, is that positive or negative infinity? Sometimes that makes an awful lot of difference.


When you're wishing for 1/0 to be infinity, you're probably thinking of the limit as x->0 of 1/x. And it matters which direction you approach 0 from - if you approach from the right, the limit is infinity. If you approach from the left, the limit is negative infinity. If you don't specify the approach direction, the limit is undefined, even if you allow infinity in your computational system.

See also http://mathforum.org/dr.math/faq/faq.divideby0.html . The explanations get progressively more advanced as you go down the page.

 -Ken



Reply via email to