[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Date: Tue, 3 Feb 87 13:42 EDT
Division by zero should signal an error whenever possible.
Defining it to silently return something would make debugging
numerical code more difficult. I have found some very obscure
bugs as a result of division by zero traps.
The existence of infinite rational objects and how they come about are
two separate issues. If there were a Common Lisp error system, you
would want something like:
- Division by zero signals an error. (Note that 0/0 is different from
- The user has an option when the error is signalled (in the non-zero/0
case) to use an "infinite" result.
- There is a form which turns off such error signalling within its
body, so that infinities are produced for division by zero, without
- There is a way for the programmer or user to explicitly enter an
infinite object into the system (by typing it).
- When an infinite object appears in a computation, the "mathematically
correct" thing happens. [The IEEE floating-point rules are one
possible definition of "correct".]
So infinities only appear under explicit programmer or user control.
Thus you get the best of both trapping and non-trapping worlds. The
Symbolics system handles IEEE floating-point divide-by-zero this way.
[Hard-core IEEE standards fanatics will point out that the default is
supposed to be that division doesn't trap, but just quietly returns an
infinity. We chose to make trapping be the default for all exceptions
Note that it depends on what sort of calculation you're doing whether
infinity is an appropriate answer or not. One of the reasons that
rational infinities aren't in Common Lisp yet is that there is some
debate about whether rational infinity is affine (signed) or projective