Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Detect-division-by-zero/Ol/detect-division-by-zero.ol
Normal file
17
Task/Detect-division-by-zero/Ol/detect-division-by-zero.ol
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
(define (safediv a b)
|
||||
(if (eq? (type b) type-complex)
|
||||
(/ a b) ; complex can't be 0
|
||||
(let ((z (/ 1 (inexact b))))
|
||||
(unless (or (equal? z +inf.0) (equal? z -inf.0))
|
||||
(/ a b)))))
|
||||
|
||||
; testing:
|
||||
(for-each (lambda (x)
|
||||
(if x (print x) (print "division by zero detected")))
|
||||
(list
|
||||
(safediv 1 5) ; => 1/5
|
||||
(safediv 2 0) ; => division by zero detected
|
||||
(safediv 3 1+2i) ; => 3/5-6/5i
|
||||
(safediv 4 0+i) ; => 0-4i
|
||||
(safediv 5 7/5) ; => 25/7
|
||||
))
|
||||
Loading…
Add table
Add a link
Reference in a new issue