HH\Lib\Math

Math\abs()

function abs<T as num>(T $number): T  Returns the absolute value of $number ($number if $number > 0, -$number if $number < 0).

function base_convert(string $value, int$from_base, int $to_base): string  Converts the given string in base $from_base to base $to_base, assuming letters a-z are used for digits for bases greater than 10. The conversion is done to arbitrary precision. To convert a string in some base to an int, see Math\from_base. To convert an int to a string in some base, see Math\to_base. Math\ceil() function ceil(num$value): float


Returns the smallest integer value greater than or equal to $value. To find the largest integer value less than or equal to $value, see Math\floor.

Math\cos()

function cos(num $arg): float  Returns the cosine of $arg.

To find the sine, see Math\sin. To find the tangent, see Math\tan.

Math\exp()

function exp(num $arg): float  Returns e to the power $arg.

To find the logarithm, see Math\log.

Math\floor()

function floor(num $value): float  Returns the largest integer value less than or equal to $value.

To find the smallest integer value greater than or equal to $value, see Math\ceil. To find the largest integer value less than or equal to a ratio, see Math\int_div. Math\from_base() function from_base(string$number, int $from_base): int  Converts the given string in the given base to an int, assuming letters a-z are used for digits when $from_base > 10.

To base convert an int into a string, see Math\to_base.

Math\int_div()

function int_div(int $numerator, int$denominator): int


Returns the result of integer division of $numerator by $denominator.

To round a single value, see Math\floor.

Math\log()

function log(num $arg, ?num$base = null): float


Returns the logarithm base $base of $arg.

For the exponential function, see Math\exp.

(function(T):num) $num_func, ): ?T  Returns the largest element of the given Traversable, or null if the Traversable is empty. The value for comparison is determined by the given function. In the case of duplicate numeric keys, later values overwrite previous ones. For numeric elements, see Math\max. Math\maxva() function maxva<T as num>(T$first, T ...$rest): T  Returns the largest of all input numbers. To find the smallest number, see Math\minva. For Traversables, see Math\max. Math\mean() function mean(Container<num>$numbers): ?float


Returns the arithmetic mean of the numbers in the given container.

To find the sum, see Math\sum. To find the maximum, see Math\max. To find the minimum, see Math\min.

function median(Container<num> $numbers): ?float  Returns the median of the given numbers. To find the mean, see Math\mean. Math\min() function min<T as num>(Traversable<T>$numbers): ?T


Returns the smallest element of the given Traversable, or null if the Traversable is empty.

For a known number of inputs, see Math\minva. To find the largest number, see Math\max.

Math\min_by()

function min_by<T>(
Traversable<T> $traversable, (function(T):num)$num_func,
): ?T


Returns the smallest element of the given Traversable, or null if the Traversable is empty.

The value for comparison is determined by the given function. In the case of duplicate numeric keys, later values overwrite previous ones.

For numeric elements, see Math\min.

Math\minva()

function minva<T as num>(T $first, T ...$rest): T


Returns the smallest of all input numbers.

To find the largest number, see Math\maxva. For Traversables, see Math\min.

Math\round()

function round(num $val, int$precision = 0): float


Returns the given number rounded to the specified precision. A positive precision rounds to the nearest decimal place whereas a negative precision rounds to the nearest power of ten. For example, a precision of 1 rounds to the nearest tenth whereas a precision of -1 rounds to the nearest ten.

Math\sin()

function sin(num $arg): float  Returns the sine of$arg.

To find the cosine, see Math\cos. To find the tangent, see Math\tan.

Math\sqrt()

function sqrt(num $arg): float  Returns the square root of $arg.

function sum(Traversable<int> $traversable): int  Returns the integer sum of the values of the given Traversable. For a float sum, see Math\sum_float. Math\sum_float() function sum_float<T as num>(Traversable<T>$traversable): float


Returns the float sum of the values of the given Traversable.

For an integer sum, see Math\sum.

Math\tan()

function tan(num $arg): float  Returns the tangent of $arg.

To find the cosine, see Math\cos. To find the sine, see Math\sin.

Math\to_base()

function to_base(int $number, int$to_base): string


Converts the given non-negative number into the given base, using letters a-z for digits when \$to_base > 10.

To base convert a string to an int, see Math\from_base.