This module redefines Elixir's numeric operators so we can use Decimal
seemlessly.
Summary
Functions
Arithmetic multiplication operator.
Arithmetic positive unary operator.
Arithmetic addition operator.
Arithmetic negative unary operator.
Arithmetic substraction operator.
Arithmetic division operator.
Whether a number is not equal to the other or not.
Imports the Decimal operators instead of the Kernel ones.
Whether a number is less than other or not.
Whether a number is less than or equal to the other or not.
Whether a number is equal to the other or not.
Whether a number is greater than than other or not.
Whether a number is greater than or equal to the other or not.
The absolute value of given number. Sets the number's sign to positive.
Returns the smallest number larger than or equal to number.
Divides two numbers and returns the integer part.
Returns the largest number smaller than or equal to number.
Generates infinity.
Whether the number is infinite or not.
Whether the number is an integer or not.
Compares two values numerically and returns the maximum.
Compares two values numerically and returns the minimum.
Whether the value is a number or not.
Remainder of integer division of two numbers. The result will have the sign of the first number.
Rounds the given number to specified decimal places with the given
strategy (default is to round to nearest one). If places is negative, at
least that many digits to the left of the decimal point will be zero.
Finds the square root of a number.
Types
Functions
Arithmetic multiplication operator.
Examples
iex> use DecimalEnv.Operators
iex> "21" * "2" == Decimal.new("42")
true
iex> 21 * 2 == Decimal.new("42")
true
iex> 21.0 * 2.0 == Decimal.new("42")
true
iex> 21.0 * "2.0" == Decimal.new("42")
true
Arithmetic positive unary operator.
Examples
iex> use DecimalEnv.Operators
iex> +"42" == Decimal.new("42")
true
iex> +42 == Decimal.new("42")
true
iex> +42.0 == Decimal.new("42")
true
Arithmetic addition operator.
Examples
iex> use DecimalEnv.Operators
iex> "21" + "21" == Decimal.new("42")
true
iex> 21 + 21 == Decimal.new("42")
true
iex> 21.0 + 21.0 == Decimal.new("42")
true
iex> 21.0 + "21.0" == Decimal.new("42")
true
Arithmetic negative unary operator.
Examples
iex> use DecimalEnv.Operators
iex> -"42" == Decimal.new("-42")
true
iex> -42 == Decimal.new("-42")
true
iex> -42.0 == Decimal.new("-42")
true
Arithmetic substraction operator.
Examples
iex> use DecimalEnv.Operators
iex> "84" - "42" == Decimal.new("42")
true
iex> 84 - 42 == Decimal.new("42")
true
iex> 84.0 - 42.0 == Decimal.new("42")
true
iex> 84.0 - "42.0" == Decimal.new("42")
true
Arithmetic division operator.
Examples
iex> use DecimalEnv.Operators
iex> "84" / "2" == Decimal.new("42")
true
iex> 84 / 2 == Decimal.new("42")
true
iex> 84.0 / 2.0 == Decimal.new("42")
true
iex> 84.0 / "2.0" == Decimal.new("42")
true
Whether a number is not equal to the other or not.
Examples
iex> use DecimalEnv.Operators
iex> "42" != "41"
true
iex> 42 != 41
true
iex> 42.0 != 41.0
true
iex> 42.0 != "41.0"
true
iex> 42 != 42
false
Imports the Decimal operators instead of the Kernel ones.
Whether a number is less than other or not.
Examples
iex> use DecimalEnv.Operators
iex> "41" < "42"
true
iex> 41 < 42
true
iex> 41.0 < 42.0
true
iex> 41.0 < "42.0"
true
iex> 42 < 41
false
Whether a number is less than or equal to the other or not.
Examples
iex> use DecimalEnv.Operators
iex> "41" <= "42"
true
iex> 41 <= 42
true
iex> 41.0 <= 42.0
true
iex> 41.0 <= "42.0"
true
iex> 42 <= 42
true
iex> 42 <= 41
false
Whether a number is equal to the other or not.
Examples
iex> use DecimalEnv.Operators
iex> "42" == "42"
true
iex> 42 == 42
true
iex> 42.0 == 42.0
true
iex> 42.0 == "42.0"
true
iex> 42 == 41
false
Whether a number is greater than than other or not.
Examples
iex> use DecimalEnv.Operators
iex> "42" > "41"
true
iex> 42 > 41
true
iex> 42.0 > 41.0
true
iex> 42.0 > "41.0"
true
iex> 41 > 42
false
Whether a number is greater than or equal to the other or not.
Examples
iex> use DecimalEnv.Operators
iex> "42" >= "41"
true
iex> 42 >= 41
true
iex> 42.0 >= 41.0
true
iex> 42.0 >= "41.0"
true
iex> 42 >= 42
true
iex> 41 >= 42
false
The absolute value of given number. Sets the number's sign to positive.
Examples
iex> use DecimalEnv.Operators
iex> abs("42") == Decimal.new("42")
true
iex> abs("-42") == Decimal.new("42")
true
iex> abs(42) == Decimal.new("42")
true
iex> abs(-42) == Decimal.new("42")
true
iex> abs(42.0) == Decimal.new("42")
true
iex> abs(-42.0) == Decimal.new("42")
true
Returns the smallest number larger than or equal to number.
Examples
iex> use DecimalEnv.Operators
iex> ceil(42) == Decimal.new("42")
true
iex> ceil("41.1") == Decimal.new("42")
true
iex> ceil(41.1) == Decimal.new("42")
true
Divides two numbers and returns the integer part.
Examples
iex> use DecimalEnv.Operators
iex> div(5, 2) == Decimal.new("2")
true
iex> div("5", "2") == Decimal.new("2")
true
iex> div(5.0, 2.0) == Decimal.new("2")
true
iex> div(5.0, "2.0") == Decimal.new("2")
true
Returns the largest number smaller than or equal to number.
Examples
iex> use DecimalEnv.Operators
iex> floor(42) == Decimal.new("42")
true
iex> floor("42.9") == Decimal.new("42")
true
iex> floor(42.9) == Decimal.new("42")
true
@spec inf() :: Decimal.t()
Generates infinity.
Examples
iex> use DecimalEnv.Operators
iex> inf() == Decimal.new("+Inf")
true
iex> -inf() == Decimal.new("-Inf")
true
Whether the number is infinite or not.
Examples
iex> use DecimalEnv.Operators
iex> inf?(inf())
true
iex> inf?(-inf())
true
Whether the number is an integer or not.
Examples
iex> use DecimalEnv.Operators
iex> integer?(42)
true
iex> integer?("42")
true
iex> integer?(42.0)
true
iex> integer?(42.5)
false
iex> integer?("42.5")
false
Compares two values numerically and returns the maximum.
Examples
iex> use DecimalEnv.Operators
iex> max("42", "41") == Decimal.new("42")
true
iex> max(42, 41) == Decimal.new("42")
true
iex> max(42.0, 41.0) == Decimal.new("42")
true
iex> max(42.0, "41.0") == Decimal.new("42")
true
iex> max(41.0, "42.0") == Decimal.new("42")
true
Compares two values numerically and returns the minimum.
Examples
iex> use DecimalEnv.Operators
iex> min("43", "42") == Decimal.new("42")
true
iex> min(43, 42) == Decimal.new("42")
true
iex> min(43.0, 42.0) == Decimal.new("42")
true
iex> min(43.0, "42.0") == Decimal.new("42")
true
iex> min(42.0, "43.0") == Decimal.new("42")
true
Whether the value is a number or not.
Examples
iex> use DecimalEnv.Operators
iex> number?(42)
true
iex> number?("42.0")
true
iex> number?(42.0)
true
iex> number?("+Inf")
true
iex> number?("-Inf")
true
iex> number?(%Decimal{coef: :NaN})
false
Remainder of integer division of two numbers. The result will have the sign of the first number.
Examples
iex> use DecimalEnv.Operators
iex> rem(5, 2) == Decimal.new("1")
true
iex> rem("5", "2") == Decimal.new("1")
true
iex> rem("5.0", "2.0") == Decimal.new("1")
true
iex> rem(5.0, "2.0") == Decimal.new("1")
true
@spec round(input(), non_neg_integer(), Decimal.rounding()) :: Decimal.t()
Rounds the given number to specified decimal places with the given
strategy (default is to round to nearest one). If places is negative, at
least that many digits to the left of the decimal point will be zero.
The available strategies are:
:down:half_up:half_even:ceiling:floor:half_down:up
Examples
iex> use DecimalEnv.Operators
iex> round(42) == Decimal.new("42")
true
iex> round(41.5) == Decimal.new("42")
true
iex> round("41.5") == Decimal.new("42")
true
iex> round("42.4") == Decimal.new("42")
true
Finds the square root of a number.
Examples
iex> use DecimalEnv.Operators
iex> sqrt(4) == Decimal.new("2")
true
iex> sqrt("4") == Decimal.new("2")
true
iex> sqrt(4.0) == Decimal.new("2")
true