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

equalsApprox() method to compare using tolerance #2

Merged
merged 2 commits into from
Mar 9, 2024
Merged

Conversation

bradenmacdonald
Copy link
Owner

@bradenmacdonald bradenmacdonald commented Mar 9, 2024

This introduces a new API method, Quantity.equalsApprox() which allows comparing two quantity values using the tolerance (plusMinus) value of the first one.

Example:

> Q`60±5 W`.equalsApprox(Q`63 W`)
true
> Q`60±0.05 W`.equalsApprox(Q`60.1 W`)
false

If no tolerance is specified, a default tolerance of 0.01% is used.

Also improved the Q helper to allow parsing strings with tolerance.

@bradenmacdonald bradenmacdonald merged commit 2837aa9 into main Mar 9, 2024
1 check passed
@bradenmacdonald bradenmacdonald deleted the eq-approx branch March 9, 2024 23:05
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.

1 participant