You are currently looking at the v6.0 - v8.2 docs (Reason v3.6 syntax edition). You can find the latest API docs here.
(These docs cover all versions between v3 to v8 and are equivalent to the old BuckleScript docs before the rebrand)
Math
Provide utilities for JS Math. Note: The constants _E, _LN10, _LN2, _LOG10E, _LOG2E, _PI, _SQRT1_2, and _SQRT2 begin with an underscore because ReasonML variable names cannot begin with a capital letter. (Module names begin with upper case.)
_E
RElet _E: float;
Euler's number; ≈ 2.718281828459045. See Math.E on MDN.
_LN2
RElet _LN2: float;
Natural logarithm of 2; ≈ 0.6931471805599453. See Math.LN2 on MDN.
_LN10
RElet _LN10: float;
Natural logarithm of 10; ≈ 2.302585092994046. See Math.LN10 on MDN.
_LOG2E
RElet _LOG2E: float;
Base 2 logarithm of E; ≈ 1.4426950408889634. See Math.LOG2E on MDN.
_LOG10E
RElet _LOG10E: float;
Base 10 logarithm of E; ≈ 0.4342944819032518. See Math.LOG10E on MDN.
_PI
RElet _PI: float;
Pi - ratio of the circumference to the diameter of a circle; ≈ 3.141592653589793. See Math.PI on MDN.
_SQRT1_2
RElet _SQRT1_2: float;
Square root of 1/2; ≈ 0.7071067811865476. See Math.SQRT1_2 on MDN.
_SQRT2
RElet _SQRT2: float;
Square root of 2; ≈ 1.4142135623730951. See Math.SQRT2 on MDN.
abs_int
RElet abs_int: int => int;
Absolute value for integer argument. See Math.abs on MDN.
abs_float
RElet abs_float: float => float;
Absolute value for float argument. See Math.abs on MDN.
acos
RElet acos: float => float;
Arccosine (in radians) of argument; returns NaN if the argument is outside the range [-1.0, 1.0]. See Math.acos on MDN.
acosh
RElet acosh: float => float;
Hyperbolic arccosine (in radians) of argument; returns NaN if the argument is less than 1.0. See Math.acosh on MDN.
asin
RElet asin: float => float;
Arcsine (in radians) of argument; returns NaN if the argument is outside the range [-1.0, 1.0]. See Math.asin on MDN.
asinh
RElet asinh: float => float;
Hyperbolic arcsine (in radians) of argument. See Math.asinh on MDN.
atan
RElet atan: float => float;
Arctangent (in radians) of argument. See Math.atan on MDN.
atanh
RElet atanh: float => float;
Hyperbolic arctangent (in radians) of argument; returns NaN if the argument is is outside the range [-1.0, 1.0]. Returns -Infinity and Infinity for arguments -1.0 and 1.0. See Math.atanh on MDN.
atan2
RElet atan2: (~y: float, ~x: float, unit) => float;
Returns the angle (in radians) of the quotient y /. x. It is also the angle between the x-axis and point (x, y). See Math.atan2 on MDN.
REJs.Math.atan2(~y=0.0, ~x=10.0, ()) == 0.0 ;
Js.Math.atan2(~x=5.0, ~y=5.0, ()) == Js.Math._PI /. 4.0;
Js.Math.atan2(~x=-5.0, ~y=5.0, ());
Js.Math.atan2(~x=-5.0, ~y=5.0, ()) == 3.0 *. Js.Math._PI /. 4.0;
Js.Math.atan2(~x=-0.0, ~y=-5.0, ()) == -. Js.Math._PI /. 2.0;
cbrt
RElet cbrt: float => float;
Cube root. See Math.cbrt on MDN
unsafe_ceil_int
RElet unsafe_ceil_int: float => int;
Returns the smallest integer greater than or equal to the argument. This function may return values not representable by int, whose range is -2147483648 to 2147483647. This is because, in JavaScript, there are only 64-bit floating point numbers, which can represent integers in the range ±(253-1) exactly. See Math.ceil on MDN.
REJs.Math.unsafe_ceil_int(3.1) == 4;
Js.Math.unsafe_ceil_int(3.0) == 3;
Js.Math.unsafe_ceil_int(-3.1) == -3;
Js.Math.unsafe_ceil_int(1.0e15); // result is outside range of int datatype
unsafe_ceil
RElet unsafe_ceil: float => int;
Deprecated; please use unsafe_ceil_int instead.
ceil_int
RElet ceil_int: float => int;
Returns the smallest int greater than or equal to the argument; the result is pinned to the range of the int data type: -2147483648 to 2147483647. See Math.ceil on MDN.
REJs.Math.ceil_int(3.1) == 4;
Js.Math.ceil_int(3.0) == 3;
Js.Math.ceil_int(-3.1) == -3;
Js.Math.ceil_int(-1.0e15) == -2147483648;
Js.Math.ceil_int(1.0e15) == 2147483647;
ceil
RElet ceil: float => int;
Deprecated; please use ceil_int instead.
ceil_float
RElet ceil_float: float => float;
Returns the smallest integral value greater than or equal to the argument. The result is a float and is not restricted to the int data type range. See Math.ceil on MDN.
REJs.Math.ceil_float(3.1) == 4.0;
Js.Math.ceil_float(3.0) == 3.0;
Js.Math.ceil_float(-3.1) == -3.0;
Js.Math.ceil_float(2_150_000_000.3) == 2_150_000_001.0;
clz32
RElet clz32: int => int;
Number of leading zero bits of the argument's 32 bit int representation. See Math.clz32 on MDN.
REJs.Math.clz32(0) == 32;
Js.Math.clz32(-1) == 0;
Js.Math.clz32(255) == 24;
cos
RElet cos: float => float;
Cosine of argument, which must be specified in radians. See Math.cos on MDN.
cosh
RElet cosh: float => float;
Hyperbolic cosine of argument, which must be specified in radians. See Math.cosh on MDN.
exp
RElet exp: float => float;
Natural exponentional; returns e (the base of natural logarithms) to the power of the given argument. See Math.exp on MDN.
expm1
RElet expm1: float => float;
Returns e (the base of natural logarithms) to the power of the given argument minus 1. See Math.expm1 on MDN.
unsafe_floor_int
RElet unsafe_floor_int: float => int;
Returns the largest integer less than or equal to the argument. This function may return values not representable by int, whose range is -2147483648 to 2147483647. This is because, in JavaScript, there are only 64-bit floating point numbers, which can represent integers in the range ±(253-1) exactly. See Math.floor on MDN.
REJs.Math.unsafe_floor_int(3.7) == 3;
Js.Math.unsafe_floor_int(3.0) == 3;
Js.Math.unsafe_floor_int(-3.7) == -4;
Js.Math.unsafe_floor_int(1.0e15); // result is outside range of int datatype
unsafe_floor
RElet unsafe_floor: float => int;
Deprecated; please use unsafe_floor_int instead.
floor_int
RElet floor_int: float => int;
Returns the largest int less than or equal to the argument; the result is pinned to the range of the int data type: -2147483648 to 2147483647. See Math.floor on MDN.
REJs.Math.floor_int(3.7) == 3;
Js.Math.floor_int(3.0) == 3;
Js.Math.floor_int(-3.1) == -4;
Js.Math.floor_int(-1.0e15) == -2147483648;
Js.Math.floor_int(1.0e15) == 2147483647;
floor
RElet floor: float => int;
Deprecated; please use floor_int instead.
floor_float
RElet floor_float: float => float;
Returns the largest integral value less than or equal to the argument. The result is a float and is not restricted to the int data type range. See Math.floor on MDN.
REJs.Math.floor_float(3.7) == 3.0;
Js.Math.floor_float(3.0) == 3.0;
Js.Math.floor_float(-3.1) == -4.0;
Js.Math.floor_float(2_150_000_000.3) == 2_150_000_000.0;
fround
RElet fround: float => float;
Round to nearest single precision float. See Math.fround on MDN.
REJs.Math.fround(5.5) == 5.5;
Js.Math.fround(5.05) == 5.050000190734863;
hypot
RElet hypot: (float, float) => float;
Returns the square root of the sum of squares of its two arguments (the Pythagorean formula). See Math.hypot on MDN.
hypotMany
RElet hypotMany: array(float) => float;
Returns the square root of the sum of squares of the numbers in the array argument (generalized Pythagorean equation). Using an array allows you to have more than two items. See Math.hypot on MDN.
REJs.Math.hypotMany([|3.0, 4.0, 12.0|]) == 13.0;
imul
RElet imul: (int, int) => int;
32-bit integer multiplication. Use this only when you need to optimize performance of multiplication of numbers stored as 32-bit integers. See Math.imul on MDN.
log
RElet log: float => float;
Returns the natural logarithm of its argument; this is the number x such that ex equals the argument. Returns NaN for negative arguments. See Math.log on MDN.
REJs.Math.log(Js.Math._E) == 1.0;
Js.Math.log(100.0) == 4.605170185988092;
log1p
RElet log1p: float => float;
Returns the natural logarithm of one plus the argument. Returns NaN for arguments less than -1. See Math.log1p on MDN.
REJs.Math.log1p(Js.Math._E -. 1.0) == 1.0;
Js.Math.log1p(99.0) == 4.605170185988092;
log10
RElet log10: float => float;
Returns the base 10 logarithm of its argument. Returns NaN for negative arguments. See Math.log10 on MDN.
REJs.Math.log10(1000.0) == 3.0;
Js.Math.log10(0.01) == -2.0;
Js.Math.log10(Js.Math.sqrt(10.0)) == 0.5;
log2
RElet log2: float => float;
Returns the base 2 logarithm of its argument. Returns NaN for negative arguments. See Math.log2 on MDN.
REJs.Math.log2(512.0) == 9.0;
Js.Math.log2(0.125) == -3.0;
Js.Math.log2(Js.Math._SQRT2) == 0.5000000000000001; // due to precision
max_int
RElet max_int: (int, int) => int;
Returns the maximum of its two integer arguments. See Math.max on MDN.
maxMany_int
RElet maxMany_int: array(int) => int;
Returns the maximum of the integers in the given array. See Math.max on MDN.
max_float
RElet max_float: (float, float) => float;
Returns the maximum of its two floating point arguments. See Math.max on MDN.
maxMany_float
RElet maxMany_float: array(float) => float;
Returns the maximum of the floating point values in the given array. See Math.max on MDN.
min_int
RElet min_int: (int, int) => int;
Returns the minimum of its two integer arguments. See Math.min on MDN.
minMany_int
RElet minMany_int: array(int) => int;
Returns the minimum of the integers in the given array. See Math.min on MDN.
min_float
RElet min_float: (float, float) => float;
Returns the minimum of its two floating point arguments. See Math.min on MDN.
minMany_float
RElet minMany_float: array(float) => float;
Returns the minimum of the floating point values in the given array. See Math.min on MDN.
pow_int
RElet pow_int: (~base: int, ~exp: int) => int;
Raises the given base to the given exponent. (Arguments and result are integers.) See Math.pow on MDN.
REJs.Math.pow_int(~base=3, ~exp=4) == 81;
pow_float
RElet pow_float: (~base: float, ~exp: float) => float;
Raises the given base to the given exponent. (Arguments and result are floats.) Returns NaN if the result would be imaginary. See Math.pow on MDN.
REJs.Math.pow_float(~base=3.0, ~exp=4.0) == 81.0;
Js.Math.pow_float(~base=4.0, ~exp=-2.0) == 0.0625;
Js.Math.pow_float(~base=625.0, ~exp=0.5) == 25.0;
Js.Math.pow_float(~base=625.0, ~exp=-0.5) == 0.04;
Js.Float.isNaN(Js.Math.pow_float(~base=-2.0, ~exp=0.5)) == true;
random
RElet random: unit => float;
Returns a random number in the half-closed interval [0,1). See Math.random on MDN.
random_int
RElet random_int: (int, int) => int;
A call to random_int(minVal, maxVal) returns a random number in the half-closed interval [minVal, maxVal). See Math.random on MDN.
unsafe_round
RElet unsafe_round: float => int;
Rounds its argument to nearest integer. For numbers with a fractional portion of exactly 0.5, the argument is rounded to the next integer in the direction of positive infinity. This function may return values not representable by int, whose range is -2147483648 to 2147483647. This is because, in JavaScript, there are only 64-bit floating point numbers, which can represent integers in the range ±(253-1) exactly. See Math.round on MDN.
REJs.Math.unsafe_round(3.7) == 4;
Js.Math.unsafe_round(-3.5) == -3;
Js.Math.unsafe_round(2_150_000_000_000.3); // out of range for int
round
RElet round: float => float;
Rounds to nearest integral value (expressed as a float). See Math.round on MDN.
sign_int
RElet sign_int: int => int;
Returns the sign of its integer argument: -1 if negative, 0 if zero, 1 if positive. See Math.sign on MDN.
sign_float
RElet sign_float: float => float;
Returns the sign of its float argument: -1.0 if negative, 0.0 if zero, 1.0 if positive. See Math.sign on MDN.
sin
RElet sin: float => float;
Sine of argument, which must be specified in radians. See Math.sin on MDN.
sinh
RElet sinh: float => float;
Hyperbolic sine of argument, which must be specified in radians. See Math.sinh on MDN.
sqrt
RElet sqrt: float => float;
Square root. If the argument is negative, this function returns NaN. See Math.sqrt on MDN.
tan
RElet tan: float => float;
Tangent of argument, which must be specified in radians. Returns NaN if the argument is positive infinity or negative infinity. See Math.cos on MDN.
tanh
RElet tanh: float => float;
Hyperbolic tangent of argument, which must be specified in radians. See Math.tanh on MDN.
unsafe_trunc
RElet unsafe_trunc: float => int;
Truncates its argument; i.e., removes fractional digits. This function may return values not representable by int, whose range is -2147483648 to 2147483647. This is because, in JavaScript, there are only 64-bit floating point numbers, which can represent integers in the range ±(253-1) exactly. See Math.trunc on MDN.
trunc
RElet trunc: float => float;
Truncates its argument; i.e., removes fractional digits. See Math.trunc on MDN.