1. Arithmetic Functions
Function | Description | Examples | ||
---|---|---|---|---|
(+x1x2…xn) |
Returns x1+x2+⋯+xn. Returns 0 if no arguments are specified. Throws an |
|
||
(+'x1x2…xn) |
Returns x1+x2+⋯+xn. Returns 0 if no arguments are specified. Converts result automatically into |
|
||
(incx) |
Returns x+1. Throws an |
|
||
(inc'x) |
Returns x+1. Converts result automatically into |
|
||
(-x1x2…xn) |
Returns x1−x2−⋯−xn. Returns −x1 if only one argument is provided. Throws an |
|
||
(-'x1x2…xn) |
Returns x1−x2−⋯−xn. Returns −x1 if only one argument is provided. Converts result automatically into |
|
||
(decx) |
Returns x−1. Throws an |
|
||
(dec'x) |
Returns x−1. Converts result automatically into |
|
||
(*x1x2…xn) |
Returns x1×x2×⋯×xn. Returns 1 if no arguments are specified. Throws an |
|
||
(*'x1x2…xn) |
Returns x1×x2×⋯×xn. Returns 1 if no arguments are specified. Converts result automatically into |
|
||
(/x1x2…xn) |
Returns x1÷x2÷⋯÷xn. Returns 1x1 if only one argument is provided. |
|
||
(quotxy) |
Returns the integer quotient of dividing x by y. |
|
||
(remxy) |
Returns the remainder of dividing x by y.
|
|
||
(modxy) |
Returns xmod (modulus of x and y). This is basically equivalent to: \texttt{(- } x \;\texttt{(* (}\texttt{Math/floor }\texttt{(/ } x\;y\texttt{)) }y\texttt{))}
|
|
2. Numerical Predicates
Function | Description | Examples |
---|---|---|
(\texttt{zero?}\;x) |
Returns |
|
(\texttt{pos?}\;x) |
Returns |
|
(\texttt{neg?}\;x) |
Returns |
|
(\texttt{even?}\;x) |
Returns |
|
(\texttt{odd?}\;x) |
Returns |
|
3. Comparison Functions
Function | Description | Examples | ||
---|---|---|---|---|
(\texttt{=}\;x_1\;x_2\;\ldots\;x_n) |
Returns
|
|
||
(\texttt{==}\;x_1\;x_2\;\ldots\;x_n) |
Returns |
|
||
(\texttt{not=}\;x_1\;x_2\;\ldots\;x_n) |
Same as (\texttt{not}\;(\texttt{=}\;x_1\;x_2\;\ldots\;x_n)).
|
|
||
(\texttt{<}\;x_1\;x_2\;\ldots\;x_n) |
Returns |
|
||
(\texttt{<=}\;x_1\;x_2\;\ldots\;x_n) |
Returns |
|
||
(\texttt{>}\;x_1\;x_2\;\ldots\;x_n) |
Returns |
|
||
(\texttt{>=}\;x_1\;x_2\;\ldots\;x_n) |
Returns |
|
4. Random Numbers
Function | Description | Examples |
---|---|---|
(\texttt{rand}) (\texttt{rand}\;n) |
Returns a random floating point number r, where 0 \leqslant r < n. If n is omitted it defaults to 1. |
|
(\texttt{rand-int}\;n) |
Returns a random integer number r, where 0 \leqslant r < n. |
|
5. Numeric Tower Functions
These are math functions that deal intelligently with the various types in Clojure’s numeric tower.
To use these functions, you need to import them by doing something like this (replace abs
with the function names you want to use):
(require '[clojure.math.numeric-tower :refer [abs]])
Function | Description | Examples |
---|---|---|
(\texttt{abs}\;x) |
Returns \left | x \right | (absolute value of x). |
|
(\texttt{sqrt}\;x) |
Returns \sqrt{x} (square root of x), exact if possible. |
|
(\texttt{expt}\;x\;y) |
Returns x^y (x raised to the power y). |
|
(\texttt{round}\;x) |
Returns \left \lfloor x \right \rceil (x rounded to the nearest integer). Rounds up for values exactly in between two integers. The result is always an integer. |
|
(\texttt{ceil}\;x) |
Returns \left \lceil x \right \rceil (least integer greater than or equal to x, or in other words, x rounded towards +\infty). If x is an exact number, returns an integer, otherwise a double. |
|
(\texttt{floor}\;x) |
Returns \left \lfloor x \right \rfloor (greatest integer less than or equal to x, or in other words, x rounded towards -\infty). If x is an exact number, returns an integer, otherwise a double. |
|
(\texttt{gcd}\;x\;y) |
Returns the greatest common divisor of x and y. Arguments must be integers. |
|
(\texttt{lcm}\;x\;y) |
Returns the least common multiple of x and y. Arguments must be integers. |
|