decimal icon indicating copy to clipboard operation
decimal copied to clipboard

Adds `compare/3` and `eq?/3` with threshold as parameter

Open v1d3rm3 opened this issue 1 year ago • 0 comments

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

v1d3rm3 avatar May 25 '24 19:05 v1d3rm3