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`.
(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.
(ceil x)Smallest integer ≥ x, in x's unit.
Smallest integer ≥ x, in x's unit.
(floor x)Largest integer ≤ x, in x's unit.
Largest integer ≤ x, in x's unit.
(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.
(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.
(mod x y)x modulo y — conforming, dimension-preserving (keeps x's unit).
x modulo y — conforming, dimension-preserving (keeps x's unit).
(pow x n)Raise to an integer or rational exponent.
Raise to an integer or rational exponent.
(rem x y)Remainder of x by y — conforming, dimension-preserving.
Remainder of x by y — conforming, dimension-preserving.
(round x)Nearest integer (half → +∞), in x's unit.
Nearest integer (half → +∞), in x's unit.
(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.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |