KitchenSink v1.3.7 KitchenSink.Math View Source

Math functions!

Link to this section Summary

Types

Some functions allow us to specify something to return in a case which would normally raise an error. This type identifies that

Functions

Numerical division which allows a specified return for “divide by zero.”

Round down to the nearest multiple of significance

Always round up to the nearest multiple of significance

Link to this section Types

Link to this type error_return() View Source
error_return() :: any

Some functions allow us to specify something to return in a case which would normally raise an error. This type identifies that.

Link to this section Functions

Link to this function ceil(number, significance) View Source
Link to this function div(numerator, denominator, div_by_zero) View Source
div(number, number, error_return) :: number | error_return

Numerical division which allows a specified return for “divide by zero.”

iex> div(1, 2, :oops)
0.5
iex> div(1, 0, :oops)
:oops
Link to this function floor(number, significance) View Source
Link to this function round_down_to_multiple(number, significance) View Source
round_down_to_multiple(number, number) :: number | no_return

Round down to the nearest multiple of significance.

Parameters

  • number: The number you wish to have rounded.
  • significance: The multiple to which you would like to round. Must not be 0.

Examples:

iex> round_down_to_multiple(31, 5)
30

iex> round_down_to_multiple(29.49, 10)
20
Link to this function round_up_to_multiple(number, significance) View Source
round_up_to_multiple(number, number) :: number | no_return

Always round up to the nearest multiple of significance.

Parameters

  • number: The number you wish to have rounded.
  • significance: The multiple to which you would like to round. Must not be 0.

Examples:

iex> round_up_to_multiple(31, 5)
35

iex> round_up_to_multiple(29.49, 10)
30