class MathHelper implements ProtectedContextAwareInterface (View source)

Math helpers for Eel contexts

The implementation sticks to the JavaScript specificiation including EcmaScript 6 proposals.

See https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Math for a documentation and specification of the JavaScript implementation.

Methods

float
getE()

No description

float
getLN2()

No description

float
getLN10()

No description

float
getLOG2E()

No description

float
getLOG10E()

No description

float
getPI()

No description

float
getSQRT1_2()

No description

float
getSQRT2()

No description

float
abs(float $x = NAN)

No description

float
acos(float $x)

No description

float
acosh(float $x)

No description

float
asin(float $x)

No description

float
asinh(float $x)

No description

float
atan(float $x)

No description

float
atanh(float $x)

No description

float
atan2(float $y, float $x)

No description

float
cbrt(float $x)

No description

float
ceil(float $x)

No description

float
cos(float $x)

No description

float
cosh(float $x)

No description

float
exp(float $x)

No description

float
expm1(float $x)

No description

float
floor(float $x)

No description

bool
isFinite(mixed $x)

Test if the given value is a finite number

bool
isInfinite(mixed $x)

Test if the given value is an infinite number (INF or -INF)

bool
isNaN(mixed $x)

Test if the given value is not a number (either not numeric or NAN)

float
hypot(float $x, float $y, float $z_ = null)

No description

float
log(float $x)

No description

float
log1p(float $x)

No description

float
log10(float $x)

No description

float
log2(float $x)

No description

float
max(float $x = null, float $y_ = null)

No description

float
min(float $x = null, float $y_ = null)

No description

float
pow(float $x, float $y)

Calculate the power of x by y

float
random()

Get a random foating point number between 0 (inclusive) and 1 (exclusive)

int
randomInt(int $min, int $max)

Get a random integer number between a min and max value (inclusive)

float
round(mixed $subject, int $precision = 0)

Rounds the subject to the given precision

int
sign(int|float $x)

Get the sign of the given number, indicating whether the number is positive, negative or zero

float
sin(float $x)

No description

float
sinh(float $x)

No description

float
sqrt(float $x)

No description

float
tan(float $x)

No description

float
tanh(float $x)

No description

int|float
trunc(float $x)

Get the integral part of the given number by removing any fractional digits

bool
allowsCallOfMethod(string $methodName)

All methods are considered safe

Details

float getE()

No description

Return Value

float

Euler's constant and the base of natural logarithms, approximately 2.718

float getLN2()

No description

Return Value

float

Natural logarithm of 2, approximately 0.693

float getLN10()

No description

Return Value

float

Natural logarithm of 10, approximately 2.303

float getLOG2E()

No description

Return Value

float

Base 2 logarithm of E, approximately 1.443

float getLOG10E()

No description

Return Value

float

Base 10 logarithm of E, approximately 0.434

float getPI()

No description

Return Value

float

Ratio of the circumference of a circle to its diameter, approximately 3.14159

float getSQRT1_2()

No description

Return Value

float

Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707

float getSQRT2()

No description

Return Value

float

Square root of 2, approximately 1.414

float abs(float $x = NAN)

No description

Parameters

float $x

A number

Return Value

float

The absolute value of the given value

float acos(float $x)

No description

Parameters

float $x

A number

Return Value

float

The arccosine (in radians) of the given value

float acosh(float $x)

No description

Parameters

float $x

A number

Return Value

float

The hyperbolic arccosine (in radians) of the given value

float asin(float $x)

No description

Parameters

float $x

A number

Return Value

float

The arcsine (in radians) of the given value

float asinh(float $x)

No description

Parameters

float $x

A number

Return Value

float

The hyperbolic arcsine (in radians) of the given value

float atan(float $x)

No description

Parameters

float $x

A number

Return Value

float

The arctangent (in radians) of the given value

float atanh(float $x)

No description

Parameters

float $x

A number

Return Value

float

The hyperbolic arctangent (in radians) of the given value

float atan2(float $y, float $x)

No description

Parameters

float $y

A number

float $x

A number

Return Value

float

The arctangent of the quotient of its arguments

float cbrt(float $x)

No description

Parameters

float $x

A number

Return Value

float

The cube root of the given value

float ceil(float $x)

No description

Parameters

float $x

A number

Return Value

float

The smallest integer greater than or equal to the given value

float cos(float $x)

No description

Parameters

float $x

A number given in radians

Return Value

float

The cosine of the given value

float cosh(float $x)

No description

Parameters

float $x

A number

Return Value

float

