Math

Math Functions

The mash.math object provides many built-in mathematical functions.

Properties

inf

inf  get

The infinite.

nan

nan  get

Not a number.

### pi

pi  get

Pi 3.14159265358979323846

Methods

abs

mash.math.abs(number: num) -> number

Returns the absolute value of num.

acos

mash.math.acos(number: num) -> number

Returns the arc cosine of num in radians.

acosh

mash.math.acosh(number: num) -> number

Returns the inverse hyperbolic cosine of num, i.e. the value whose hyperbolic cosine is num.

asin

mash.math.asin(number: num) -> number

Returns the arc sine of num in radians.

asinh

mash.math.asinh(number: num) -> number

Returns the inverse hyperbolic sine of num, i.e. the value whose hyperbolic sine is num.

atan

mash.math.atan(number: num) -> number

Returns the arc tangent of num in radians.

atan2

mash.math.atan2(number: x, number: y) -> number

This method calculates the arc tangent of the two variables x and y. It is similar to calculating the arc tangent of y / x, except that the signs of both arguments are used to determine the quadrant of the result.

The method returns the result in radians, which is between -Pi and Pi (inclusive).

atanh

mash.math.atanh(number: num) -> number

Returns the inverse hyperbolic tangent of num, i.e. the value whose hyperbolic tangent is num.

ceil

mash.math.ceil(number: num) -> number

Returns the next highest integer value by rounding up num if necessary.

cos

mash.math.cos(number: num) -> number

Returns the cosine of num. The num parameter is in radians.

cosh

mash.math.cosh(number: num) -> number

Returns the hyperbolic cosine of num, defined as (exp(num) + exp(-num))/2.

exp

mash.math.exp(number: num) -> number

Returns e raised to the power of num.

Notes

e is the base of the natural system of logarithms, or approximately 2.718282.

floor

mash.math.floor(number: num) -> number

Returns the next lowest integer value (as float) by rounding down num if necessary.

isNan

mash.math.isNan(mixed: value) -> boolean

Checks whether value is ‘not a number’ and returns true if so.

log

mash.math.log(number: num, number: ?base = M_E) -> number

Returns the logarithm of num to base, if given, or the natural logarithm.

max

mash.math.max(array: data) -> mixed

Returns the value from data considered “highest” according to standard comparisons. If multiple values of different types evaluate as equal (e.g. 0 and ‘abc’) the first provided to the method will be returned.

min

mash.math.min(array: data) -> mixed

Returns the parameter from data considered “lowest” according to standard comparisons. If multiple values of different types evaluate as equal (e.g. 0 and ‘abc’) the first provided to the method will be returned.

pow

mash.math.pow(number: num, number: exponent) -> number

Returns num raised to the power of exponent.

Notes

It is possible to use the ** operator instead.

random

mash.math.random(number: ?min = 0, number: ?max) -> number

Return a random whole number between the optional min and max values.

round

mash.math.round(number: num, number: ?precision = 0) -> number

Returns the rounded value of num to specified precision (number of digits after the decimal point). precision can also be negative or zero (default).

sin

mash.math.sin(number: num) -> number

Returns the sine of num. The num parameter is in radians.

sinh

mash.math.sinh(number: num) -> number

Returns the hyperbolic sine of num, defined as (exp(num) - exp(-num))/2.

sqrt

mash.math.sqrt(number: num) -> number

Returns the square root of num.

tan

mash.math.tan(number: num) -> number

Returns the tangent of num. The num parameter is in radians.

tanh

mash.math.tanh(number: num) -> number

Returns the hyperbolic tangent of num, defined as sinh(num)/cosh(num).

toBase

mash.math.toBase(string: num, number: from, number: to) -> string

Returns a string containing num represented in base to. The base in which num is given is specified in from. Both from and to have to be between 2 and 36, inclusive. Digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35. Num is interpreted case-insensitively.

toBinary

mash.math.toBinary(number: num) -> string

Returns a string containing a binary representation of num.

toDecimal

mash.math.toDecimal(string: num, number: ?base = 10) -> number

Returns the decimal equivalent of num. The optional base parameter can be one of 2, 8, 10 or 16.

toDegrees

mash.math.toDegrees(number: num) -> number

Converts num from radian to degrees.

toHex

mash.math.toHex(number|string: num) -> number

Returns a string containing a hexadecimal representation of num.

toOct

mash.math.toOct(number: num) -> string

Returns a string containing an octal representation of num.

toRadians

mash.math.toRadians(number: num) -> number

Converts num from degrees to the radian equivalent.

← All articles