fastmath.core

Collection of fast math functions and plethora of constants known from other math libraries.

Primitive math operators

Based on Primitive Math by Zach Tellman several operators are introduced and replace clojure.core functions. All operators are macros and can’t be used as functions. List includes:

Known from Clojure: * + - / > < >= <= == rem quot mod bit-or bit-and bit-xor bit-not bit-shift-left bit-shift-right unsigned-bit-shift-right inc dec zero? neg? pos? min max even? odd?

And additionally:

  • bool-and - and working on booleans
  • bool-or - boolean or
  • bool-xor - boolean xor
  • bool-not - boolean not
  • << - bit shift left
  • >> - signed bit shift right
  • >>> - unsigned bit shift right
  • not== - not equal

Warning: All bool- evaluate all parameters.

To turn on primitive math on your namespace call use-primitive-operators. To turn off and revert original versions call unuse-primitive-operators

Fast Math

Almost all math functions are backed by FastMath library. Most of them are macros. Some of them are wrapped in Clojure functions. Almost all operates on primitive double and returns double (with an exception round or qround which returns long).

Other functions

Additionally namespace contains functions which are common in frameworks like OpenFrameworks and Processing.

Categories

Other vars: co-intervals cut group-by-intervals mnorm next-double prev-double slice-range

Constants

*

macro

(* x)(* x y)(* x y & rest)

A primitive math version of *

+

macro

(+ x)(+ x y)(+ x y & rest)

A primitive math version of +

-

macro

(- x)(- x y)(- x y & rest)

A primitive math version of -

-E

const

;;=> -2.718281828459045

Value of \(e\)

-HALF_PI

const

;;=> -1.5707963267948966

Value of \(-\frac{\pi}{2}\)

-PI

const

;;=> -3.141592653589793

Value of \(-pi\)

-QUARTER_PI

const

;;=> -0.7853981633974483

Value of \(-\frac{\pi}{4}\)

-TAU

const

;;=> -6.283185307179586

Alias for TWO_PI-

-THIRD_PI

const

;;=> -1.0471975511965976

Value of \(-\frac{\pi}{3}\)

-TWO_PI

const

;;=> -6.283185307179586

Value of \(-2 {\pi}\)

/

macro

(/ x)(/ x y)(/ x y & rest)

A primitive math version of /

<

macro

(< x)(< x y)(< x y & rest)

A primitive math version of <

<<

macro

(<< x y)

fastmath.java.PrimitiveMath/shiftLeft function wrapped in macro.

<=

macro

(<= x)(<= x y)(<= x y & rest)

A primitive math version of <=

==

macro

(== x)(== x y)(== x y & rest)

Equality. See also eq for function version.

>

macro

(> x)(> x y)(> x y & rest)

A primitive math version of >

>=

macro

(>= x)(>= x y)(>= x y & rest)

A primitive math version of >=

>>

macro

(>> x y)

fastmath.java.PrimitiveMath/shiftRight function wrapped in macro.

>>>

macro

(>>> x y)

fastmath.java.PrimitiveMath/unsignedShiftRight function wrapped in macro.

abs

(abs x)

\(|x|\) - double version. See iabs.

Examples

Usage

(fastmath.core/abs 1.0)
;;=> 1.0

Plot of abs

acos

macro

(acos x)

net.jafama.FastMath/acos function wrapped in macro.

Examples

Usage

(fastmath.core/acos 1.0)
;;=> 0.0

Plot of acos

acosh

macro

(acosh x)

net.jafama.FastMath/acosh function wrapped in macro.

Examples

Usage

(fastmath.core/acosh 1.0)
;;=> 0.0

Plot of acosh

acot

(acot v)

Arccotangent

Examples

Usage

(fastmath.core/acot 1.0)
;;=> 0.7853981633974483

Plot of acot

acoth

(acoth v)

Area hyperbolic cotangent

Examples

Usage

(fastmath.core/acoth 1.0)
;;=> Infinity

Plot of acoth

acsc

(acsc v)

Arccosecant

Examples

Usage

(fastmath.core/acsc 1.0)
;;=> 1.5707963267948966

Plot of acsc

acsch

(acsch v)

Area hyperbolic cosecant

Examples

Usage

(fastmath.core/acsch 1.0)
;;=> 0.8813735870195429

Plot of acsch

approx

(approx v)(approx v digits)

Round v to specified (default: 2) decimal places. Be aware of double number accuracy.

Examples

Default rounding (2 digits).

(approx 1.232323)
;;=> 1.23

Rounding up to 4 digits.

(approx 1.232323 4)
;;=> 1.2323

approx-eq

(approx-eq a b)(approx-eq a b digits)

Checks equality approximately. See approx.

Examples

Default rounding (2 digits).

(approx-eq 1.232323 1.231999)
;;=> true

Rounding up to 4 digits.

(approx-eq 1.232323 1.23231999 4)
;;=> true

Keep an eye on rounding

(approx-eq 1.2349 1.235)
;;=> false

asec

(asec v)

Arcsecant

Examples

Usage

(fastmath.core/asec 1.0)
;;=> 0.0

Plot of asec

asech

(asech v)

Area hyperbolic secant

Examples

Usage

(fastmath.core/asech 1.0)
;;=> 0.0

Plot of asech

asin

macro

(asin x)

net.jafama.FastMath/asin function wrapped in macro.

Examples

Usage

(fastmath.core/asin 1.0)
;;=> 1.5707963267948966

Plot of asin

asinh

macro

(asinh x)

net.jafama.FastMath/asinh function wrapped in macro.

Examples

Usage

(fastmath.core/asinh 1.0)
;;=> 0.8813735870195429

Plot of asinh

atan

macro

(atan x)

net.jafama.FastMath/atan function wrapped in macro.

Examples

Usage

(fastmath.core/atan 1.0)
;;=> 0.7853981633974483

Plot of atan

atan2

macro

(atan2 x y)

net.jafama.FastMath/atan2 function wrapped in macro.

Examples

atan2 values

(degrees (atan2 1 1))
;;=> 45.0
(degrees (atan2 0 1))
;;=> 0.0
(degrees (atan2 0 -1))
;;=> 180.0

Plot of atan2

atanh

macro

(atanh x)