The hyperbolic cosine of the given value

float exp(float $x)

No description

Parameters

float $x

A number

Return Value

float

The power of the Euler's constant with the given value (e^x)

float expm1(float $x)

No description

Parameters

float $x

A number

Return Value

float

The power of the Euler's constant with the given value minus 1 (e^x - 1)

float floor(float $x)

No description

Parameters

float $x

A number

Return Value

float

The largest integer less than or equal to the given value

bool isFinite(mixed $x)

Test if the given value is a finite number

This is equivalent to the global isFinite() function in JavaScript.

Parameters

mixed $x

A value

Return Value

bool

true if the value is a finite (not NAN) number

bool isInfinite(mixed $x)

Test if the given value is an infinite number (INF or -INF)

This function has no direct equivalent in JavaScript.

Parameters

mixed $x

A value

Return Value

bool

true if the value is INF or -INF

bool isNaN(mixed $x)

Test if the given value is not a number (either not numeric or NAN)

This is equivalent to the global isNaN() function in JavaScript.

Parameters

mixed $x

A value

Return Value

bool

true if the value is not a number

float hypot(float $x, float $y, float $z_ = null)

No description

Parameters

float $x

A number

float $y

A number

float $z_

Optional variable list of additional numbers

Return Value

float

The square root of the sum of squares of the arguments

float log(float $x)

No description

Parameters

float $x

A number

Return Value

float

The natural logarithm (base e) of the given value

float log1p(float $x)

No description

Parameters

float $x

A number

Return Value

float

The natural logarithm (base e) of 1 + the given value

float log10(float $x)

No description

Parameters

float $x

A number

Return Value

float

The base 10 logarithm of the given value

float log2(float $x)

No description

Parameters

float $x

A number

Return Value

float

The base 2 logarithm of the given value

float max(float $x = null, float $y_ = null)

No description

Parameters

float $x

A number

float $y_

Optional variable list of additional numbers

Return Value

float

The largest of the given numbers (zero or more)

float min(float $x = null, float $y_ = null)

No description

Parameters

float $x

A number

float $y_

Optional variable list of additional numbers

Return Value

float

The smallest of the given numbers (zero or more)

float pow(float $x, float $y)

Calculate the power of x by y

Parameters

float $x

The base

float $y

The exponent

Return Value

float

The base to the exponent power (x^y)

float random()

Get a random foating point number between 0 (inclusive) and 1 (exclusive)

That means a result will always be less than 1 and greater or equal to 0, the same way Math.random() works in JavaScript.

See Math.randomInt(min, max) for a function that returns random integer numbers from a given interval.

Return Value

float

A random floating point number between 0 (inclusive) and 1 (exclusive), that is from [0, 1)

int randomInt(int $min, int $max)

Get a random integer number between a min and max value (inclusive)

That means a result will always be greater than or equal to min and less than or equal to max.

Parameters

int $min

The lower bound for the random number (inclusive)

int $max

The upper bound for the random number (inclusive)

Return Value

int

A random number between min and max (inclusive), that is from [min, max]

float round(mixed $subject, int $precision = 0)

Rounds the subject to the given precision

The precision defines the number of digits after the decimal point. Negative values are also supported (-1 rounds to full 10ths).

Parameters

mixed $subject

The value to round

int $precision

The precision (digits after decimal point) to use, defaults to 0

Return Value

float

The rounded value

int sign(int|float $x)

Get the sign of the given number, indicating whether the number is positive, negative or zero

Parameters

int|float $x

The value

Return Value

int

-1, 0, 1 depending on the sign or NAN if the given value was not numeric

float sin(float $x)

No description

Parameters

float $x

A number given in radians

Return Value

float

The sine of the given value

float sinh(float $x)

No description

Parameters

float $x

A number

Return Value

float

The hyperbolic sine of the given value

float sqrt(float $x)

No description

Parameters

float $x

A number

Return Value

float

The square root of the given number

float tan(float $x)

No description

Parameters

float $x

A number given in radians

Return Value

float

The tangent of the given value

float tanh(float $x)

No description

Parameters

float $x

A number

Return Value

float

The hyperbolic tangent of the given value

int|float trunc(float $x)

Get the integral part of the given number by removing any fractional digits

This function doesn't round the given number but merely calls ceil(x) or floor(x) depending on the sign of the number.

Parameters

float $x

A number

Return Value

int|float

The integral part of the given number or NAN if the given value was not numeric

bool allowsCallOfMethod(string $methodName)

All methods are considered safe

Parameters

string $methodName

Return Value

bool