-
Notifications
You must be signed in to change notification settings - Fork 746
Fix high precision decimal calculations in v3.13 (#3898) #3929
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
Fix high precision decimal calculations in v3.13 (#3898) #3929
Conversation
add tests for how numerics are treated back to a baseline
2800ab8
to
4dc416f
Compare
EDIT - It could be that my tolerance level is too high so the code tries to "compensate" by adding more decimal places? Hi,
Result: _BeforeExpected = -0.09404701272000002 BeforeActual = -0.09 at NUnit.Framework.Assert.ReportFailure(String message) |
Hi @realfaisalk |
@stevenaw - Yup, exactly right. The tolerance was asked for by the customer but changed to 0.01 due the the 2dp numbers. |
Oh that's a good point @realfaisalk thanks for pointing that out! That could probably be made clearer. Would you be willing to file a GitHub issue about it? |
Fixes #3898
Fixes high-precision decimal calculations by internally using
decimal
when appropriate.I tried a few approaches here, and the one I found worked best while maintaining full backwards compatibility is to compare
expected
andactual
as decimals when at least one of the values is decimal and BOTH are within the valid values for decimals (betweendecimal.MinValue
anddecimal.MaxValue
).I also tried to treat all floating point operations as
decimal
internally when expected and actual are within valid range, however this caused some a change in failure messages when comparing twodouble
orfloat
values (or a double to an int, etc) with a tolerance since the number of decimal places in the "+/-" portion of the error message changed. This approach broke some existing tests in nunit, and likely would've broken others as well.NOTE: After merging, this should also be ported to the main development branch too