Skip to content

p-math

The math module provides all JavaScript Math methods and lowercase constant aliases.

use p-math as m
NameValueDescription
pi3.141592653589793Ratio of a circle’s circumference to its diameter
e2.718281828459045Euler’s number
ln20.6931471805599453Natural logarithm of 2
ln102.302585092994046Natural logarithm of 10
log2e1.4426950408889634Base-2 logarithm of e
log10e0.4342944819032518Base-10 logarithm of e
sqrt21.4142135623730951Square root of 2
sqrt1_20.7071067811865476Square root of 1/2
use p-math as m
console.log[m.pi] -- 3.141592653589793
console.log[m.e] -- 2.718281828459045

Returns the largest integer less than or equal to x.

Returns the smallest integer greater than or equal to x.

Returns x rounded to the nearest integer.

Returns the integer part of x by removing any fractional digits.

use p-math as m
m.floor[4.7] -- 4
m.ceil[4.1] -- 5
m.round[4.5] -- 5
m.trunc[4.9] -- 4

Returns the absolute value of x.

Returns -1, 0, or 1 indicating the sign of x.

Returns the largest of the given numbers.

Returns the smallest of the given numbers.

Returns base raised to the power exp.

Returns the square root of x.

Returns the cube root of x.

Returns the square root of the sum of squares of its arguments.

Returns the number of leading zero bits in the 32-bit integer representation of x.

Returns the nearest 32-bit single precision float representation of x.

Returns the result of the C-like 32-bit multiplication of a and b.

use p-math as m
m.abs[-5] -- 5
m.max[1; 2; 3] -- 3
m.min[1; 2; 3] -- 1
m.sqrt[16] -- 4
m.hypot[3; 4] -- 5

Standard trigonometric functions. x is in radians.

Inverse trigonometric functions. Returns radians.

Returns the angle in radians between the positive x-axis and the point (x, y).

Hyperbolic functions.

Inverse hyperbolic functions.

use p-math as m
m.sin[m.pi div 2] -- 1
m.cos[0] -- 1
m.atan2[1; 1] -- 0.7853... (π/4)

Returns the natural logarithm (base e) of x.

Returns the base-2 logarithm of x.

Returns the base-10 logarithm of x.

Returns e raised to the power x.

Returns e^x - 1, accurate for small values of x.

Returns the natural logarithm of 1 + x, accurate for small values of x.

use p-math as m
m.log[m.e] -- 1
m.log2[8] -- 3
m.log10[1000] -- 3
m.exp[1] -- 2.718281828459045

Returns a floating-point number in [0, 1). For more random utilities, see the random module.

use p-math as m
const x be m.random[] -- e.g. 0.4231...