math module reference
math module reference
Mathematical functions.
This module is exactly like math-simple, except that the operators
also work componentwise with vectors (num[X]) and matrices (num[X][Y]).
All operators are PureOps.
(+ 1 2 3) #(<num= 6>)
(+ [1 2] [3 4]) #(<num[2]= [4 6]>)
The arguments for an operator generally have to be of the same type. However it is also okay to pass in scalar numbers together with a different type. The scalars will be repeated as necessary to fit the shape of other arguments:
(* [[1 2] [3 4]]
2)
#(<num[2][2]= [[2 4] [6 8]]>)
The mul (*) operator is the only exception to this,
as it handles matrix-matrix and matrix-vector multiplication according to linear algebra.
index
- alias of
mod - alias of
mul - alias of
add - alias of
sub - alias of
div - alias of
idiv - alias of
pow - Get the absolute value.
- Inverse cosine function (radians).
- Add values.
- Inverse sine function (radians).
- Inverse tangent function (radians).
- Inverse tangent function (two argument version).
- Round towards positive infinity.
- Clamp a value to a range.
- Cosine function (radians).
- Hyperbolic cosine function (radians).
- Decrement by 1.
- Divide values.
- *e* number raised to a power.
- Round towards negative infinity.
- Positive infinity constant.
- Divide values and floor.
- Increment by 1.
- Logarithm with optional base.
- Logarithm with base 10.
- Find the maximum.
- Find the minimum.
- Linearly interpolate.
- Modulo operator.
- Multiply scalars, vectors and matrices.
- The pi constant.
- Raise to a power.
- Sine function (radians).
- Hyperbolic sine function (radians).
- Square root function.
- Subtract values.
- Tangent function (radians).
- Hyperbolic tangent function (radians).
- The tau constant.
details
- Get the absolute value.
(abs val) - Inverse cosine function (radians).
(acos cos) - Add values.
(+ a b [c…])(add a b [c…])Sum all arguments.
- Inverse sine function (radians).
(asin sin) - Inverse tangent function (radians).
(atan tan) - Inverse tangent function (two argument version).
(atan2 y x) - Round towards positive infinity.
(ceil val) - Clamp a value to a range.
(clamp min max val)Returns
minifval < min;maxifval > max; andvalotherwise. - Cosine function (radians).
(cos alpha) - Hyperbolic cosine function (radians).
(cosh alpha) - Decrement by 1.
(dec i) - Divide values.
(/ a b [c…])(div a b [c…])Divide
aby all other arguments. - *e* number raised to a power.
(exp exp) - Round towards negative infinity.
(floor val) - Positive infinity constant.
- Divide values and floor.
(// a b [c…])(idiv a b [c…])Divide
aby all other arguments, flooring each time. - Increment by 1.
(inc i) - Logarithm with optional base.
(log val [base]) - Logarithm with base 10.
(log10 val) - Find the maximum.
(max a b [c…])Return the highest of arguments.
- Find the minimum.
(min a b [c…])Return the lowest of arguments.
- Linearly interpolate.
(mix a b i)Interpolate between
aandbusingiin range 0-1. - Modulo operator.
(% num div)(mod num div)Calculate remainder of division by
div. - Multiply scalars, vectors and matrices.
(* a b [c…])(mul a b [c…])Multiplies all arguments.
For every pair of arguments, from left to right:
- If either argument is a scalar, or both are vectors, multiply componentwise.
- If either argument is a matrix and the other is a vector, apply the matrix transformation.
(* num[L][M] num[M]) → num[L](forward transform)(* num[M] num[M][N]) → num[N](reverse transform)
- If both arguments are matrices, multiply them using matrix multiplication.
(* num[L][M] num[M][N]) → num[M][N]
- The pi constant.
- Raise to a power.
(^ base exp)(pow base expRaise
baseto the powerexp. - Sine function (radians).
(sin alpha) - Hyperbolic sine function (radians).
(sinh alpha) - Square root function.
(sqrt val) - Subtract values.
(- a b [c…])(sub a b [c…])Subtract all other arguments from
a. - Tangent function (radians).
(tan alpha) - Hyperbolic tangent function (radians).
(tanh alpha) - The tau constant.