code • words • emotions

Daniel Janus’s blog

Posts in category: wat

Double, double toil and trouble

or, Corner-Cases of Comparing Clojure Numbers

21 February 2025 •

Let’s talk about Clojure.

In Clojure, comparing two numbers can throw an exception.

Wat

Check this out:

(< 1/4 0.5M)
;=> true        ; as expected

(< 1/3 0.5M)
; Execution error (ArithmeticException) at java.math.BigDecimal/divide (BigDecimal.java:1783).
; Non-terminating decimal expansion; no exact representable decimal result.

Continue reading