Liking cljdoc? Tell your friends :D

commensura.math

Math functions over quantities and intervals — the ones that carry dimensions.

(require '[commensura.math :as m]) (m/sqrt (c/pow (u/meter 1) 2)) ;=> 1 meter (exact when a perfect root) (m/abs (u/meter -5)) ;=> 5 meter (m/min (u/foot 1) (u/inch 6)) ;=> 6 inch (physical order, keeps the unit) (m/mod (u/hour 25) (u/hour 24));=> 1 hour

Only functions that touch dimensions live here — preserving them (abs/mod/min/max/ floor/ceil/round), scaling them (sqrt/root/pow), or crossing the boundary (sign: dimensioned → dimensionless). Transcendentals (exp/ln/sin/…) are intentionally absent: they only ever map dimensionless → dimensionless, so they belong to plain numeric code.

The monotone functions are interval-aware (mapped over the endpoints, with abs special-cased when the interval spans zero); mod/rem are scalar-only. Names shadow clojure.core, so use this namespace qualified (m/abs), never :refer. Comparisons come from commensura.core.

Math functions over quantities and intervals — the ones that *carry dimensions*.

  (require '[commensura.math :as m])
  (m/sqrt (c/pow (u/meter 1) 2))  ;=> 1 meter        (exact when a perfect root)
  (m/abs  (u/meter -5))           ;=> 5 meter
  (m/min  (u/foot 1) (u/inch 6))  ;=> 6 inch          (physical order, keeps the unit)
  (m/mod  (u/hour 25) (u/hour 24));=> 1 hour

Only functions that touch dimensions live here — preserving them (`abs`/`mod`/`min`/`max`/
`floor`/`ceil`/`round`), scaling them (`sqrt`/`root`/`pow`), or crossing the boundary (`sign`:
dimensioned → dimensionless). Transcendentals (`exp`/`ln`/`sin`/…) are intentionally absent:
they only ever map dimensionless → dimensionless, so they belong to plain numeric code.

The monotone functions are interval-aware (mapped over the endpoints, with `abs` special-cased
when the interval spans zero); `mod`/`rem` are scalar-only. Names shadow `clojure.core`, so use
this namespace qualified (`m/abs`), never `:refer`. Comparisons come from `commensura.core`.
raw docstring

absclj

(abs x)

Absolute value; dimension-preserving. Over a zero-spanning interval the lower bound is 0.

Absolute value; dimension-preserving. Over a zero-spanning interval the lower bound is 0.
sourceraw docstring

ceilclj

(ceil x)

Smallest integer ≥ x, in x's unit.

Smallest integer ≥ x, in x's unit.
sourceraw docstring

floorclj

(floor x)

Largest integer ≤ x, in x's unit.

Largest integer ≤ x, in x's unit.
sourceraw docstring

maxclj

(max x)
(max x y)
(max x y & more)

The physically larger value (variadic); keeps the winner's unit. Conforming.

The physically larger value (variadic); keeps the winner's unit. Conforming.
sourceraw docstring

minclj

(min x)
(min x y)
(min x y & more)

The physically smaller value (variadic); keeps the winner's unit. Conforming.

The physically smaller value (variadic); keeps the winner's unit. Conforming.
sourceraw docstring

modclj

(mod x y)

x modulo y — conforming, dimension-preserving (keeps x's unit).

x modulo y — conforming, dimension-preserving (keeps x's unit).
sourceraw docstring

powclj

(pow x n)

Raise to an integer or rational exponent.

Raise to an integer or rational exponent.
sourceraw docstring

remclj

(rem x y)

Remainder of x by y — conforming, dimension-preserving.

Remainder of x by y — conforming, dimension-preserving.
sourceraw docstring

rootclj

(root x q)

The q-th root.

The q-th root.
sourceraw docstring

roundclj

(round x)

Nearest integer (half → +∞), in x's unit.

Nearest integer (half → +∞), in x's unit.
sourceraw docstring

signclj

(sign x)

Sign of a value: a plain -1, 0, or 1, for a value of any dimension.

Sign of a value: a plain -1, 0, or 1, for a value of any dimension.
sourceraw docstring

sqrtclj

(sqrt x)

Square root.

Square root.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close