RosettaCodeData/Task/Detect-division-by-zero/Clojure/detect-division-by-zero.clj
Ingy döt Net 86c034bb8b new files
2013-04-10 12:38:42 -07:00

7 lines
242 B
Clojure

(defn safe-/ [x y]
(try (/ x y)
(catch ArithmeticException _
(println "Division by zero caught!")
(cond (> x 0) Double/POSITIVE_INFINITY
(zero? x) Double/NaN
:else Double/NEGATIVE_INFINITY) )))