O'Reilly logo

Clojure Programming by Brian Carper, Christophe Grand, Chas Emerick

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Clojure Mathematics

Knowing the types of available numbers and their representations is not sufficient to understand how mathematics is modeled in Clojure. Clojure’s various arithmetic and equality operators provide additional semantic guarantees in order to support sensible results across all the numeric types in play and in the face of many common issues that arise in computational mathematics, such as the handling of overflow and underflow, controlling the promotion of arithmetic results, and collection equality.

Bounded Versus Arbitrary Precision

The 64-bit range of longs and doubles is quite expansive; integers ±263-1 can be represented and operated on, along with decimals ±1.7976931348623157308. Most applications have no need for additional range or precision, so longs and doubles are often perfectly sufficient.

For those applications that do require additional range and/or precision, arbitrary precision numeric representations are available. These representations are always boxed; Clojure uses both clojure.lang.BigInt and java.math.BigInteger to represent arbitrary-range integers, and java.math.BigDecimal for arbitrary-precision decimals.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required