Collection of basic math functions and constants.
Contains:
Almost all math functions are backed by FastMath library. Almost all operates on primitive double
and returns double
or long
and are inlined.
Inlined function operating on double/longs as a replacement of Clojure numerical tower: *
+
-
/
>
<
>=
<=
==
rem
quot
mod
bit-or
bit-and
bit-xor
bit-and-not
bit-set
bit-clear
bit-test
bit-flip
bit-not
bit-shift-left
bit-shift-right
unsigned-bit-shift-right
inc
dec
zero?
neg?
pos?
min
max
even?
odd?
abs
And additionally:
<<
- bit shift left>>
- signed bit shift right>>>
- unsigned bit shift rightnot==
- not equalTo turn on primitive math on your namespace call use-primitive-operators
.
To turn off and revert original versions call unuse-primitive-operators
which is recomended when Clojure 1.12+ is used.
Collection of basic math functions and constants. Contains: * Basic math functions * Predicates * Bitwise operations * Trigonometry * Log/power * Floating point format operations * Factorial, combinations, gcd/lcd * Additional functions: sampling, rank, lerp Almost all math functions are backed by [FastMath](https://github.com/jeffhain/jafama) library. Almost all operates on primitive `double` and returns `double` or `long` and are inlined. #### Primitive math operators Inlined function operating on double/longs as a replacement of Clojure numerical tower: `*` `+` `-` `/` `>` `<` `>=` `<=` `==` `rem` `quot` `mod` `bit-or` `bit-and` `bit-xor` `bit-and-not` `bit-set` `bit-clear` `bit-test` `bit-flip` `bit-not` `bit-shift-left` `bit-shift-right` `unsigned-bit-shift-right` `inc` `dec` `zero?` `neg?` `pos?` `min` `max` `even?` `odd?` `abs` And additionally: * `<<` - bit shift left * `>>` - signed bit shift right * `>>>` - unsigned bit shift right * `not==` - not equal To turn on primitive math on your namespace call [[use-primitive-operators]]. To turn off and revert original versions call [[unuse-primitive-operators]] which is recomended when Clojure 1.12+ is used.
(*)
(* a)
(* a b)
(* a b c)
(* a b c d)
(* a b c d & r)
Primitive and inlined *
.
Primitive and inlined `*`.
(+)
(+ a)
(+ a b)
(+ a b c)
(+ a b c d)
(+ a b c d & r)
Primitive and inlined +
.
Primitive and inlined `+`.
(- a)
(- a b)
(- a b c)
(- a b c d)
(- a b c d & r)
Primitive and inlined -
.
Primitive and inlined `-`.
(/ a)
(/ a b)
(/ a b c)
(/ a b c d)
(/ a b c d & r)
Primitive and inlined /
.
Primitive and inlined `/`.
(< _)
(< a b)
(< a b & r)
Primitive math less-then function.
Primitive math less-then function.
(<= _)
(<= a b)
(<= a b & r)
Primitive math less-and-equal function.
Primitive math less-and-equal function.
(== _)
(== a b)
(== a b & r)
Primitive math equality function.
Primitive math equality function.
(> _)
(> a b)
(> a b & r)
Primitive math greater-than function.
Primitive math greater-than function.
(>= _)
(>= a b)
(>= a b & r)
Primitive math greater-and-equal function.
Primitive math greater-and-equal function.
(>> x shift)
Shift bits right and keep most significant bit unchanged
Shift bits right and keep most significant bit unchanged
(>>> x shift)
Shift bits right and set most significant bit to 0
Shift bits right and set most significant bit to `0`
(abs x)
Primitive and inlined version of abs.
Primitive and inlined version of abs.
(approx v)
(approx v digits)
Round v
to specified (default: 2) decimal places. Be aware of floating point number accuracy.
Round `v` to specified (default: 2) decimal places. Be aware of floating point number accuracy.
(approx-eq a b)
(approx-eq a b digits)
Checks equality approximately. See approx
.
Checks equality approximately. See [[approx]].
(between-? [x y] v)
(between-? x y v)
Check if given number is within the range (x,y].
Check if given number is within the range (x,y].
(between? [x y] v)
(between? x y v)
Check if given number is within the range [x,y].
Check if given number is within the range [x,y].
(bit-and x)
(bit-and x y)
(bit-and x y & r)
x ∧ y - bitwise AND
x ∧ y - bitwise AND
(bit-and-not x)
(bit-and-not x y)
(bit-and-not x y & r)
x ∧ ~y - bitwise AND (with complement second argument)
x ∧ ~y - bitwise AND (with complement second argument)
(bit-flip x bit)
Flip bit (set to 0
when 1
or to 1
when 0
).
Flip bit (set to `0` when `1` or to `1` when `0`).
(bit-nand x)
(bit-nand x y)
(bit-nand x y & r)
~(x ∧ y) - bitwise NAND
~(x ∧ y) - bitwise NAND
(bit-nor x)
(bit-nor x y)
(bit-nor x y & r)
~(x ∨ y) - bitwise NOR
~(x ∨ y) - bitwise NOR
(bit-or x)
(bit-or x y)
(bit-or x y & r)
x ∨ y - bitwise OR
x ∨ y - bitwise OR
(bit-shift-right x shift)
Shift bits right and keep most significant bit unchanged
Shift bits right and keep most significant bit unchanged
(bit-test x bit)
Test bit (return to true
when 1
or false
when 0
).
Test bit (return to `true` when `1` or `false` when `0`).
(bit-xnor x)
(bit-xnor x y)
(bit-xnor x y & r)
~(x⊕y) - bitwise XNOR
~(x⊕y) - bitwise XNOR
(bit-xor x)
(bit-xor x y)
(bit-xor x y & r)
x⊕y - bitwise XOR
x⊕y - bitwise XOR
(bits->double v)
Convert 64 bits to double
Convert 64 bits to double
(bool-xor x y)
(bool-xor x y & r)
Primitive boolean xor
Primitive boolean xor
(ceil x)
(ceil x scale)
\(\lceil x \rceil\). See: qceil
.
Rounding is done to a multiply of scale value (when provided).
\\(\lceil x \rceil\\). See: [[qceil]]. Rounding is done to a multiply of scale value (when provided).
(co-intervals data)
(co-intervals data number)
(co-intervals data number overlap)
Divide sequence to overlaping intervals containing similar number of values. Same as R's co.intervals()
Divide sequence to overlaping intervals containing similar number of values. Same as R's `co.intervals()`
(combinations n k)
Binomial coefficient (n choose k)
Binomial coefficient (n choose k)
(constrain value mn mx)
Clamp value
to the range [mn,mx]
.
Clamp `value` to the range `[mn,mx]`.
(copy-sign magnitude sign)
Returns a value with a magnitude of first argument and sign of second.
Returns a value with a magnitude of first argument and sign of second.
(cos-interpolation start stop t)
oF interpolateCosine interpolation. See also lerp
/mlerp
, quad-interpolation
or smooth-interpolation
.
oF interpolateCosine interpolation. See also [[lerp]]/[[mlerp]], [[quad-interpolation]] or [[smooth-interpolation]].
(cut data breaks)
(cut x1 x2 breaks)
Cut range or sequence into intervals
Cut range or sequence into intervals
(degrees rad)
Convert radians into degrees.
Convert radians into degrees.
(delta-eq a b)
(delta-eq a b accuracy)
(delta-eq a b abs-tol rel-tol)
Checks equality for given absolute accuracy (default 1.0e-6
).
Version with 4-arity accepts absolute and relative accuracy.
Checks equality for given absolute accuracy (default `1.0e-6`). Version with 4-arity accepts absolute and relative accuracy.
(difference-of-products a b c d)
Kahan's algorithm for (ab)-(cd) to avoid catastrophic cancellation.
Kahan's algorithm for (a*b)-(c*d) to avoid catastrophic cancellation.
(dist [x1 y1] [x2 y2])
(dist x1 y1 x2 y2)
Euclidean distance between points (x1,y1)
and (x2,y2)
. See fastmath.vector
namespace to see other metrics which work on vectors.
Euclidean distance between points `(x1,y1)` and `(x2,y2)`. See [[fastmath.vector]] namespace to see other metrics which work on vectors.
Convert double array into sequence.
Alias for seq
.
Convert double array into sequence. Alias for `seq`.
(double-bits v)
Returns double as 64-bits (long)
Returns double as 64-bits (long)
(double-double-array->seq res)
Convert double array of double arrays into sequence of sequences.
Convert double array of double arrays into sequence of sequences.
(double-exponent v)
Extract exponent information from double
Extract exponent information from double
(double-high-bits v)
Returns high word from double as bits
Returns high word from double as bits
(double-low-bits v)
Returns low word from double as bits
Returns low word from double as bits
Value of 0x1.fffffffffffffp-1d = 0.(9)
Value of 0x1.fffffffffffffp-1d = 0.(9)
(double-significand v)
Extract significand from double
Extract significand from double
(eq _)
(eq a b)
(eq a b & r)
Primitive math equality function.
Primitive math equality function.
(factorial20 n)
Factorial table up to 20!
Factorial table up to 20!
(falling-factorial n x)
Falling (descending) factorial.
Falling (descending) factorial.
(falling-factorial-int n x)
Falling (descending) factorial for integer n.
Falling (descending) factorial for integer n.
(fast*)
(fast* a)
(fast* a b)
(fast* a b & r)
Primitive and inlined *
as a function
Primitive and inlined `*` as a function
(fast+)
(fast+ a)
(fast+ a b)
(fast+ a b & r)
Primitive and inlined +
as a function
Primitive and inlined `+` as a function
(fast-)
(fast- a)
(fast- a b)
(fast- a b & r)
Primitive and inlined -
as a function
Primitive and inlined `-` as a function
(fast-div)
(fast-div a)
(fast-div a b)
(fast-div a b & r)
Primitive and inlined /
as a function
Primitive and inlined `/` as a function
(fast-identity a)
Identity on double.
Identity on double.
(fast-max a)
(fast-max a b)
(fast-max a b & r)
Primitive and inlined max
as a function
Primitive and inlined `max` as a function
(fast-min a)
(fast-min a b)
(fast-min a b & r)
Primitive and inlined min
as a function
Primitive and inlined `min` as a function
(floor x)
(floor x scale)
\(\lfloor x \rfloor\). See: qfloor
.
Rounding is done to a multiply of scale value (when provided).
\\(\lfloor x \rfloor\\). See: [[qfloor]]. Rounding is done to a multiply of scale value (when provided).
(fma x y z)
(x y z)
-> (+ z (* x y))
or Math/fma
for java 9+
`(x y z)` -> `(+ z (* x y))` or `Math/fma` for java 9+
(fpow x exponent)
Fast version of pow where exponent is integer.
Fast version of pow where exponent is integer.
(frac v)
Fractional part, always returns values from 0.0 to 1.0 (exclusive). See sfrac
for signed version.
Fractional part, always returns values from 0.0 to 1.0 (exclusive). See [[sfrac]] for signed version.
(gcd a b)
Fast binary greatest common divisor (Stein's algorithm)
Fast binary greatest common divisor (Stein's algorithm)
(group-by-intervals coll)
(group-by-intervals intervals coll)
Group sequence of values into given intervals.
If intervals
are missing, use co-intervals
to find some.
Group sequence of values into given intervals. If `intervals` are missing, use [[co-intervals]] to find some.
(haversin x)
(haversin [lat1 lon1] [lat2 lon2])
(haversin lat1 lon1 lat2 lon2)
Haversine formula for value or lattitude and longitude pairs.
Haversine formula for value or lattitude and longitude pairs.
(haversine-dist [lat1 lon1] [lat2 lon2])
(haversine-dist lat1 lon1 lat2 lon2)
Haversine distance d
for r=1
Haversine distance `d` for `r=1`
(high-2-exp x)
Find lowest exponent (power of 2) which is greater or equal x
. See low-2-exp
.
Find lowest exponent (power of 2) which is greater or equal `x`. See [[low-2-exp]].
(high-exp b x)
Find lowest exponent for base b
which is higher or equalx
. See also low-exp
.
Find lowest exponent for base `b` which is higher or equal`x`. See also [[low-exp]].
(hypot-sqrt x y)
(hypot-sqrt x y z)
Hypot, sqrt version: \(\sqrt{x^2+y^2}\) or \(\sqrt{x^2+y^2+z^2}\).
Hypot, sqrt version: \\(\sqrt{x^2+y^2}\\) or \\(\sqrt{x^2+y^2+z^2}\\).
(iabs x)
\(|x|\) - long
version. See abs
.
\\(|x|\\) - `long` version. See [[abs]].
(inf? v)
Check if a number is an infinite (positive or negative).
Check if a number is an infinite (positive or negative).
(integer? v)
Check if given real number is an integer.
Check if given real number is an integer.
(inv-factorial n)
Inverse of factorial, 1/n!
Inverse of factorial, 1/n!
(invalid-double? v)
Check if a number is not finite double (NaN or ±Inf).
Check if a number is not finite double (NaN or ±Inf).
(itrunc v)
Truncate fractional part, keep sign. Returns long
.
Truncate fractional part, keep sign. Returns `long`.
(lcm a b)
Fast binary least common multiplier.
Fast binary least common multiplier.
(lerp start stop t)
Linear interpolation between start
and stop
for amount t
. See also mlerp
, cos-interpolation
, quad-interpolation
or smooth-interpolation
.
Linear interpolation between `start` and `stop` for amount `t`. See also [[mlerp]], [[cos-interpolation]], [[quad-interpolation]] or [[smooth-interpolation]].
(log x)
(log base x)
log(x)=ln(x) or logarithm with given base
.
log(x)=ln(x) or logarithm with given `base`.
(log-combinations n k)
Log of binomial coefficient (n choose k)
Log of binomial coefficient (n choose k)
(log-factorial x)
Log factorial, alias to log-gamma
Log factorial, alias to log-gamma
(log2 x)
Logarithm with base 2.
\(\ln_2{x}\)
Logarithm with base 2. \\(\ln_2{x}\\)
(log2int v)
Fast and integer version of log2, returns long
Fast and integer version of log2, returns long
(logb b x)
Logarithm with base b
.
\(\ln_b{x}\)
Logarithm with base `b`. \\(\ln_b{x}\\)
(long-abs x)
\(|x|\) - long
version. See abs
.
\\(|x|\\) - `long` version. See [[abs]].
(long-add)
(long-add a)
(long-add a b)
(long-add a b c)
(long-add a b c d)
(long-add a b c d & r)
Primitive and inlined +
. Coerces arguments and returned value to a long.
Primitive and inlined `+`. Coerces arguments and returned value to a long.
(long-dec x)
Primitive and inlined dec
coerced to a long
Primitive and inlined `dec` coerced to a long
(long-div a)
(long-div a b)
(long-div a b c)
(long-div a b c d)
(long-div a b c d & r)
Primitive and inlined /
. Coerces to arguments and returned value to a long.
Primitive and inlined `/`. Coerces to arguments and returned value to a long.
(long-inc x)
Primitive and inlined inc
coerced to a long
Primitive and inlined `inc` coerced to a long
(long-max a)
(long-max a b)
(long-max a b c)
(long-max a b c d)
(long-max a b c d & r)
Primitive and inlined max
. Coerces arguments and returned values to longs.
Primitive and inlined `max`. Coerces arguments and returned values to longs.
(long-min a)
(long-min a b)
(long-min a b c)
(long-min a b c d)
(long-min a b c d & r)
Primitive and inlined min
. Coerces arguments and returned values to longs.
Primitive and inlined `min`. Coerces arguments and returned values to longs.
(long-mod x y)
Primitive and inlined mod
coerced to longs
Primitive and inlined `mod` coerced to longs
(long-mult)
(long-mult a)
(long-mult a b)
(long-mult a b c)
(long-mult a b c d)
(long-mult a b c d & r)
Primitive and inlined *
. Coerces arguments and returned value to a long.
Primitive and inlined `*`. Coerces arguments and returned value to a long.
(long-quot x y)
Primitive and inlined quot
coerced to longs
Primitive and inlined `quot` coerced to longs
(long-rem x y)
Primitive and inlined rem
coerced to longs
Primitive and inlined `rem` coerced to longs
(long-sub a)
(long-sub a b)
(long-sub a b c)
(long-sub a b c d)
(long-sub a b c d & r)
Primitive and inlined -
. Coerces arguments and returned value to a long.
Primitive and inlined `-`. Coerces arguments and returned value to a long.
(low-2-exp x)
Find greatest exponent (power of 2) which is lower or equal x
. See high-2-exp
.
Find greatest exponent (power of 2) which is lower or equal `x`. See [[high-2-exp]].
(low-exp b x)
Find greatest exponent for base b
which is lower or equal x
. See also high-exp
.
Find greatest exponent for base `b` which is lower or equal `x`. See also [[high-exp]].
ULP(1)/2. Half of the smallest difference between 1.0 and next possible double floating point number.
ULP(1)/2. Half of the smallest difference between 1.0 and next possible double floating point number.
(make-norm start stop)
(make-norm start stop dstart dstop)
Make norm
function for given range. Resulting function accepts double
value (with optional target [dstart,dstop]
range) and returns double
.
Make [[norm]] function for given range. Resulting function accepts `double` value (with optional target `[dstart,dstop]` range) and returns `double`.
(max a)
(max a b)
(max a b c)
(max a b c d)
(max a b c d & r)
Primitive and inlined max
.
Primitive and inlined `max`.
(min a)
(min a b)
(min a b c)
(min a b c d)
(min a b c d & r)
Primitive and inlined min
.
Primitive and inlined `min`.
(mlerp start stop t)
lerp
as macro. For inline code. See also lerp
, cos-interpolation
, quad-interpolation
or smooth-interpolation
.
[[lerp]] as macro. For inline code. See also [[lerp]], [[cos-interpolation]], [[quad-interpolation]] or [[smooth-interpolation]].
(mnorm v start stop)
(mnorm v start1 stop1 start2 stop2)
Macro version of norm
.
Macro version of [[norm]].
(muladd x y z)
(x y z)
-> (+ z (* x y))
or Math/fma
for java 9+
`(x y z)` -> `(+ z (* x y))` or `Math/fma` for java 9+
(near-zero? x)
(near-zero? x abs-tol)
(near-zero? x abs-tol rel-tol)
Checks if given value is near zero with absolute (default: 1.0e-6
) and/or relative (default 0.0
) tolerance.
Checks if given value is near zero with absolute (default: `1.0e-6`) and/or relative (default `0.0`) tolerance.
(neg-inf? v)
Check if a number is negatively infinite.
Check if a number is negatively infinite.
(negative-zero? x)
Check if zero is negative, ie. -0.0
Check if zero is negative, ie. -0.0
(negmuladd x y z)
(x y z)
-> (+ z (* -x y))
or Math/fma
for java 9+
`(x y z)` -> `(+ z (* -x y))` or `Math/fma` for java 9+
(next-double v)
(next-double v delta)
Next double value. Optional value delta
sets step amount.
Next double value. Optional value `delta` sets step amount.
(norm v start stop)
(norm v start1 stop1 start2 stop2)
Normalize v
from the range [start,stop]
to the range [0,1]
or map v
from the range [start1,stop1]
to the range [start2,stop2]
. See also make-norm
.
Normalize `v` from the range `[start,stop]` to the range `[0,1]` or map `v` from the range `[start1,stop1]` to the range `[start2,stop2]`. See also [[make-norm]].
(not-neg? x)
Primitive and inlined not-neg?
(x>=0.0)
Primitive and inlined `not-neg?` (x>=0.0)
(not-pos? x)
Primitive and inlined not-pos?
(x<=0.0)
Primitive and inlined `not-pos?` (x<=0.0)
(not== _)
(not== a b)
(not== a b & r)
Not equality. For more than two arguments, pairwise not equality is checked.
(not== 1 2 1)
=== (and (not= 1 2) (not= 2 1))
Not equality. For more than two arguments, pairwise not equality is checked. `(not== 1 2 1)` === `(and (not= 1 2) (not= 2 1))`
(one? x)
Primitive and inlined one?
(x==1.0)
Primitive and inlined `one?` (x==1.0)
(order vs)
(order vs decreasing?)
Ordering permutation. See R docs
Order uses 0 based indexing.
Ordering permutation. See [R docs](https://www.rdocumentation.org/packages/base/versions/3.6.1/topics/order) Order uses 0 based indexing.
(pos-inf? v)
Check if a number is positively infinite.
Check if a number is positively infinite.
(prev-double v)
(prev-double v delta)
Next double value. Optional value delta
sets step amount.
Next double value. Optional value `delta` sets step amount.
(qceil x)
Fast version of ceil
. Returns long
.
Fast version of [[ceil]]. Returns `long`.
(qexp x)
Quick and less accurate version of exp
.
Quick and less accurate version of [[exp]].
(qfloor x)
Fast version of floor
. Returns long
.
Fast version of [[floor]]. Returns `long`.
(qlog x)
Fast and less accurate version of log
.
Fast and less accurate version of [[log]].
(qpow x exponent)
Fast and less accurate version of pow
.
Fast and less accurate version of [[pow]].
(qround x)
Fast version of round
. Returns long
Fast version of [[round]]. Returns `long`
(qsqrt x)
Approximated sqrt
using binary operations with error 1.0E-2
.
Approximated [[sqrt]] using binary operations with error `1.0E-2`.
(quad-interpolation start stop t)
Quad interpolation. See also lerp
/mlerp
, cos-interpolation
or smooth-interpolation
.
Quad interpolation. See also [[lerp]]/[[mlerp]], [[cos-interpolation]] or [[smooth-interpolation]].
(radians deg)
Convert degrees into radians.
Convert degrees into radians.
(rank vs)
(rank vs ties)
(rank vs ties desc?)
Sample ranks. See R docs.
Rank uses 0 based indexing.
Possible tie strategies: :average
, :first
, :last
, :random
, :min
, :max
, :dense
.
:dense
is the same as in data.table::frank
from R
Sample ranks. See [R docs](https://www.rdocumentation.org/packages/base/versions/3.6.1/topics/rank). Rank uses 0 based indexing. Possible tie strategies: `:average`, `:first`, `:last`, `:random`, `:min`, `:max`, `:dense`. `:dense` is the same as in `data.table::frank` from R
(remainder dividend divisor)
From FastMath
doc: returns dividend - divisor * n,
where n is the mathematical integer closest to dividend/divisor. Returned value in [-|divisor|/2,|divisor|/2]
From `FastMath` doc: returns dividend - divisor * n, where n is the mathematical integer closest to dividend/divisor. Returned value in `[-|divisor|/2,|divisor|/2]`
(rising-factorial n x)
Rising (Pochhammer) factorial.
Rising (Pochhammer) factorial.
(rising-factorial-int n x)
Rising (Pochhammer) factorial for integer n.
Rising (Pochhammer) factorial for integer n.
(round-even x)
Round evenly (like in round in R), IEEE / IEC rounding
Round evenly (like in round in R), IEEE / IEC rounding
(round-up-pow2 v)
Round long to the next power of 2
Round long to the next power of 2
(rqsqrt x)
Reciprocal of qsqrt
. Quick and less accurate.
Reciprocal of [[qsqrt]]. Quick and less accurate.
(safe-sqrt value)
Safe sqrt, for value <= 0 result is 0.
\( \left\{ \begin{array}{lr} 0 & : x \leq 0\\ \sqrt{x} & : x > 0 \end{array} \right. \)
Safe sqrt, for value <= 0 result is 0. \\( \left\\{ \begin{array}{lr} 0 & : x \leq 0\\\\ \sqrt{x} & : x > 0 \end{array} \\right. \\)
(sample f number-of-values)
(sample f number-of-values domain?)
(sample f domain-min domain-max number-of-values)
(sample f domain-min domain-max number-of-values domain?)
Sample function f
and return sequence of values.
range-min
defaults to 0.0, range-max
to 1.0.
Range is inclusive.
When optional domain?
is set to true (default: false) function returns pairs [x,(f x)]
.
Sample function `f` and return sequence of values. `range-min` defaults to 0.0, `range-max` to 1.0. Range is inclusive. When optional `domain?` is set to true (default: false) function returns pairs `[x,(f x)]`.
(seq->double-array vs)
Convert sequence to double array. Returns input if vs
is double array already.
Convert sequence to double array. Returns input if `vs` is double array already.
(seq->double-double-array vss)
Convert sequence to double-array of double-arrays.
If sequence is double-array of double-arrays returns vss
Convert sequence to double-array of double-arrays. If sequence is double-array of double-arrays returns `vss`
(sfrac v)
Fractional part, always returns values from -1.0 to 1.0 (exclusive). See frac
for unsigned version.
Fractional part, always returns values from -1.0 to 1.0 (exclusive). See [[frac]] for unsigned version.
(sgn value)
Return -1 when value
is negative, 1 otherwise. See also signum
.
Return -1 when `value` is negative, 1 otherwise. See also [[signum]].
(signum value)
Return 1 if value
is > 0, 0 if it is 0, -1 otherwise. See also sgn
.
Return 1 if `value` is > 0, 0 if it is 0, -1 otherwise. See also [[sgn]].
(slice-range cnt)
(slice-range start end cnt)
Slice range to get cnt
number of points evenly distanced.
Slice range to get `cnt` number of points evenly distanced.
(smooth-interpolation start stop t)
Smoothstep based interpolation. See also lerp
/mlerp
, quad-interpolation
or cos-interpolation
.
Smoothstep based interpolation. See also [[lerp]]/[[mlerp]], [[quad-interpolation]] or [[cos-interpolation]].
(smooth-max xs)
(smooth-max xs alpha)
(smooth-max xs alpha family)
Smooth maximum function.
A smooth function with alpha
argument. When alpha
goes to infinity, function returns maximum value of xs
.
Family:
:lse
- LogSumExp (default):boltzmann
- Boltzmann operator, works for small alpha values:mellowmax
:p-norm
:smu
- smooth maximum unit, epsilon = 1/alpha > 0Smooth maximum function. A smooth function with `alpha` argument. When `alpha` goes to infinity, function returns maximum value of `xs`. Family: * `:lse` - LogSumExp (default) * `:boltzmann` - Boltzmann operator, works for small alpha values * `:mellowmax` * `:p-norm` * `:smu` - smooth maximum unit, epsilon = 1/alpha > 0
(smoothstep edge0 edge1 x)
GL smoothstep.
GL [smoothstep](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/smoothstep.xhtml).
(sum-of-products a b c d)
Kahan's algorithm for (ab)+(cd) to avoid catastrophic cancellation.
Kahan's algorithm for (a*b)+(c*d) to avoid catastrophic cancellation.
(trunc v)
Truncate fractional part, keep sign. Returns double
.
Truncate fractional part, keep sign. Returns `double`.
(ulp x)
Unit in the Last Place, distance between next value larger than x
and x
Unit in the Last Place, distance between next value larger than `x` and `x`
(unsigned-bit-shift-right x shift)
Shift bits right and set most significant bit to 0
Shift bits right and set most significant bit to `0`
(unuse-primitive-operators)
(unuse-primitive-operators skip-set)
Undoes the work of use-primitive-operators
. This is idempotent.
Undoes the work of [[use-primitive-operators]]. This is idempotent.
(use-primitive-operators)
(use-primitive-operators skip-set)
Replaces Clojure's arithmetic and number coercion functions with primitive equivalents. These are
defined as macros, so they cannot be used as higher-order functions. This is an idempotent operation. Undo with unuse-primitive-operators
.
Replaces Clojure's arithmetic and number coercion functions with primitive equivalents. These are defined as macros, so they cannot be used as higher-order functions. This is an idempotent operation. Undo with [[unuse-primitive-operators]].
(valid-double? v)
Check if a number is finite double.
Check if a number is finite double.
(wrap [start stop] value)
(wrap start stop value)
Wrap overflowed value into the range, similar to ofWrap.
Wrap overflowed value into the range, similar to [ofWrap](http://openframeworks.cc/documentation/math/ofMath/#!show_ofWrap).
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close