PassiveSupport.Integer (passive_support v0.8.2)

Functions and guards for working with integers

Link to this section Summary

Functions

Arbitrary-precision exponentiation.

Arbitrary-precision factorial.

Converts an integer to a string, with a separator (default ",") inserted, starting in from the right side of the number, spaced apart by the number of digits specified by spacing (default 3).

Qualifies if integer is an integer less than 0.

Qualifies if integer is a natural number or 0.

Qualifies if integer is an integer greater than 0.

Returns the quotient and the remainder of dividend ÷ divisor

Link to this section Functions

Link to this function

exponential(base, exponent)

Specs

exponential(integer(), integer()) :: number()

Arbitrary-precision exponentiation.

Will be deprecated by Elixir v1.12.0

Examples

iex> exponential(2, 10)
1024

iex> exponential(3, 3)
27

iex> exponential(2, 100)
1267650600228229401496703205376

iex> exponential(5, -3)
0.008

iex> exponential(9832, 0)
1

iex> exponential(0, 2)
0

iex> exponential(0, 0)
1
Link to this function

factorial(integer)

Specs

factorial(integer()) :: integer()

Arbitrary-precision factorial.

Examples

iex> factorial(5)
120

iex> factorial(6)
720

iex> factorial(-6)
-720

iex> factorial(1)
1
Link to this function

formatted(integer, opts \\ [])

Specs

formatted(integer(), separator: String.t(), spacing: integer()) :: String.t()

Converts an integer to a string, with a separator (default ",") inserted, starting in from the right side of the number, spaced apart by the number of digits specified by spacing (default 3).

Examples

iex> formatted(57468291379)
"57,468,291,379"
iex> formatted(57468291379, separator: "_")
"57_468_291_379"
iex> formatted(57468291379, spacing: 4)
"574,6829,1379"
Link to this macro

is_negative(integer)

(macro)

Qualifies if integer is an integer less than 0.

Link to this macro

is_nonnegative(integer)

(macro)

Qualifies if integer is a natural number or 0.

Link to this macro

is_positive(integer)

(macro)

Qualifies if integer is an integer greater than 0.

(adhering to the mathematical principle that 0 is neither positive nor negative)

Link to this function

remdiv(dividend, divisor)

Specs

remdiv(integer(), integer()) :: {integer(), integer()}

Returns the quotient and the remainder of dividend ÷ divisor

Examples

iex> remdiv(3, 2)
{1, 1}

iex> remdiv(-325, 60)
{-5, -25}

iex> remdiv(11, 3)
{3, 2}