numbers v2.0.3 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
Adds two Numeric a and b together
Attempts to coerce a built-in datatype num to a struct of type numericType
by calling numericType.new(num)
Divides the Numeric a by b
Computes the unary minus of num, also known as its negation
Multiplies the Numeric a with the Numeric b
Power function: computes base^exponent,
where base is Numeric,
and exponent has to be an integer
Subtracts the Numeric b from the Numeric a
Tries to convert num to a built-in floating-point number
Functions
Attempts to coerce a built-in datatype num to a struct of type numericType
by calling numericType.new(num).
This function will raise an CannotCoerceError if:
- There is no
numericType.new/1function available. - The function is available but returns an ArgumentError for the passed built-in data type.
Divides the Numeric a by b.
Note that this is a supposed to be a full (non-truncated) division; no rounding or truncation is supposed to happen, even when calculating with integers.
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.