net.jafama.FastMath/atanh function wrapped in macro.

Examples

Usage

(fastmath.core/atanh 1.0)
;;=> Infinity

Plot of atanh

bessel-j

macro

(bessel-j x y)

Bessel J function value for given order and argument.

Examples

bessel-j values

(bessel-j 1 1)
;;=> 0.44005058574493355
(bessel-j 0 1)
;;=> 0.7651976865579666
(bessel-j 0 10)
;;=> -0.24593576445134827

Plot of bessel-j

between-?

(between-? [x y] v)(between-? x y v)

Check if given number is within the range (x,y].

between?

(between? [x y] v)(between? x y v)

Check if given number is within the range [x,y].

Examples

Examples

(between? [1 4] 2)
;;=> true
(between? [1 4] 5)
;;=> false
(between? [1 4] -2)
;;=> false
(between? [1 4] 1)
;;=> true
(between? 1 4 2)
;;=> true
(between? 1 4 5)
;;=> false
(between? 1 4 -2)
;;=> false
(between? 1 4 1)
;;=> true

;; Test: ok.

bit-and

macro

(bit-and x)(bit-and x y)(bit-and x y & rest)

A primitive math version of bit-and

bit-not

macro

(bit-not x)

fastmath.java.PrimitiveMath/bitNot function wrapped in macro.

bit-or

macro

(bit-or x)(bit-or x y)(bit-or x y & rest)

A primitive math version of bit-or

bit-shift-left

macro

(bit-shift-left x y)

fastmath.java.PrimitiveMath/shiftLeft function wrapped in macro.

bit-shift-right

macro

(bit-shift-right x y)

fastmath.java.PrimitiveMath/shiftRight function wrapped in macro.

bit-xor

macro

(bit-xor x)(bit-xor x y)(bit-xor x y & rest)

A primitive math version of bit-xor

bool-and

macro

(bool-and x)(bool-and x y)(bool-and x y & rest)

A primitive math version of bool-and

bool-not

macro

(bool-not x)

fastmath.java.PrimitiveMath/not function wrapped in macro.

bool-or

macro

(bool-or x)(bool-or x y)(bool-or x y & rest)

A primitive math version of bool-or

bool-xor

macro

(bool-xor x)(bool-xor x y)(bool-xor x y & rest)

A primitive math version of bool-xor

cb

(cb x)

\(x^3\)

Examples

Usage

(fastmath.core/cb 1.0)
;;=> 1.0

Plot of cb

cbrt

macro

(cbrt x)

\(\sqrt[3]{x}\)

Examples

Usage

(fastmath.core/cbrt 1.0)
;;=> 1.0

Plot of cbrt

ceil

(ceil x)

\(\lceil x \rceil\). See: qceil.

Examples

Usage

(fastmath.core/ceil 1.0)
;;=> 1.0

Plot of ceil

cnorm

(cnorm v start1 stop1 start2 stop2)(cnorm v start stop)

Constrained version of norm. Result of norm is applied to constrain to [0,1] or [start2,stop2] ranges.

Examples

Constrain result of norm.

(cnorm 1.5 0 1 100 200)
;;=> 200.0
(cnorm 555 200 500)
;;=> 1.0

co-intervals

