massex v0.1.0 Massex View Source
Defines a whole value pattern container for masses, and utility methods for working with them to improve handling within your applications.
Link to this section Summary
Functions
Returns a Massex
with the arithmetical absolute of the amount
Adds two Massex
structs together, returning a Massex
Compares two Massex
structs, returning 0 on equality, 1 if left is greater than right, or -1 if left is less than right
Divides a Massex
by the provided denominator
Returns true if two Massex
represent the same amount of mass
Multiplies a Massex
by the provided amount
Returns true if the amount of a Massex
is less than zero
Builds a Massex
struct from an amount and unit
Returns true if the amount of a Massex
is more than zero
Subtracts one Massex struct from another, returning a Massex
Returns true if the amount of a Massex
is zero
Link to this section Types
Specs
Link to this section Functions
Specs
Returns a Massex
with the arithmetical absolute of the amount
Specs
Adds two Massex
structs together, returning a Massex
Examples
iex> left = Massex.new(10, :gram)
iex> right = Massex.new(20, :gram)
iex> Massex.add(left, right)
%Massex{unit: :gram, amount: Decimal.new(30)}
Specs
Compares two Massex
structs, returning 0 on equality, 1 if left is greater than right, or -1 if left is less than right
Examples
iex> less = Massex.new(10, :gram)
iex> more = Massex.new(20, :gram)
iex> Massex.compare(less, less)
0
iex> Massex.compare(less, more)
-1
iex> Massex.compare(more, less)
1
Specs
Divides a Massex
by the provided denominator
Examples
iex> base = Massex.new(10, :gram)
iex> Massex.divide(base, 2)
%Massex{amount: Decimal.new(5), unit: :gram}
Specs
Returns true if two Massex
represent the same amount of mass
Examples
iex> left = Massex.new(10, :gram)
iex> right = Massex.new(10, :gram)
iex> Massex.equals?(left, right)
true
Specs
Multiplies a Massex
by the provided amount
Examples
iex> mass = Massex.new(10, :gram)
iex> Massex.multiply(mass, 10)
%Massex{amount: Decimal.new(100), unit: :gram}
Specs
Returns true if the amount of a Massex
is less than zero
Examples
iex> Massex.negative?(Massex.new(-10, :gram))
true
iex> Massex.negative?(Massex.new(10, :gram))
false
Specs
Builds a Massex
struct from an amount and unit
Examples
iex> Massex.new(10, :gram)
%Massex{amount: Decimal.new(10), unit: :gram}
Specs
Returns true if the amount of a Massex
is more than zero
Examples
iex> Massex.positive?(Massex.new(-10, :gram))
false
iex> Massex.positive?(Massex.new(10, :gram))
true
Specs
Subtracts one Massex struct from another, returning a Massex
Examples
iex> left = Massex.new(20, :gram)
iex> right = Massex.new(10, :gram)
iex> Massex.subtract(left, right)
%Massex{unit: :gram, amount: Decimal.new(10)}
iex> Massex.subtract(left, 10)
%Massex{unit: :gram, amount: Decimal.new(10)}
Specs
Returns the Decimal
amount backing the Massex
Examples
iex> mass = Massex.new(20, :gram)
iex> Massex.to_decimal(mass)
Decimal.new(20)
Specs
Returns true if the amount of a Massex
is zero
Examples
iex> Massex.zero?(Massex.new(-10, :gram))
false
iex> Massex.zero?(Massex.new(0, :gram))
true