ClojureDocs

Nav

Namespaces

abs

clojure.core

Available since 1.11 (source)
  • (abs a)
Returns the absolute value of a.
If a is Long/MIN_VALUE => Long/MIN_VALUE
If a is a double and zero => +0.0
If a is a double and ##Inf or ##-Inf => ##Inf
If a is a double and ##NaN => ##NaN
2 Examples
(abs -10) ;; => 10
;; As indicated in its documentation, abs can return a negative value!

(abs Long/MIN_VALUE)
;;=> -9223372036854775808

;; This is, because -Long/MIN_VALUE > Long/MAX_VALUE:
;; (* -1 Long/MIN_VALUE)
;;=> Execution error (ArithmeticException) at java.lang.Math/multiplyExact
;;=> (Math.java:1032).
;;=> long overflow
See Also
No see-alsos for clojure.core/abs
0 Notes
No notes for abs