(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()

Examples

Usage

(co-intervals [1 2 3 1 2 3 4 5 6 1 2 3 4 5 6 7 1 1 1 1 -1])
;;=> ([-1.5 1.5] [0.5 2.5] [0.5 3.5] [1.5 4.5] [2.5 5.5] [3.5 7.5])

Higher overlap

(co-intervals [1 2 3 1 2 3 4 5 6 1 2 3 4 5 6 7 1 1 1 1 -1] 5 0.95)
;;=> ([-1.5 5.5] [0.5 5.5] [0.5 6.5] [0.5 7.5])

constrain

macro

(constrain value mn mx)

Clamp value to the range [mn,mx].

Examples

Examples

(constrain 0.5 1 2)
;;=> 1.0
(constrain 1.5 1 2)
;;=> 1.5
(constrain 2.5 1 2)
;;=> 2.0

cos

macro

(cos x)

net.jafama.FastMath/cos function wrapped in macro.

Examples

Usage

(fastmath.core/cos 1.0)
;;=> 0.5403023058681398

Plot of cos

cos-interpolation

(cos-interpolation start stop t)

oF interpolateCosine interpolation. See also lerp/mlerp, quad-interpolation or smooth-interpolation.

Examples

Example

(cos-interpolation 0.0 1.0 0.123)
;;=> 0.03686712449046664

Plot of cos-interpolation

cosh

macro

(cosh x)

net.jafama.FastMath/cosh function wrapped in macro.

Examples

Usage

(fastmath.core/cosh 1.0)
;;=> 1.543080634815244

Plot of cosh

cot

(cot v)

Cotangent

Examples

Usage

(fastmath.core/cot 1.0)
;;=> 0.6420926159343308

Plot of cot

coth

(coth v)

Hyperbolic cotangent

Examples

Usage

(fastmath.core/coth 1.0)
;;=> 1.3130352854993315

Plot of coth

csc

(csc v)

Cosecant

Examples

Usage

(fastmath.core/csc 1.0)
;;=> 1.1883951057781215

Plot of csc

csch

(csch v)

Hyperbolic cosecant

Examples

Usage

(fastmath.core/csch 1.0)
;;=> 0.8509181282393214

Plot of csch

cut

(cut data breaks)(cut x1 x2 breaks)

Cut range or sequence into intervals

dec

macro

(dec x)

fastmath.java.PrimitiveMath/dec function wrapped in macro.

deg-in-rad

const

;;=> 0.017453292519943295

\(\frac{\pi}{180}\)

degrees

(degrees rad)

Convert radians into degrees.

Examples

Let’s convert \(\pi\) radians to degrees.

(degrees PI)
;;=> 180.0

digamma

macro

(digamma x)

Logarithmic derivative of \(\Gamma\).

Examples

Usage

(fastmath.core/digamma 1.0)
;;=> -0.5772156677920679

Plot of digamma

dist

(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.

Examples

Distance between two points.

(dist 1 3 -2 10)
;;=> 7.615773105863909

double-array->seq

Convert double array into sequence.

Alias for seq.

Examples

Convert

(double-array->seq (seq->double-array [4 3 2]))
;;=> (4.0 3.0 2.0)

double-array-type

const

;;=> class [D

double-double-array->seq

(double-double-array->seq res)

Convert double array of double arrays into sequence of sequences.

Examples

Convert

(double-double-array->seq (seq->double-double-array
                           [[4 3 2] (double-array [1 2 3])]))
;;=> ((4.0 3.0 2.0) (1.0 2.0 3.0))

double-double-array-type

const

;;=> class [[D

E

const

;;=> 2.718281828459045

Value of \(e\)

EPSILON

const

;;=> 1.0E-10

Very small number \(\varepsilon\)

eq

(eq _)(eq a b)(eq a b c)(eq a b c d)

Primitive math equality function for doubles. See ==.

erf

macro

(erf x)(erf x y)

Error function. For two arguments return difference between (erf x) and (erf y).

Examples

Usage

(fastmath.core/erf 1.0)
;;=> 0.8427007929497151

Plot of erf

Plort of 2d erf

erfc

macro

(erfc x)

Complementary error function.

Examples

Usage

(fastmath.core/erfc 1.0)
;;=> 0.15729920705028488

Plot of erfc

even?

macro

(even? x)

fastmath.java.PrimitiveMath/isEven function wrapped in macro.

exp

macro

(exp x)

net.jafama.FastMath/exp function wrapped in macro.

Examples

Usage

(fastmath.core/exp 1.0)
;;=> 2.7182818284590455

Plot of exp

expm1

macro

(expm1 x)

net.jafama.FastMath/expm1 function wrapped in macro.

Examples

Usage

(fastmath.core/expm1 1.0)
;;=> 1.7182818284590455

Plot of expm1

fast*

(fast* a b)

Primitive * for two arguments as function (not macro).

fast+

(fast+ a b)

Primitive + for two arguments as function (not macro).

fast-

(fast- a b)

Primitive - for two arguments as function (not macro).

fast-identity

(fast-identity a)

Identity on double.

fast-max

(fast-max a b)

Primitive max for two arguments as function (not macro).

fast-min

(fast-min a b)

Primitive min for two arguments as function (not macro).

floor

(floor x)

\(\lfloor x \rfloor\). See: qfloor.

Examples

Usage

(fastmath.core/floor 1.0)
;;=> 1.0

Plot of floor

fpow

macro

(fpow x y)

Fast version of pow where exponent is integer.

Examples

Example

(fpow 1.23 4)
;;=> 2.28886641
(fpow 1.23 4.123)
;;=> 2.28886641
(fpow 1.23 4.999)
;;=> 2.28886641
(fpow 1.23 5)
;;=> 2.8153056842999997
(fpow 1.23 -2)
;;=> 0.6609822195782934

frac

(frac v)

Fractional part, always returns values from 0.0 to 1.0 (exclusive). See sfrac for signed version.

Examples

Examples

(frac 0.555)
;;=> 0.555
(frac -0.555)
;;=> 0.555

Usage

(fastmath.core/frac 1.0)
;;=> 0.0

Plot of frac

GAMMA

const

;;=> 0.5772156649015329

Euler-Mascheroni constant

gamma

macro

(gamma x)

Gamma function \(\Gamma(x)\)

Examples

Usage

(fastmath.core/gamma 1.0)
;;=> 1.0

Plot of gamma

gcd

(gcd a b)

Fast binary greatest common divisor (Stein’s algorithm)

Examples

Usage

(gcd 340 440)
;;=> 20
(gcd (* 123 5544331) (* 123 123))
;;=> 123
(gcd -234 -432)
;;=> 18

group-by-intervals

(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.

Examples

Examples

(group-by-intervals [1 2 3 4 1 2 3 4 5 1 -2])
;;=> {[-2.5 1.5] (1 1 1 -2),
;;=>  [0.5 2.5] (1 2 1 2 1),
;;=>  [1.5 3.5] (2 3 2 3),
;;=>  [2.5 4.5] (3 4 3 4),
;;=>  [3.5 5.5] (4 4 5)}
(group-by-intervals [[1 2] [3 4]] [1 2 3 4 1 2 3 4 5 1 -2])
;;=> {[1 2] (2 2), [3 4] (4 4)}

HALF_PI

const

;;=> 1.5707963267948966

Value of \(\frac{\pi}{2}\)

haversine

(haversine v)(haversine [lat1 lon1] [lat2 lon2])(haversine lat1 lon1 lat2 lon2)

Haversine formula

Examples

Usage

(haversine 10)
;;=> 0.9195357645382263
(haversine [10 20] [30 10])
;;=> 0.17694529423473296
(haversine 10 20 30 10)
;;=> 0.17694529423473296

Usage

(fastmath.core/haversine 1.0)
;;=> 0.22984884706593012

Plot of haversine

haversine-dist

(haversine-dist [lat1 lon1] [lat2 lon2])(haversine-dist lat1 lon1 lat2 lon2)

Haversine distance d for r=1

Examples

Usage

(haversine-dist [10 20] [30 10])
;;=> 0.8683203900985386
(haversine-dist 10 20 30 10)
;;=> 0.8683203900985386

high-2-exp

(high-2-exp v)

Find lowest exponent (power of 2) which is greater or equal x. See low-2-exp.

Examples

Result 5 means, that \(2^5=32\) is greater than 23.11. Lower exponent (4) gives lower value (16).

(high-2-exp 23.11)
;;=> 5

For x less than 1.0 gives negative exponent.

(high-2-exp 0.11)
;;=> -3

Usage

(fastmath.core/high-2-exp 1.0)
;;=> 0

Plot of high-2-exp

high-exp

(high-exp b x)

Find lowest exponent for base b which is higher or equalx. See also low-exp.

Examples

Result 2 means, that \(9^2=81\) is greater than 23.11. Lower exponent 1 gives lower value 9.

(high-exp 9 23.11)
;;=> 2

For x less than 1.0 gives negative exponent.

(high-exp 10 0.011)
;;=> -1

hypot

(hypot x y)(hypot x y z)

Hypot. See also hypot-sqrt.

Examples

Plot of hypot

hypot-sqrt

(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}\). Should be faster than hypot.

Examples

Plot of hypot-sqrt

iabs

(iabs x)

\(|x|\) - long version. See abs.

Examples

Usage

(fastmath.core/iabs 1.0)
;;=> 1

Plot of iabs

inc

macro

(inc x)

fastmath.java.PrimitiveMath/inc function wrapped in macro.

inf?

(inf? v)

Check if number is infinite

Examples

Usage

(inf? ##Inf)
;;=> true
(inf? (/ 0))
;;=> true
(inf? 1)
;;=> false
(inf? ##-Inf)
;;=> true
(inf? ##NaN)
;;=> false

;; Test: ok.

inv-erf

macro

(inv-erf x)

Inverse erf.

Examples

Usage

(fastmath.core/inv-erf 1.0)
;;=> Infinity

Plot of inv-erf

inv-erfc

macro

(inv-erfc x)

Inverse erfc.

Examples

Usage

(fastmath.core/inv-erfc 1.0)
;;=> 0.0

Plot of inv-erfc

inv-gamma-1pm1

macro

(inv-gamma-1pm1 x)

\(\frac{1}{\Gamma(1+x)}\).

Examples

Usage

(fastmath.core/inv-gamma-1pm1 1.0)
;;=> -0.0

Plot of inv-gamma-1pm1

INV_LN2

const

;;=> 1.4426950408889634

\(\frac{1}{\ln{2}}\)

INV_LOG_HALF

const

;;=> -1.4426950408889634

\(\frac{1}{\ln{0.5}}\)

invalid-double?

(invalid-double? v)

Check if number is invalid

Examples

Usage

(invalid-double? ##Inf)
;;=> true
(invalid-double? (/ 0))
;;=> true
(invalid-double? 1)
;;=> false
(invalid-double? ##-Inf)
;;=> true
(invalid-double? ##NaN)
;;=> true

;; Test: ok.

itrunc

(itrunc v)

Truncate fractional part, keep sign. Returns long.

Examples

Examples

(itrunc 1.234)
;;=> 1
(itrunc -1.544)
;;=> -1

Usage

(fastmath.core/itrunc 1.0)
;;=> 1

Plot of itrunc

LANCZOS_G

const

;;=> 4.7421875

Lanchos approximation g constant

lcm

(lcm a b)

Fast binary least common multiplier.

Examples

Usage

(lcm 340 440)
;;=> 7480
(lcm (* 123 331) (* 123 123))
;;=> 5007699
(lcm 331 (* 123 123))
;;=> 5007699
(lcm -234 -432)
;;=> 5616

lerp

(lerp start stop t)

Linear interpolation between start and stop for amount t. See also mlerp, cos-interpolation, quad-interpolation or smooth-interpolation.

Examples

Examples

(lerp 0.0 1.0 0.123)
;;=> 0.123
(lerp 0.0 100.0 0.123)
;;=> 12.3
(lerp 100 200 0.5)
;;=> 150.0

Interpolate outside given range.

(lerp -1.0 1.0 1.5)
;;=> 2.0

Plot of lerp

ln

macro

(ln x)

net.jafama.FastMath/log function wrapped in macro.

Examples

Usage

(fastmath.core/ln 1.0)
;;=> 0.0

Plot of ln

LN10

const

;;=> 2.302585092994046

\(\ln{10}\)

LN2

const

;;=> 0.6931471805599453

\(\ln{2}\)

LN2_2

const

;;=> 0.34657359027997264

\(\frac{\ln{2}}{2}\)

log

macro

(log x)

net.jafama.FastMath/log function wrapped in macro.

Examples

Usage

(fastmath.core/log 1.0)
;;=> 0.0

Plot of log

log-beta

macro

(log-beta x y)

Logarithm of Beta function.

Examples

Plot of log-beta

log-gamma

macro

(log-gamma x)

Gamma function \(\ln\Gamma(x)\)

Examples

Usage

(fastmath.core/log-gamma 1.0)
;;=> -0.0

Plot of log-gamma

log-gamma-1p

macro

(log-gamma-1p x)

Gamma function \(\ln\Gamma(1+x)\)

Examples

Usage

(fastmath.core/log-gamma-1p 1.0)
;;=> 0.0

Plot of log-gamma-1p

log10

macro

(log10 x)

\(\ln_{10}{x}\)

Examples

Usage

(fastmath.core/log10 1.0)
;;=> 0.0

Plot of log10

LOG10E

const

;;=> 0.4342944819032518

\(\log_{10}{e}\)

log1p

macro

(log1p x)

net.jafama.FastMath/log1p function wrapped in macro.

Examples

Usage

(fastmath.core/log1p 1.0)
;;=> 0.6931471805599453

Plot of log1p

log1pexp

(log1pexp x)

log(1+exp(x))

Examples

Usage

(fastmath.core/log1pexp 1.0)
;;=> 1.3132616875182228

Plot of log1pexp

log2

(log2 x)

Logarithm with base 2.

\(\ln_2{x}\)

Examples

Usage

(fastmath.core/log2 1.0)
;;=> 0.0

Plot of log2

LOG2E

const

;;=> 1.4426950408889634

\(\log_{2}{e}\)

logb

(logb b x)

Logarithm with base b.

\(\ln_b{x}\)

logit

(logit x)

Logit function

Examples

Usage

(fastmath.core/logit 1.0)
;;=> Infinity

Plot of logit

low-2-exp

(low-2-exp x)

Find greatest exponent (power of 2) which is lower or equal x. See high-2-exp.

Examples

Result 4 means, that \(2^4=16\) is lower than 23.11. Next exponent (5) gives greater value (32).

(low-2-exp 23.11)
;;=> 4

For x less than 1.0 gives negative exponent.

(low-2-exp 0.11)
;;=> -4

Usage

(fastmath.core/low-2-exp 1.0)
;;=> 0

Plot of low-2-exp

low-exp

(low-exp b x)

Find greatest exponent for base b which is lower or equal x. See also high-exp.

Examples

Result 1 means, that \(9^1=9\) is lower than 23.11. Next exponent 2 gives greater value 82.

(low-exp 9 23.11)
;;=> 1

For x less than 1.0 gives negative exponent.

(low-exp 10 0.011)
;;=> -2

M_1_PI

const

;;=> 0.3183098861837907

\(\frac{1}{\pi}\)

M_2_PI

const

;;=> 0.6366197723675814

\(\frac{2}{\pi}\)

M_2_SQRTPI

const

;;=> 1.1283791670955126

\(\frac{2}{\sqrt\pi}\)

M_3PI_4

const

;;=> 2.356194490192345

\(\frac{3\pi}{4}\)

M_E

const

;;=> 2.718281828459045

\(e\)

M_INVLN2

const

;;=> 1.4426950408889634

\(\frac{1}{\ln{2}}\)

M_IVLN10

const

;;=> 0.43429448190325176

\(\frac{1}{\ln{10}}\)

M_LN10

const

;;=> 2.302585092994046

\(\ln{10}\)

M_LN2

const

;;=> 0.6931471805599453

\(\ln{2}\)

M_LOG10E

const

;;=> 0.4342944819032518

\(\log_{10}{e}\)

M_LOG2_E

const

;;=> 0.6931471805599453

\(\ln{2}\)

M_LOG2E

const

;;=> 1.4426950408889634

\(\log_{2}{e}\)

M_PI

const

;;=> 3.141592653589793

\(\pi\)

M_PI_2

const

;;=> 1.5707963267948966

\(\frac{\pi}{2}\)

M_PI_4

const

;;=> 0.7853981633974483

\(\frac{\pi}{4}\)

M_SQRT1_2

const

;;=> 0.7071067811865475

\(\frac{1}{\sqrt{2}}\)

M_SQRT2

const

;;=> 1.4142135623730951

\(\sqrt{2}\)

M_SQRT3

const

;;=> 1.7320508075688772

\(\sqrt{3}\)

M_SQRT_PI

const

;;=> 1.7724538509055159

\(\sqrt\pi\)

M_TWOPI

const

;;=> 6.283185307179586

\(2\pi\)

MACHINE-EPSILON

const

;;=> 1.1102230246251565E-16

Smallest machine number. Value is calculated during evaluation and may differ on different processors.

make-norm

(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.

Examples

Make cos() normalizer from [-1.0,1.0] to [0.0, 1.0].

(let [norm-cos (make-norm -1.0 1.0 0.0 1.0)] (norm-cos (cos 2.0)))
;;=> 0.29192658172642894

Make normalizer from [0,255] to any range.

(let [norm-0-255 (make-norm 0 255)]
  [(norm-0-255 123 -10 -20) (norm-0-255 123 20 10)])
;;=> [-14.823529411764707 15.176470588235293]

max

macro

(max x)(max x y)(max x y & rest)

A primitive math version of max

min

macro

(min x)(min x y)(min x y & rest)

A primitive math version of min

mlerp

macro

(mlerp start stop t)

lerp as macro. For inline code. See also lerp, cos-interpolation, quad-interpolation or smooth-interpolation.

Examples

Examples

(mlerp 0.0 1.0 0.123)
;;=> 0.123
(mlerp 0.0 100.0 0.123)
;;=> 12.3
(mlerp 100 200 0.5)
;;=> 150.0

Interpolate outside given range.

(mlerp -1.0 1.0 1.5)
;;=> 2.0

mnorm

macro

(mnorm v start stop)(mnorm v start1 stop1 start2 stop2)

Macro version of norm.

Examples

Normalize from [1,-1] to [0,1]

(mnorm 0.234 -1.0 1.0)
;;=> 0.617

Normalize from [-1,1] to [0,1]

(mnorm 0.234 1.0 -1.0)
;;=> 0.383

Normalize cos() to [0,255]

(mnorm (cos HALF_PI) -1.0 1.0 0.0 255.0)
;;=> 127.5

Normalize cos() to [255,0]

(mnorm (cos HALF_PI) -1.0 1.0 255.0 0.0)
;;=> 127.5

mod

macro

(mod x y)

fastmath.java.PrimitiveMath/modulus function wrapped in macro.

Examples

Modulus (compared to clojure.core version).

(mod 3.123 0.333)
;;=> 0.12600000000000006
(mod -3.123 0.333)
;;=> 0.20699999999999996
(mod -3.123 -0.333)
;;=> -0.12600000000000006
(mod 3.123 -0.333)
;;=> -0.20699999999999996
(clojure.core/mod 3.123 0.333)
;;=> 0.1259999999999999
(clojure.core/mod -3.123 0.333)
;;=> 0.20700000000000013
(clojure.core/mod -3.123 -0.333)
;;=> -0.1259999999999999
(clojure.core/mod 3.123 -0.333)
;;=> -0.20700000000000013

nan?

(nan? v)

Check if number is NaN

Examples

Usage

(nan? ##Inf)
;;=> false
(nan? (/ 0))
;;=> false
(nan? 1)
;;=> false
(nan? ##-Inf)
;;=> false
(nan? ##NaN)
;;=> true

;; Test: ok.

neg-inf?

(neg-inf? v)

Check if number is negatively infinite

Examples

Usage

(neg-inf? ##Inf)
;;=> false
(neg-inf? (/ 0))
;;=> false
(neg-inf? 1)
;;=> false
(neg-inf? ##-Inf)
;;=> true
(neg-inf? ##NaN)
;;=> false

;; Test: ok.

neg?

macro

(neg? x)

fastmath.java.PrimitiveMath/isNeg function wrapped in macro.

next-double

(next-double v)(next-double v delta)

Next double value. Optional value delta sets step amount.

Examples

Next double.

(next-double 1234.56789)
;;=> 1234.5678900000003

Next double with delta.

(next-double 1234.56789 1000)
;;=> 1234.5678900002274

norm

(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.

Examples

Normalize from [1,-1] to [0,1]

(norm 0.234 -1.0 1.0)
;;=> 0.617

Normalize from [-1,1] to [0,1]

(norm 0.234 1.0 -1.0)
;;=> 0.383

Normalize cos() to [0,255]

(norm (cos HALF_PI) -1.0 1.0 0.0 255.0)
;;=> 127.5

Normalize cos() to [255,0]

(norm (cos HALF_PI) -1.0 1.0 255.0 0.0)
;;=> 127.5

not==

macro

(not== x)(not== x y)(not== x y & rest)

A primitive math version of not==

odd?

macro

(odd? x)

fastmath.java.PrimitiveMath/isOdd function wrapped in macro.

one?

macro

(one? x)

fastmath.java.PrimitiveMath/isOne function wrapped in macro.

order

(order vs)(order vs decreasing?)

Ordering permutation. See R docs

Order uses 0 based indexing.

Examples

Usage

(order [1 1 3 2 1 1 2 3 4 3])
;;=> (0 1 4 5 3 6 2 7 9 8)

;; Test: ok.

Reverse order

(order [1 1 3 2 1 1 2 3 4 3] true)
;;=> (8 2 7 9 3 6 0 1 4 5)

;; Test: ok.

PHI

const

;;=> 1.618033988749895

Golden ratio \(\varphi\)

PI

const

;;=> 3.141592653589793

Value of \(\pi\)

pos-inf?

(pos-inf? v)

Check if number is positively infinite

Examples

Usage

(pos-inf? ##Inf)
;;=> true
(pos-inf? (/ 0))
;;=> true
(pos-inf? 1)
;;=> false
(pos-inf? ##-Inf)
;;=> false
(pos-inf? ##NaN)
;;=> false

;; Test: ok.

pos?

macro

(pos? x)

fastmath.java.PrimitiveMath/isPos function wrapped in macro.

pow

macro

(pow x y)

net.jafama.FastMath/pow function wrapped in macro.

pow2

(pow2 x)

Same as sq. \(x^2\)

Examples

Usage

(fastmath.core/pow2 1.0)
;;=> 1.0

Plot of pow2

pow3

(pow3 x)

\(x^3\)

Examples

Usage

(fastmath.core/pow3 1.0)
;;=> 1.0

Plot of pow3

prev-double

(prev-double v)(prev-double v delta)

Previous double value. Optional value delta sets step amount.

Examples

Prev double.

(prev-double 1234.56789)
;;=> 1234.5678899999998

Prev double with delta.

(prev-double 1234.56789 1000)
;;=> 1234.5678899997727

qceil

macro

(qceil x)

Fast version of ceil. Returns long. See: ceil.

qcos

macro

(qcos x)

Fast and less accurate cos.

Examples

Compare cos and qcos.

(cos 1.123)
;;=> 0.43298018843109504
(qcos 1.123)
;;=> 0.433093818853152

Usage

(fastmath.core/qcos 1.0)
;;=> 0.540171472729893

Plot of qcos

qdist

(qdist x1 y1 x2 y2)

Quick version of Euclidean distance between points. qsqrt is used instead of sqrt.

Examples

Distance between two points (quick version).

(qdist 1 3 -2 10)
;;=> 7.481406462931432

Distance between two points (accurate version).

(dist 1 3 -2 10)
;;=> 7.615773105863909

qexp

macro

(qexp x)

Quick and less accurate version of exp.

Examples

Compare exp and qexp.

(exp 1.123)
;;=> 3.07406257154899
(qexp 1.123)
;;=> 3.1542205810546875

Usage

(fastmath.core/qexp 1.0)
;;=> 2.799318313598633

Plot of qexp

qfloor

macro

(qfloor x)

Fast version of floor. Returns long. See: floor.

qlog

macro

(qlog x)

Fast and less accurate version of log.

Examples

Compare log and qlog.

(log 23.123)
;;=> 3.1408277931718307
(qlog 23.123)
;;=> 3.1407453502111626

Usage

(fastmath.core/qlog 1.0)
;;=> 0.0

Plot of qlog

qpow

macro

(qpow x y)

Fast and less accurate version of pow.

Examples

Compare pow and qpow.

(pow 1.23 43.3)
;;=> 7814.322402338249
(qpow 1.23 43.3)
;;=> 7808.951363383271

qround

macro

(qround x)

Fast version of round. Returns long. See: rint, round.

qsin

macro

(qsin x)

Fast and less accurate sin.

Examples

Compare sin and qsin.

(sin 1.123)
;;=> 0.901403437105813
(qsin 1.123)
;;=> 0.901348847046022

Usage

(fastmath.core/qsin 1.0)
;;=> 0.8415549774368984

Plot of qsin

qsqrt

macro

(qsqrt x)

Approximated sqrt using binary operations with error 1.0E-2.

Examples

Compare sqrt and qsqrt.

(sqrt 23.123)
;;=> 4.808638060823459
(qsqrt 23.123)
;;=> 4.746781462931431

Usage

(fastmath.core/qsqrt 1.0)
;;=> 0.982050807866429

Plot of qsqrt

quad-interpolation

(quad-interpolation start stop t)

Quad interpolation. See also lerp/mlerp, cos-interpolation or smooth-interpolation.

Examples

Example

(quad-interpolation 0.0 1.0 0.123)
;;=> 0.030258

Plot of quad-interpolation

QUARTER_PI

const

;;=> 0.7853981633974483

Value of \(\frac{\pi}{4}\)

quot

macro

(quot x y)

fastmath.java.PrimitiveMath/quotient function wrapped in macro.

Examples

Quotient (compared to clojure.core version).

(quot 3.123 0.333)
;;=> 9.0
(quot -3.123 0.333)
;;=> -9.0
(quot -3.123 -0.333)
;;=> 9.0
(quot 3.123 -0.333)
;;=> -9.0
(clojure.core/quot 3.123 0.333)
;;=> 9.0
(clojure.core/quot -3.123 0.333)
;;=> -9.0
(clojure.core/quot -3.123 -0.333)
;;=> 9.0
(clojure.core/quot 3.123 -0.333)
;;=> -9.0

rad-in-deg

const

;;=> 57.29577951308232

\(\frac{180}{\pi}\)

radians

(radians deg)

Convert degrees into radians.

Examples

Let’s convert 180 degrees to radians.

(radians 180)
;;=> 3.141592653589793

rank

(rank vs)(rank vs ties)

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

Examples

Usage

(rank [3 1 4 1 5 9 2 6 5 3 5])
;;=> (3.5 0.5 5.0 0.5 7.0 10.0 2.0 9.0 7.0 3.5 7.0)
(rank [3 1 4 1 5 9 2 6 5 3 5] :average)
;;=> (3.5 0.5 5.0 0.5 7.0 10.0 2.0 9.0 7.0 3.5 7.0)
(rank [3 1 4 1 5 9 2 6 5 3 5] :first)
;;=> [3 0 5 1 6 10 2 9 7 4 8]
(rank [3 1 4 1 5 9 2 6 5 3 5] :last)
;;=> [4 1 5 0 8 10 2 9 7 3 6]
(rank [3 1 4 1 5 9 2 6 5 3 5] :min)
;;=> (3 0 5 0 6 10 2 9 6 3 6)
(rank [3 1 4 1 5 9 2 6 5 3 5] :max)
;;=> (4 1 5 1 8 10 2 9 8 4 8)
(rank [3 1 4 1 5 9 2 6 5 3 5] :dense)
;;=> (2 0 3 0 4 6 1 5 4 2 4)

;; Test: ok.

Random ties

(rank [3 1 4 1 5 9 2 6 5 3 5] :random)
;;=> [4 1 5 0 6 10 2 9 7 3 8]
(rank [3 1 4 1 5 9 2 6 5 3 5] :random)
;;=> [4 1 5 0 8 10 2 9 7 3 6]
(rank [3 1 4 1 5 9 2 6 5 3 5] :random)
;;=> [4 1 5 0 6 10 2 9 8 3 7]
(rank [3 1 4 1 5 9 2 6 5 3 5] :random)
;;=> [3 1 5 0 6 10 2 9 8 4 7]

regularized-beta

macro

(regularized-beta x y z)

Regularized Beta.

regularized-gamma-p

macro

(regularized-gamma-p x y)

Regularized gamma P

regularized-gamma-q

macro

(regularized-gamma-q x y)

Regularized gamma Q

rem

macro

(rem x y)

fastmath.java.PrimitiveMath/remainder function wrapped in macro.

Examples

Remainder (compared to clojure.core version).

(rem 3.123 0.333)
;;=> 0.12600000000000006
(rem -3.123 0.333)
;;=> -0.12600000000000006
(rem -3.123 -0.333)
;;=> -0.12600000000000006
(rem 3.123 -0.333)
;;=> 0.12600000000000006
(clojure.core/rem 3.123 0.333)
;;=> 0.1259999999999999
(clojure.core/rem -3.123 0.333)
;;=> -0.1259999999999999
(clojure.core/rem -3.123 -0.333)
;;=> -0.1259999999999999
(clojure.core/rem 3.123 -0.333)
;;=> 0.1259999999999999

remainder

macro

(remainder x y)

From FastMath doc: returns dividend - divisor * n, where n is the mathematical integer closest to dividend/divisor. Returned value in [-|divisor|/2,|divisor|/2]

Examples

Compare with rem and mod.

(remainder 3.123 0.2)
;;=> -0.07699999999999996
(rem 3.123 0.2)
;;=> 0.12300000000000005
(mod 3.123 0.2)
;;=> 0.12300000000000005

rint

(rint x)

Round to double. See round, qround.

Examples

Round to double.

(rint PI)
;;=> 3.0

Usage

(fastmath.core/rint 1.0)
;;=> 1.0

Plot of rint

round

(round x)

Round to long. See: rint, qround.

Examples

Round to long.

(round PI)
;;=> 3

Usage

(fastmath.core/round 1.0)
;;=> 1

Plot of round

round-even

(round-even x)

Round evenly (like in round in R), IEEE / IEC rounding

round-up-pow2

(round-up-pow2 v)

Round long to the next power of 2

Examples

Examples

(round-up-pow2 1023)
;;=> 1024
(round-up-pow2 1024)
;;=> 1024
(round-up-pow2 1025)
;;=> 2048

Usage

(fastmath.core/round-up-pow2 1.0)
;;=> 1

Plot of round-up-pow2

rqsqrt

macro

(rqsqrt x)

Inversed version of qsqrt. Quick and less accurate.

Examples

Usage

(fastmath.core/rqsqrt 1.0)
;;=> 0.9662250423950712

Plot of rqsqrt

safe-sqrt

(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. \)

Examples

Usage

(fastmath.core/safe-sqrt 1.0)
;;=> 1.0

Plot of safe-sqrt

sample

(sample f number-of-values)(sample f number-of-values domain?)(sample f range-min range-max number-of-values)(sample f range-min range-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)].

Examples

Usage

(sample identity 10)
;;=> (0.0
;;=>  0.1111111111111111
;;=>  0.2222222222222222
;;=>  0.3333333333333333
;;=>  0.4444444444444444
;;=>  0.5555555555555556
;;=>  0.6666666666666666
;;=>  0.7777777777777778
;;=>  0.8888888888888888
;;=>  1.0)
(sample identity -11 22 5)
;;=> (-11.0 -2.75 5.5 13.75 22.0)
(sample sq 1 5 5)
;;=> (1.0 4.0 9.0 16.0 25.0)
(sample sq 1 5 5 true)
;;=> ([1.0 1.0] [2.0 4.0] [3.0 9.0] [4.0 16.0] [5.0 25.0])

sec

(sec v)

Secant

Examples

Usage

(fastmath.core/sec 1.0)
;;=> 1.8508157176809255

Plot of sec

sech

(sech v)

Hyperbolic secant

Examples

Usage

(fastmath.core/sech 1.0)
;;=> 0.6480542736638853

Plot of sech

seq->double-array

(seq->double-array vs)

Convert sequence to double array. Returns input if vs is double array already.

Examples

Convert

(seq->double-array [1 2 3])
;;=> [D@123561f2
(seq (seq->double-array [1 2 3]))
;;=> (1.0 2.0 3.0)
(double-array->seq (seq->double-array [1 2 3]))
;;=> (1.0 2.0 3.0)

Also works on number (treated as one element list).

(seq (seq->double-array 1))
;;=> (1.0)

seq->double-double-array

(seq->double-double-array vss)

Convert sequence to double-array of double-arrays.

If sequence is double-array of double-arrays returns vss

Examples

Convert

(seq->double-double-array [[1 2] [3 4]])
;;=> [[D@42f3dac6
(double-double-array->seq (seq->double-double-array [[1 2] [3 4]]))
;;=> ((1.0 2.0) (3.0 4.0))

Also works on seq of numbers

(seq (second (seq->double-double-array [1 2 3])))
;;=> (2.0)

sfrac

(sfrac v)

Fractional part, always returns values from -1.0 to 1.0 (exclusive). See frac for unsigned version.

Examples

Examples

(sfrac 0.555)
;;=> 0.555
(sfrac -0.555)
;;=> -0.555

Usage

(fastmath.core/sfrac 1.0)
;;=> 0.0

Plot of sfrac

sgn

(sgn value)

Return -1 when value is negative, 1 otherwise. See also signum.

\( \left\{ \begin{array}{lr} 1.0 & : x \geq 0\\ -1.0 & : x < 0\\ \end{array} \right. \)

Examples

Usage

(fastmath.core/sgn 1.0)
;;=> 1.0

Plot of sgn

sigmoid

(sigmoid x)

Sigmoid function

Examples

Usage

(fastmath.core/sigmoid 1.0)
;;=> 0.7310585786300049

Plot of sigmoid

signum

(signum value)

Return 1 if value is > 0, 0 if it is 0, -1 otherwise. See also sgn.

\( \left\{ \begin{array}{lr} 1.0 & : x > 0\\ -1.0 & : x < 0\\ 0.0 & : x = 0 \end{array} \right. \)

Examples

Usage

(fastmath.core/signum 1.0)
;;=> 1.0

Plot of signum

sin

macro

(sin x)

net.jafama.FastMath/sin function wrapped in macro.

Examples

Usage

(fastmath.core/sin 1.0)
;;=> 0.8414709848078964

Plot of sin

sinc

(sinc v)

Sinc function.

Examples

Usage

(fastmath.core/sinc 1.0)
;;=> 3.898171832295186E-17

Plot of sinc

sinh

macro

(sinh x)

net.jafama.FastMath/sinh function wrapped in macro.

Examples

Usage

(fastmath.core/sinh 1.0)
;;=> 1.1752011936438016

Plot of sinh

SIXTH

const

;;=> 0.16666666666666666

Value of \(\frac{1}{6}\)

slice-range

(slice-range start end cnt)(slice-range cnt)

Slice range to get cnt number of points evenly distanced.

smooth-interpolation

(smooth-interpolation start stop t)

Smoothstep based interpolation. See also lerp/mlerp, quad-interpolation or cos-interpolation.

Examples

Example

(smooth-interpolation 0.0 1.0 0.123)
;;=> 0.041665266

Plot of smooth-interpolation

smoothstep

(smoothstep edge0 edge1 x)

Examples

x from range.

(smoothstep 100 200 120)
;;=> 0.10400000000000002

corner case (< x edge0)

(smoothstep 100 200 50)
;;=> 0.0

corner case (> x edge1)

(smoothstep 100 200 250)
;;=> 1.0

sq

(sq x)

Same as pow2. \(x^2\)

Examples

Usage

(fastmath.core/sq 1.0)
;;=> 1.0

Plot of sq

sqrt

macro

(sqrt x)

\(\sqrt{x}\)

Examples

Usage

(fastmath.core/sqrt 1.0)
;;=> 1.0

Plot of sqrt

SQRT2

const

;;=> 1.4142135623730951

\(\sqrt{2}\)

SQRT2_2

const

;;=> 0.7071067811865476

\(\frac{\sqrt{2}}{2}\)

SQRT2PI

const

;;=> 2.5066282746310002

\(\sqrt{2\pi}\)

SQRT3

const

;;=> 1.7320508075688772

\(\sqrt{3}\)

SQRT3_2

const

;;=> 0.8660254037844386

\(\frac{\sqrt{3}}{2}\)

SQRT3_3

const

;;=> 0.5773502691896257

\(\frac{\sqrt{3}}{3}\)

SQRT5

const

;;=> 2.23606797749979

\(\sqrt{5}\)

SQRTPI

const

;;=> 1.7724538509055159

\(\sqrt{\pi}\)

tan

macro

(tan x)

net.jafama.FastMath/tan function wrapped in macro.

Examples

Usage

(fastmath.core/tan 1.0)
;;=> 1.5574077246549018

Plot of tan

tanh

macro

(tanh x)

net.jafama.FastMath/tanh function wrapped in macro.

Examples

Usage

(fastmath.core/tanh 1.0)
;;=> 0.7615941559557649

Plot of tanh

TAU

const

;;=> 6.283185307179586

Alias for TWO_PI

THIRD

const

;;=> 0.3333333333333333

Value of \(\frac{1}{3}\)

THIRD_PI

const

;;=> 1.0471975511965976

Value of \(\frac{\pi}{3}\)

trigamma

macro

(trigamma x)

Derivative of digamma.

Examples

Usage

(fastmath.core/trigamma 1.0)
;;=> 1.6449340668481562

Plot of trigamma

trunc

(trunc v)

Truncate fractional part, keep sign. Returns double.

Examples

Examples

(trunc 1.234)
;;=> 1.0
(trunc -1.544)
;;=> -1.0

Usage

(fastmath.core/trunc 1.0)
;;=> 1.0

Plot of trunc

TWO_PI

const

;;=> 6.283185307179586

Value of \(2 {\pi}\)

TWO_THIRD

const

;;=> 0.6666666666666666

Value of \(\frac{2}{3}\)

unsigned-bit-shift-right

macro

(unsigned-bit-shift-right x y)

fastmath.java.PrimitiveMath/unsignedShiftRight function wrapped in macro.

unuse-primitive-operators

(unuse-primitive-operators)

Undoes the work of use-primitive-operators. This is idempotent.

use-primitive-operators

(use-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?

(valid-double? v)

Check if number is invalid

Examples

Usage

(valid-double? ##Inf)
;;=> false
(valid-double? (/ 0))
;;=> false
(valid-double? 1)
;;=> true
(valid-double? ##-Inf)
;;=> false
(valid-double? ##NaN)
;;=> false

;; Test: ok.

wrap

(wrap start stop value)

Wrap overflowed value into the range, similar to ofWrap.

Examples

Example 1

(wrap 0 -1 1)
;;=> -1.0

Example 2 (value outside range)

(wrap -1.1 -1 1.5)
;;=> -1.0000000000000022

Example 3 (reversed range)

(wrap 0.7 0.5 1.0)
;;=> 0.6000000000000001

Plot of wrap

zero?

macro

(zero? x)

fastmath.java.PrimitiveMath/isZero function wrapped in macro.