Skip to content

Conversation

@v1d3rm3
Copy link
Contributor

@v1d3rm3 v1d3rm3 commented May 25, 2024

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

@ericmj ericmj merged commit 7260d91 into ericmj:main Oct 3, 2024
@ericmj
Copy link
Owner

ericmj commented Oct 3, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants