Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds compare/3 and eq?/3 with threshold as parameter #208

Merged
merged 7 commits into from
Oct 3, 2024

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

lib/decimal.ex Outdated Show resolved Hide resolved
lib/decimal.ex Outdated Show resolved Hide resolved
@ericmj ericmj merged commit 7260d91 into ericmj:main Oct 3, 2024
2 checks passed
@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