decimal
decimal copied to clipboard
Adds `compare/3` and `eq?/3` with threshold as parameter
It adds two new functions: compare/3 and eq?/3. The new parameter is threshold. It compares the two numbers with a threshold. It's just to improve ergonomics. There're some situations that we don't want so much precision, mainly when we have periodic thites. It can be useful for testing situations.
iex> Decimal.compare("1.1", 1, "0.2")
:eq
iex> Decimal.compare("1.2", 1, "0.1")
:gt
iex> Decimal.compare("1.0", "1.2", "0.1")
:lt
iex> Decimal.eq?("1.0", 1, "0")
true
iex> Decimal.eq?("1.2", 1, "0.1")
false
iex> Decimal.eq?("1.2", 1, "0.2")
true
iex> Decimal.eq?(1, -1, "0.0")
false