Detect division by zero: Difference between revisions

m (→‎{{header|Déjà Vu}}: Updates example)
Line 1,400:
caught another error: 0/foo -> can't use non-numeric string as operand of "/"</pre>
As can be seen, division-by-zero is only signaled when performing integer division. Similarly, separate detection of values that would otherwise be IEEE NaN is only performed when doing floating-point division.
 
=={{header|TXR}}==
 
<lang txr>@(do (defun div-check (x y)
(catch (/ x y)
(numeric_error (msg)
'div-check-failed))))
@(bind good @(div-check 32 8))
@(bind bad @(div-check 42 0))</lang>
 
Run:
 
<pre>$ txr division-by-zero.txr
good="4.0"
bad="div-check-failed"</pre>
 
=={{header|XPL0}}==
543

edits