IEEE754_2008 states
7.3 Division by zero 7.3.0
The divideByZero exception shall be signaled if and only if an exact infinite result is defined for an
operation on finite operands. The default result of divideByZero shall be an ∞ correctly signed according to
the operation:
― For division, when the divisor is zero and the dividend is a finite non-zero number, the sign of the
infinity is the exclusive OR of the operands’ signs (see 6.3).
Current Behaviour
my $res;
try {
$res = 42e0/0e0
}
say $!; #Attempt to divide 42 by zero using /
say $!.^name; #X::Numeric::DivideByZero
say $res; #(Any)
Proposed Behaviour (Num)
Default behaviour is unchanged.
For the operations that can trigger a DBZ ( /, %)....
$*DBZ-SUPPRESS = True;
say 42e0/0e0; #Inf
say -1e0/0e0; #-Inf
say 1e0/-0e0; #-Inf
say -1e0/-0e0; #Inf
say 0e0/0e0; #NaN \ regardless of dividend or divisor sign
say Inf/Inf; #NaN /
Proposed Behaviour (Rat)
Since $*RAT-OVERFLOW already gives the power to overflow to Num, then in the event that coders want the Num behaviours, they can set $*RAT-OVERFLOW=Num (the default).
i.e. No change for Rat.
Proposed Behaviour (FatRat)
See above. If you want FatRat, then in principle it will never overflow (?) and the current behaviour to throw an exception is to be expected.
i.e. No change for FatRat.
Proposed Behaviour (Int)
In the case of Int eg 1/0 makes a Rat (so the proposed Rat behaviour applies).
i.e. No change for Int.
Notes:
- Regardless of dividend magnitude
- <42/0>.nude already correctly gives (1,0) retain this
- In the case of Rat & FatRat, the DBZ is only thrown when the value is used (eg. stringified for output)
- Since Rat collapses in a way that does not retain the sign of a zero denominator, <1/-0> will produce +Inf
There is also some valuable insight in this other problem-solving issue.
There has been a previous proposal to do this by Zoffix (includes a pointer to Larry Wall @TimToady comment)
old-design-docs
.
EDIT: clarified the proposal for Int and added note [4]
IEEE754_2008 states
Current Behaviour
Proposed Behaviour (Num)
Default behaviour is unchanged.
For the operations that can trigger a DBZ (
/,%)....Proposed Behaviour (Rat)
Since
$*RAT-OVERFLOWalready gives the power to overflow to Num, then in the event that coders want the Num behaviours, they can set$*RAT-OVERFLOW=Num(the default).i.e. No change for Rat.
Proposed Behaviour (FatRat)
See above. If you want FatRat, then in principle it will never overflow (?) and the current behaviour to throw an exception is to be expected.
i.e. No change for FatRat.
Proposed Behaviour (Int)
In the case of Int eg
1/0makes a Rat (so the proposed Rat behaviour applies).i.e. No change for Int.
Notes:
There is also some valuable insight in this other problem-solving issue.
There has been a previous proposal to do this by Zoffix (includes a pointer to Larry Wall @TimToady comment)
old-design-docs
.
EDIT: clarified the proposal for Int and added note [4]