API / Core / Math

Math

Functions for interacting with JavaScript Math. See: Math.

abs

RESCRIPT
let abs: float => float

abs(v) returns absolute value of v. See Math.abs on MDN.

Examples

RESCRIPT
Math.abs(-2.0) // 2.0 Math.abs(3.0) // 3.0

acos

RESCRIPT
let acos: float => float

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

RESCRIPT
Math.acos(-1.0) // 3.141592653589793 Math.acos(-3.0)->Float.isNaN // true

acosh

RESCRIPT
let acosh: float => float

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

RESCRIPT
Math.acosh(1.0) // 0.0 Math.acosh(0.5)->Float.isNaN // true

asin

RESCRIPT
let asin: float => float

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

RESCRIPT
Math.asin(-1.0) // -1.5707963267948966 Math.asin(-2.0)->Float.isNaN // true

asinh

RESCRIPT
let asinh: float => float

asinh(v) returns the inverse hyperbolic sine of argument v. See Math.asinh on MDN.

Examples

RESCRIPT
Math.asinh(-1.0) // -0.881373587019543 Math.asinh(-0.0) // -0.0

atan

RESCRIPT
let atan: float => float

atan(v) returns the inverse tangent (in radians) of argument v. See Math.atan on MDN.

Examples

RESCRIPT
Math.atan(-0.0) // -0.0 Math.atan(0.0) // 0.0 Math.atan(1.0) // 0.7853981633974483

atanh

RESCRIPT
let atanh: float => float

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

RESCRIPT
Math.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

RESCRIPT
let atan2: (~y: float, ~x: float) => float

