numbers v0.1.1 Numeric behaviour

Any module that wants to be a Numeric type, and to be able to be called by the functions in Number, should make sure that this behaviour is followed.

Summary

Types

numStruct should be a struct that follows the Numeric behaviour

t()

To be used in your typespecs at any place where a Numeric type can be used

Callbacks

The absolute value of a number

Unary minus. Should return the negation of the number

Creates a new numStruct from the given built-in integer or float

Power function, x^n

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

Types

numStruct()
numStruct() :: struct

numStruct should be a struct that follows the Numeric behaviour.

t()
t() :: number | numStruct

To be used in your typespecs at any place where a Numeric type can be used.

Callbacks

abs(numStruct)

The absolute value of a number.

add(numStruct, numStruct)
add(numStruct, numStruct) :: numStruct
add(numStruct, number) :: numStruct
add(number, numStruct) :: numStruct
div(numStruct, numStruct)
div(numStruct, numStruct) :: numStruct
div(numStruct, number) :: numStruct
div(number, numStruct) :: numStruct
minus(numStruct)
minus(numStruct) :: numStruct

Unary minus. Should return the negation of the number.

mul(numStruct, numStruct)
mul(numStruct, numStruct) :: numStruct
mul(numStruct, number) :: numStruct
mul(number, numStruct) :: numStruct
new(arg0)
new(integer | float) :: numStruct

Creates a new numStruct from the given built-in integer or float.

In the case of reading a float, it is okay to lose precision.

pow(numStruct, integer) (optional)
pow(numStruct, integer) :: numStruct

Power function, x^n.

When this optional function is not provided, Number will use the ‘Exponentiation by Squaring’ algorithm to calculate the result (which uses log(n) repeated multiplications).

Add it to your data type if it is possible to compute a power using a faster algorithm.

sub(numStruct, numStruct)
sub(numStruct, numStruct) :: numStruct
sub(numStruct, number) :: numStruct
sub(number, numStruct) :: numStruct
to_float(numStruct)
to_float(numStruct) :: float

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

It is okay to lose precision during this conversion.