numbers v5.0.0-rc0 Numbers

Summary

Functions

The absolute value of a number

Adds two Numeric a and b together

Divides the Numeric a by b

Unary minus. Returns the negation of the number

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

Convert the custom Numeric struct to the built-in float datatype

Types

t()
t() :: any

Functions

abs(num)
abs(t) :: t

The absolute value of a number.

Depends on an implementation existing of Numbers.Protocols.Absolute

add(a, b)
add(t, t) :: t

Adds two Numeric a and b together.

Depends on an implementation existing of Numbers.Protocol.Addition

div(a, b)
div(t, t) :: t

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.

Depends on an implementation existing of Numbers.Protocol.Division

minus(num)
minus(t) :: t

Unary minus. Returns the negation of the number.

Depends on an implementation existing of Numbers.Protocols.Minus

mult(a, b)
mult(t, t) :: t

Multiplies the Numeric a with the Numeric b

Depends on an implementation existing of Numbers.Protocol.Multiplication

pow(num, power)
pow(t, non_neg_integer) :: t

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.)

Depends on an implementation existing of Numbers.Protocol.Exponentiation

sub(a, b)
sub(t, t) :: t

Subtracts the Numeric b from the Numeric a.

Depends on an implementation existing of Numbers.Protocol.Subtraction

to_float(num)
to_float(t) :: {:ok, t_as_float :: float} | :error

Convert the custom Numeric struct to the built-in float datatype.

This operation might be lossy, losing precision in the process.