atan2(~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

RESCRIPT
Math.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

RESCRIPT
let cbrt: float => float

cbrt(v) returns the cube root of argument v. See Math.cbrt on MDN.

Examples

RESCRIPT
Math.cbrt(-1.0) // -1.0 Math.cbrt(-0.0) // -0.0 Math.cbrt(0.0) // 0.0

ceil

RESCRIPT
let ceil: float => float

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

RESCRIPT
Math.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

RESCRIPT
let cos: float => float

cos(v) returns the cosine of argument v, which must be specified in radians. See Math.cos on MDN.

Examples

RESCRIPT
Math.cos(-0.0) // 1.0 Math.cos(0.0) // 1.0 Math.cos(1.0) // 0.5403023058681398

cosh

RESCRIPT
let cosh: float => float

cosh(v) returns the hyperbolic cosine of argument v, which must be specified in radians. See Math.cosh on MDN.

Examples

RESCRIPT
Math.cosh(-1.0) // 1.5430806348152437 Math.cosh(-0.0) // 1.0 Math.cosh(0.0) // 1.0

exp

RESCRIPT
let exp: float => float

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

RESCRIPT
Math.exp(-1.0) // 0.36787944117144233 Math.exp(0.0) // 1.0

expm1

RESCRIPT
let expm1: float => float

expm1(v) returns e (the base of natural logarithms) to the power of the given argument v minus 1. See Math.expm1 on MDN.

Examples

RESCRIPT
Math.expm1(-1.0) // -0.6321205588285577 Math.expm1(-0.0) // -0

floor

RESCRIPT
let floor: float => float

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

RESCRIPT
Math.floor(-45.95) // -46.0 Math.floor(-45.05) // -46.0 Math.floor(-0.0) // -0.0

fround

RESCRIPT
let fround: float => float

fround(v) returns the nearest single precision float. See Math.fround on MDN.

Examples

RESCRIPT
Math.fround(5.5) == 5.5 Math.fround(5.05) == 5.050000190734863

hypot

RESCRIPT
let hypot: (float, float) => float

hypot(a, b) returns the square root of the sum of squares of its two arguments (the Pythagorean formula). See Math.hypot on MDN.

Examples

RESCRIPT
Math.hypot(3.0, 4.0) // 5.0 Math.hypot(3.0, 5.0) // 5.8309518948453

hypotMany

RESCRIPT
let hypotMany: array<float> => float

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

RESCRIPT
Math.hypotMany([3.0, 4.0, 5.0]) // 7.0710678118654755 Math.hypotMany([]) // 0.0

log

RESCRIPT
let log: float => float

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

RESCRIPT
Math.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

RESCRIPT
let log1p: float => float

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

RESCRIPT
Math.log1p(-2.0)->Float.isNaN // true Math.log1p(-1.0)->Float.isFinite // false Math.log1p(-0.0) // -0

log10

RESCRIPT
let log10: float => float

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

RESCRIPT
Math.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

RESCRIPT
let log2: float => float

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

RESCRIPT
Math.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

RESCRIPT
let min: (float, float) => float

min(a, b) returns the minimum of its two float arguments. See Math.min on MDN.

Examples

RESCRIPT
Math.min(1.0, 2.0) // 1.0 Math.min(-1.0, -2.0) // -2.0

minMany

RESCRIPT
let minMany: array<float> => float

minMany(arr) returns the minimum of the float in the given array arr. Returns Infinity if arr is empty. See Math.min on MDN.

Examples

RESCRIPT
Math.minMany([1.0, 2.0]) // 1.0 Math.minMany([-1.0, -2.0]) // -2.0 Math.minMany([])->Float.isFinite // false

max

RESCRIPT
let max: (float, float) => float

max(a, b) returns the maximum of its two float arguments. See Math.max on MDN.

Examples

RESCRIPT
Math.max(1.0, 2.0) // 2.0 Math.max(-1.0, -2.0) // -1.0

maxMany

RESCRIPT
let maxMany: array<float> => float

maxMany(arr) returns the maximum of the float in the given array arr. Returns Infinity if arr is empty. See Math.max on MDN.

Examples

RESCRIPT
Math.maxMany([1.0, 2.0]) // 2.0 Math.maxMany([-1.0, -2.0]) // -1.0 Math.maxMany([])->Float.isFinite // false

pow

RESCRIPT
let pow: (float, ~exp: float) => float

pow(a, ~exp) raises the given base a to the given exponent exp. See Math.pow on MDN.

Examples

RESCRIPT
Math.pow(2.0, ~exp=4.0) // 16.0 Math.pow(3.0, ~exp=4.0) // 81.0

random

RESCRIPT
let random: unit => float

random() returns a random number in the half-closed interval [0,1]. See Math.random on MDN.

Examples

RESCRIPT
Math.random()

round

RESCRIPT
let round: float => float

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

RESCRIPT
Math.round(-20.5) // -20.0 Math.round(-0.1) // -0.0 Math.round(0.0) // 0.0 Math.round(-0.0) // -0.0

sign

RESCRIPT
let sign: float => float

sign(v) returns the sign of its foat argument: -1 if negative, 0 if zero, 1 if positive. See Math.sign on MDN.

Examples

RESCRIPT
Math.sign(3.0) // 1.0 Math.sign(-3.0) // 1.0 Math.sign(0.0) // 0.0

sin

RESCRIPT
let sin: float => float

sin(v) returns the sine of argument v, which must be specified in radians. See Math.sin on MDN.

Examples

RESCRIPT
Math.sin(-0.0) // -0.0 Math.sin(0.0) // 0.0 Math.sin(1.0) // 0.8414709848078965

sinh

RESCRIPT
let sinh: float => float

sinh(v) returns then hyperbolic sine of argument v, which must be specified in radians. See Math.sinh on MDN.

Examples

RESCRIPT
Math.sinh(-0.0) // -0.0 Math.sinh(0.0) // 0.0 Math.sinh(1.0) // 1.1752011936438014

sqrt

RESCRIPT
let sqrt: float => float

sqrt(v) returns the square root of v. If v is negative returns NaN. See Math.sqrt on MDN.

Examples

RESCRIPT
Math.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

RESCRIPT
let tan: float => float

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

RESCRIPT
Math.tan(-0.0) // -0.0 Math.tan(0.0) // 0.0 Math.tan(1.0) // 1.5574077246549023

tanh

RESCRIPT
let tanh: float => float

tanh(v) returns the hyperbolic tangent of argument v, which must be specified in radians. See Math.tanh on MDN.

Examples

RESCRIPT
Math.tanh(-0.0) // -0.0 Math.tanh(0.0) // 0.0 Math.tanh(1.0) // 0.7615941559557649

trunc

RESCRIPT
let trunc: float => float

trunc(v) truncates the argument v, i.e., removes fractional digits. See Math.trunc on MDN.

Examples

RESCRIPT
Math.trunc(0.123) // 0.0 Math.trunc(1.999) // 1.0 Math.trunc(13.37) // 13.0 Math.trunc(42.84) // 42.0