Math
Functions for interacting with JavaScript Math.
See: Math.
abs
let abs: float => floatabs(v) returns absolute value of v.
See Math.abs on MDN.
Examples
RESCRIPTMath.abs(-2.0) // 2.0
Math.abs(3.0) // 3.0
acos
let acos: float => floatacos(v) returns arccosine (in radians) of argument v, returns NaN if the
argument is outside the range [-1.0, 1.0].
See Math.acos on MDN.
Examples
RESCRIPTMath.acos(-1.0) // 3.141592653589793
Math.acos(-3.0)->Float.isNaN // true
acosh
let acosh: float => floatacosh(v) returns the inverse hyperbolic arccosine (in radians) of argument v,
returns NaN if the argument is less than 1.0.
See Math.acosh on MDN.
Examples
RESCRIPTMath.acosh(1.0) // 0.0
Math.acosh(0.5)->Float.isNaN // true
asin
let asin: float => floatasin(v) returns the inverse sine (in radians) of argument v, returns NaN
if the argument v is outside the range [-1.0, 1.0].
See Math.asin on MDN.
Examples
RESCRIPTMath.asin(-1.0) // -1.5707963267948966
Math.asin(-2.0)->Float.isNaN // true
asinh
let asinh: float => floatasinh(v) returns the inverse hyperbolic sine of argument v.
See Math.asinh on MDN.
Examples
RESCRIPTMath.asinh(-1.0) // -0.881373587019543
Math.asinh(-0.0) // -0.0
atan
let atan: float => floatatan(v) returns the inverse tangent (in radians) of argument v.
See Math.atan on MDN.
Examples
RESCRIPTMath.atan(-0.0) // -0.0
Math.atan(0.0) // 0.0
Math.atan(1.0) // 0.7853981633974483
atanh
let atanh: float => floatatanh(v) returns the invert hyperbolic tangent of argument v. Returns NaN
if the argument v is is outside the range [-1.0, 1.0] and Infinity if v
is -1.0 or 1.0.
See Math.atanh on MDN.
Examples
RESCRIPTMath.atanh(-2.0)->Float.isNaN // true
Math.atanh(-1.0)->Float.isFinite // false
Math.atanh(-0.0) // -0.0
Math.atanh(0.0) // 0.0
Math.atanh(0.5) // 0.5493061443340548
atan2
let atan2: (~y: float, ~x: float) => floatatan2(~y, ~x) 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.
Examples
RESCRIPTMath.atan2(~y=0.0, ~x=10.0) == 0.0
Math.atan2(~x=5.0, ~y=5.0) == Math.Constants.pi /. 4.0
Math.atan2(~x=90.0, ~y=15.0) // 1.4056476493802699
Math.atan2(~x=15.0, ~y=90.0) // 0.16514867741462683
cbrt
let cbrt: float => floatcbrt(v) returns the cube root of argument v.
See Math.cbrt on MDN.
Examples
RESCRIPTMath.cbrt(-1.0) // -1.0
Math.cbrt(-0.0) // -0.0
Math.cbrt(0.0) // 0.0
ceil
let ceil: float => floatceil(v) returns the smallest integral value greater than or equal to the
argument v. The result is a float and is not restricted to the int data
type range.
See Math.ceil on MDN.
Examples
RESCRIPTMath.ceil(3.1) == 4.0
Math.ceil(3.0) == 3.0
Math.ceil(-3.1) == -3.0
Math.ceil(2_150_000_000.3) == 2_150_000_001.0
cos
let cos: float => floatcos(v) returns the cosine of argument v, which must be specified in radians.
See Math.cos on MDN.
Examples
RESCRIPTMath.cos(-0.0) // 1.0
Math.cos(0.0) // 1.0
Math.cos(1.0) // 0.5403023058681398
cosh
let cosh: float => floatcosh(v) returns the hyperbolic cosine of argument v, which must be specified
in radians.
See Math.cosh on MDN.
Examples
RESCRIPTMath.cosh(-1.0) // 1.5430806348152437
Math.cosh(-0.0) // 1.0
Math.cosh(0.0) // 1.0
exp
let exp: float => floatexp(v) returns natural exponentional, returns e (the base of natural logarithms)
to the power of the given argument v.
See Math.exp on MDN.
Examples
RESCRIPTMath.exp(-1.0) // 0.36787944117144233
Math.exp(0.0) // 1.0
expm1
let expm1: float => floatexpm1(v) returns e (the base of natural logarithms) to the power of the given
argument v minus 1.
See Math.expm1 on MDN.
Examples
RESCRIPTMath.expm1(-1.0) // -0.6321205588285577
Math.expm1(-0.0) // -0
floor
let floor: float => floatfloor(v) returns the largest integral value less than or equal to the argument
v. The result is a float and is not restricted to the int data type range.
See Math.floor on MDN.
Examples
RESCRIPTMath.floor(-45.95) // -46.0
Math.floor(-45.05) // -46.0
Math.floor(-0.0) // -0.0
fround
let fround: float => floatfround(v) returns the nearest single precision float.
See Math.fround on MDN.
Examples
RESCRIPTMath.fround(5.5) == 5.5
Math.fround(5.05) == 5.050000190734863
hypot
let hypot: (float, float) => floathypot(a, b) returns the square root of the sum of squares of its two arguments
(the Pythagorean formula).
See Math.hypot on MDN.
Examples
RESCRIPTMath.hypot(3.0, 4.0) // 5.0
Math.hypot(3.0, 5.0) // 5.8309518948453
hypotMany
let hypotMany: array<float> => floathypotMany(arr) 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. If arr is an empty array then returns 0.0.
See Math.hypot on MDN.
Examples
RESCRIPTMath.hypotMany([3.0, 4.0, 5.0]) // 7.0710678118654755
Math.hypotMany([]) // 0.0
log
let log: float => floatlog(v) returns the natural logarithm of argument v, this is the number x
such that e^x equals the argument. Returns NaN for negative arguments and
Infinity for 0.0 or -0.0.
See Math.log on MDN.
Examples
RESCRIPTMath.log(-1.0)->Float.isNaN // true
Math.log(-0.0)->Float.isFinite // false
Math.log(0.0)->Float.isFinite // false
Math.log(1.0) // 0
log1p
let log1p: float => floatlog1p(v) returns the natural logarithm of one plus the argument v.
Returns NaN for arguments less than -1 and Infinity if v is -1.0.
See Math.log1p on MDN.
Examples
RESCRIPTMath.log1p(-2.0)->Float.isNaN // true
Math.log1p(-1.0)->Float.isFinite // false
Math.log1p(-0.0) // -0
log10
let log10: float => floatlog10(v) returns the base 10 logarithm of argument v. Returns NaN for
negative v. If v is -0.0 or 0.0 returns Infinity.
See Math.log10 on MDN.
Examples
RESCRIPTMath.log10(-2.0)->Float.isNaN // true
Math.log10(-0.0)->Float.isFinite // false
Math.log10(0.0)->Float.isFinite // false
Math.log10(1.0) // 0
log2
let log2: float => floatlog2(v) returns the base 2 logarithm of argument v. Returns NaN for
negative v and Infinity if v is -0.0 or 0.0.
See Math.log2 on MDN.
Examples
RESCRIPTMath.log2(-2.0)->Float.isNaN // true
Math.log2(-0.0)->Float.isFinite // false
Math.log2(0.0)->Float.isFinite // false
Math.log2(1.0) // 0.0
min
let min: (float, float) => floatmin(a, b) returns the minimum of its two float arguments.
See Math.min on MDN.
Examples
RESCRIPTMath.min(1.0, 2.0) // 1.0
Math.min(-1.0, -2.0) // -2.0
minMany
let minMany: array<float> => floatminMany(arr) returns the minimum of the float in the given array arr.
Returns Infinity if arr is empty.
See Math.min on MDN.
Examples
RESCRIPTMath.minMany([1.0, 2.0]) // 1.0
Math.minMany([-1.0, -2.0]) // -2.0
Math.minMany([])->Float.isFinite // false
max
let max: (float, float) => floatmax(a, b) returns the maximum of its two float arguments.
See Math.max on MDN.
Examples
RESCRIPTMath.max(1.0, 2.0) // 2.0
Math.max(-1.0, -2.0) // -1.0
maxMany
let maxMany: array<float> => floatmaxMany(arr) returns the maximum of the float in the given array arr.
Returns Infinity if arr is empty.
See Math.max on MDN.
Examples
RESCRIPTMath.maxMany([1.0, 2.0]) // 2.0
Math.maxMany([-1.0, -2.0]) // -1.0
Math.maxMany([])->Float.isFinite // false
pow
let pow: (float, ~exp: float) => floatpow(a, ~exp) raises the given base a to the given exponent exp.
See Math.pow on MDN.
Examples
RESCRIPTMath.pow(2.0, ~exp=4.0) // 16.0
Math.pow(3.0, ~exp=4.0) // 81.0
random
let random: unit => floatrandom() returns a random number in the half-closed interval [0,1].
See Math.random on MDN.
Examples
RESCRIPTMath.random()
round
let round: float => floatround(v) returns then value of v rounded to nearest integral value
(expressed as a float). If the fractional portion of the argument v is greater
than 0.5, the argument v is rounded to the float with the next higher
absolute value.
See Math.round on MDN.
Examples
RESCRIPTMath.round(-20.5) // -20.0
Math.round(-0.1) // -0.0
Math.round(0.0) // 0.0
Math.round(-0.0) // -0.0
sign
let sign: float => floatsign(v) returns the sign of its foat argument: -1 if negative, 0 if
zero, 1 if positive.
See Math.sign on MDN.
Examples
RESCRIPTMath.sign(3.0) // 1.0
Math.sign(-3.0) // 1.0
Math.sign(0.0) // 0.0
sin
let sin: float => floatsin(v) returns the sine of argument v, which must be specified in radians.
See Math.sin on MDN.
Examples
RESCRIPTMath.sin(-0.0) // -0.0
Math.sin(0.0) // 0.0
Math.sin(1.0) // 0.8414709848078965
sinh
let sinh: float => floatsinh(v) returns then hyperbolic sine of argument v, which must be specified
in radians.
See Math.sinh on MDN.
Examples
RESCRIPTMath.sinh(-0.0) // -0.0
Math.sinh(0.0) // 0.0
Math.sinh(1.0) // 1.1752011936438014
sqrt
let sqrt: float => floatsqrt(v) returns the square root of v. If v is negative returns NaN.
See Math.sqrt on MDN.
Examples
RESCRIPTMath.sqrt(-1.0)->Float.isNaN // true
Math.sqrt(-0.0) // -0.0
Math.sqrt(0.0) // 0.0
Math.sqrt(1.0) // 1.0
Math.sqrt(9.0) // 3.0
tan
let tan: float => floattan(v) returns the tangent of argument v, which must be specified in
radians. Returns NaN if v is positive Infinity or negative Infinity.
See Math.tan on MDN.
Examples
RESCRIPTMath.tan(-0.0) // -0.0
Math.tan(0.0) // 0.0
Math.tan(1.0) // 1.5574077246549023
tanh
let tanh: float => floattanh(v) returns the hyperbolic tangent of argument v, which must be
specified in radians.
See Math.tanh on MDN.
Examples
RESCRIPTMath.tanh(-0.0) // -0.0
Math.tanh(0.0) // 0.0
Math.tanh(1.0) // 0.7615941559557649
trunc
let trunc: float => floattrunc(v) truncates the argument v, i.e., removes fractional digits.
See Math.trunc on MDN.
Examples
RESCRIPTMath.trunc(0.123) // 0.0
Math.trunc(1.999) // 1.0
Math.trunc(13.37) // 13.0
Math.trunc(42.84) // 42.0