numbers v2.0.0 Numbers

Allows you to perform math on any kind of data structure that follows the Numeric behaviour.

This includes plain Integer and Floats, but also many custom numeric types specified in packages (such as Ratio, Decimal, Tensor, ComplexNum).

Summary

Functions

Computes the absolute value of num

Computes the unary minus of num, also known as its negation

Power function: computes base^exponent, where base is Numeric, and exponent has to be an integer

Tries to convert num to a built-in floating-point number

Functions

abs(num)

Computes the absolute value of num.

add(a, b)
div(a, b)
minus(num)

Computes the unary minus of num, also known as its negation.

mult(a, b)
pow(base, exponent)

Power function: computes base^exponent, where base is Numeric, and exponent has to be an integer.

This means that it is impossible to calculate roots by using this function.

If base supports direct computation of pow, that is used. Otherwise, the Exponentiation by Squaring algorithm is used.

sub(a, b)
to_float(num)

Tries to convert num to a built-in floating-point number.

Note that precision might be lost during this conversion.

Not all numeric data types support this conversion! A CannotConvertToFloatError is raised if this conversion is unsupported by the passed data type.