Clojure core environment and runtime library providing a dynamic, general-purpose programming language on the JVM.
—
Comprehensive mathematical functions through the clojure.math namespace. These functions provide Clojure wrappers for java.lang.Math static methods, optimized for performance with inlined calls and proper type hints.
Mathematical constants for use in calculations.
clojure.math/E
;; Euler's number e, the base for natural logarithms (≈2.718)
;; Type: double constant
clojure.math/PI
;; Pi, ratio of circumference to diameter (≈3.14159)
;; Type: double constantStandard trigonometric functions with angles in radians.
(clojure.math/sin a)
;; Returns sine of angle a in radians
;; Returns: double
(clojure.math/cos a)
;; Returns cosine of angle a in radians
;; Returns: double
(clojure.math/tan a)
;; Returns tangent of angle a in radians
;; Returns: double
(clojure.math/asin a)
;; Returns arc sine of a, result in range -π/2 to π/2
;; Returns: double
(clojure.math/acos a)
;; Returns arc cosine of a, result in range 0 to π
;; Returns: double
(clojure.math/atan a)
;; Returns arc tangent of a, result in range -π/2 to π/2
;; Returns: double
(clojure.math/atan2 y x)
;; Returns angle θ from rectangular (x,y) to polar (r,θ) coordinates
;; Result in range -π to π
;; Returns: doubleFunctions for converting between degrees and radians.
(clojure.math/to-radians degrees)
;; Converts angle from degrees to radians
;; Returns: double
(clojure.math/to-degrees radians)
;; Converts angle from radians to degrees
;; Returns: doubleExponential, logarithmic, and power functions.
(clojure.math/exp a)
;; Returns e raised to power a
;; Returns: double
(clojure.math/expm1 x)
;; Returns e^x - 1, more accurate than (- (exp x) 1) for small x
;; Returns: double
(clojure.math/log a)
;; Returns natural logarithm (base e) of a
;; Returns: double
(clojure.math/log10 a)
;; Returns base-10 logarithm of a
;; Returns: double
(clojure.math/log1p x)
;; Returns ln(1+x), more accurate than (log (+ 1 x)) for small x
;; Returns: double
(clojure.math/pow a b)
;; Returns a raised to power b
;; Returns: doubleSquare root, cube root, and hypotenuse calculations.
(clojure.math/sqrt a)
;; Returns positive square root of a
;; Returns: double
(clojure.math/cbrt a)
;; Returns cube root of a
;; Returns: double
(clojure.math/hypot x y)
;; Returns sqrt(x² + y²) without intermediate overflow/underflow
;; Returns: doubleFunctions for rounding to integers and controlling precision.
(clojure.math/ceil a)
;; Returns smallest double >= a that equals mathematical integer
;; Returns: double
(clojure.math/floor a)
;; Returns largest double <= a that equals mathematical integer
;; Returns: double
(clojure.math/rint a)
;; Returns double closest to a that equals mathematical integer
;; If two values equally close, returns the even one
;; Returns: double
(clojure.math/round a)
;; Returns closest long to a, ties round toward positive infinity
;; Returns: longOverflow-detecting arithmetic operations that throw on overflow.
(clojure.math/add-exact x y)
;; Returns x + y, throws ArithmeticException on overflow
;; Returns: long
(clojure.math/subtract-exact x y)
;; Returns x - y, throws ArithmeticException on overflow
;; Returns: long
(clojure.math/multiply-exact x y)
;; Returns x * y, throws ArithmeticException on overflow
;; Returns: long
(clojure.math/increment-exact a)
;; Returns a + 1, throws ArithmeticException on overflow
;; Returns: long
(clojure.math/decrement-exact a)
;; Returns a - 1, throws ArithmeticException on overflow
;; Returns: long
(clojure.math/negate-exact a)
;; Returns -a, throws ArithmeticException on overflow
;; Returns: longFloor-based division and modulus operations.
(clojure.math/floor-div x y)
;; Integer division rounding toward negative infinity
;; Returns: long
(clojure.math/floor-mod x y)
;; Integer modulus: x - (floor-div x y) * y
;; Sign matches y, result in range -|y| < r < |y|
;; Returns: long
(clojure.math/IEEE-remainder dividend divisor)
;; Returns IEEE 754 remainder: dividend - divisor * n
;; where n is integer closest to dividend/divisor
;; Returns: doubleHyperbolic trigonometric functions.
(clojure.math/sinh x)
;; Returns hyperbolic sine: (e^x - e^-x)/2
;; Returns: double
(clojure.math/cosh x)
;; Returns hyperbolic cosine: (e^x + e^-x)/2
;; Returns: double
(clojure.math/tanh x)
;; Returns hyperbolic tangent: sinh(x)/cosh(x)
;; Returns: doubleFunctions for working with signs, magnitudes, and floating-point representation.
(clojure.math/signum d)
;; Returns sign of d: -1.0 if negative, 0.0 if zero, 1.0 if positive
;; Returns: double
(clojure.math/copy-sign magnitude sign)
;; Returns value with magnitude of first arg and sign of second
;; Returns: double
(clojure.math/ulp d)
;; Returns size of unit in last place (ULP) for d
;; Returns: doubleLow-level floating-point number manipulation.
(clojure.math/get-exponent d)
;; Returns exponent field of d
;; Returns: int
(clojure.math/next-after start direction)
;; Returns adjacent floating-point number to start toward direction
;; Returns: double
(clojure.math/next-up d)
;; Returns adjacent double in direction of positive infinity
;; Returns: double
(clojure.math/next-down d)
;; Returns adjacent double in direction of negative infinity
;; Returns: double
(clojure.math/scalb d scale-factor)
;; Returns d * 2^scale-factor
;; Returns: doubleSimple random number generation.
(clojure.math/random)
;; Returns pseudorandom double between 0.0 (inclusive) and 1.0 (exclusive)
;; Returns: doubleUsage Examples:
;; Import the namespace
(require '[clojure.math :as math])
;; Basic trigonometry
(math/sin (/ math/PI 2)) ; => 1.0
(math/cos 0) ; => 1.0
(math/tan (/ math/PI 4)) ; => 1.0
;; Angle conversion
(math/to-degrees math/PI) ; => 180.0
(math/to-radians 90) ; => 1.5707963267948966
;; Exponential and logarithmic
(math/exp 1) ; => 2.718281828459045 (≈ e)
(math/log math/E) ; => 1.0
(math/log10 100) ; => 2.0
(math/pow 2 3) ; => 8.0
;; Roots and powers
(math/sqrt 16) ; => 4.0
(math/cbrt 27) ; => 3.0
(math/hypot 3 4) ; => 5.0
;; Rounding
(math/ceil 3.2) ; => 4.0
(math/floor 3.8) ; => 3.0
(math/round 3.6) ; => 4
(math/rint 3.5) ; => 4.0 (rounds to even)
;; Exact arithmetic (throws on overflow)
(math/add-exact 1000000 2000000) ; => 3000000
(try
(math/multiply-exact Long/MAX_VALUE 2)
(catch ArithmeticException e
"Overflow detected"))
;; Floor division and modulus
(math/floor-div 7 3) ; => 2
(math/floor-mod 7 3) ; => 1
(math/floor-div -7 3) ; => -3
(math/floor-mod -7 3) ; => 2
;; Random numbers
(math/random) ; => random double in [0.0, 1.0)
;; Working with constants
(* 2 math/PI 5) ; circumference of circle with radius 5
(math/exp 1) ; => math/E (approximately)Install with Tessl CLI
npx tessl i tessl/maven-org-clojure--clojure