Numbers.Protocols.Addition protocol (numbers v5.2.4)
For supporting Numbers.add/2
.
Link to this section Summary
Functions
Adds two numbers together.
Should return the 'additive 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.
Link to this section Types
Specs
t() :: term()
Link to this section Functions
add(a, b)
Specs
Adds two numbers together.
add_id(term)
Specs
Should return the 'additive 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 0
, for floats, 0.0
. Most other numeric types have their own 'zero' variant as well.)
This should be defined so that:
a = some_num
add(a, add_id()) == a
add(add_id(), a) == a
If the numeric structure also implements Numbers.Protocols.Subtraction
, the following should also be true:
a = some_num
sub(a, add_id()) == a
sub(add_id(), a) == a
(Note that it is fine if the result is not structurally identical, as long as it is logically equal.)