Numbers.Protocols.Multiplication protocol (numbers v5.2.5)

Copy Markdown

For supporting Numbers.mult/2.

Summary

Types

t()

All the types that implement this protocol.

Functions

Multiplies the two numbers together.

Should return the 'multiplicative identity' of the same type as the argument. This is the value that can be added to another number, to let the result remain equal to that number.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

mult(a, b)

@spec mult(t(), t()) :: t()

Multiplies the two numbers together.

mult_id(term)

@spec mult_id(t()) :: t()

Should return the 'multiplicative identity' of the same type as the argument. This is the value that can be added to another number, to let the result remain equal to that number.

(For integers, this is 1, for floats, 1.0. Most other numeric types have their own 'one' variant as well.)

This should be defined so that:

a = some_num
mult(a, mult_id()) == a
mult(mult_id(), a) == a

If the numeric structure also implements Numbers.Protocols.Division, the following should also be true:

a = some_num
div(a, mult_id()) == a
div(mult_id(), a) == a

(Note that it is fine if the result is not structurally identical, as long as it is logically equal.)