Skip to content

Latest commit

 

History

History
18 lines (13 loc) · 475 Bytes

when-overflow-is-desired.md

File metadata and controls

18 lines (13 loc) · 475 Bytes

When Overflow Is Desired

If you try to add two MAX_VALUE Longs, Clojure is kind enough to warn you.

> (+ Long/MAX_VALUE Long/MAX_VALUE)
ArithmeticException integer overflow  clojure.lang.Numbers.throwIntOverflow (Numbers.java:1424)

However, when overflow is desired, you can use the unchecked operators (e.g. unchecked-add).

> (unchecked-add Long/MAX_VALUE Long/MAX_VALUE)
-2

See also unchecked-subtract and unchecked-multiply.