DecimalEnv.Operators (DecimalEnv v1.0.0) View Source
This module redefines Elixir's numeric operators so we can use Decimal
seemlessly.
Link to this section Summary
Functions
Whether a number is not equal to the other or not.
Arithmetic multiplication operator.
Arithmetic positive unary operator.
Arithmetic addition operator.
Arithmetic negative unary operator.
Arithmetic substraction operator.
Arithmetic division operator.
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.
Imports the Decimal operators instead of the Kernel ones.
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.
Link to this section Types
Specs
Supported inputs.
Link to this section Functions
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Imports the Decimal operators instead of the Kernel ones.
Specs
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
Specs
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
Specs
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
Specs
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
Specs
inf() :: Decimal.t()
Generates infinity.
Examples
iex> use DecimalEnv.Operators
iex> inf() == Decimal.new("+Inf")
true
iex> -inf() == Decimal.new("-Inf")
true
Specs
Whether the number is infinite or not.
Examples
iex> use DecimalEnv.Operators
iex> inf?(inf())
true
iex> inf?(-inf())
true
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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