website is under construction
Standard Library

Math

The math module provides a set of mathematical functions and constants.

Methods

abs()

Returns the absolute, or non-negative value, of a given value.

math.abs(-100)

// expected value: 100

cos()

Returns the cosine of the radian argument.

math.cos(math.pi / 2).round()

// expected value: 0

isNegative()

Determines if the specified value is negative.

math.isNegative(-100)

// expected value: true

isPositive()

Determines if the specified value is positive.

math.isPositive(100)

// expected value: true

isZero()

Determines if the specified value is zero.

math.isZero(5)

// expected value: false

max()

Returns the largest of two numbers.

math.max(100, 200)

// expected value: 200

min()

Returns the smallest of two numbers.

math.min(100, 200)

// expected value: 100

sin()

Returns the sine of the radian argument.

math.sin(math.pi).round()

// expected value: 0

tan()

Returns the tangent of the radian argument.

math.tan(0).round()

// expected value: 0

Properties

e

The mathematical constant e = 2.718281…, use the round() method to round down to the desired precision.

math.e.round(2)

// expected value: 2.72

epsilon

The mathematical constant 𝜀 = 2.220446049250e-16, represents the smallest value that a float can have different from zero.

math.epsilon

// expected value: 0.00000000000000022204460492503130808472633361816

pi

The mathematical constant π = 3.141592…, use the round() method to round down to the desired precision.

math.pi.round(2)

// expected value: 3.14

tau

The mathematical constant τ = 6.283185…, use the round() method to round down to the desired precision.

math.tau.round(2)

// expected value: 6.28