You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remainder calculation for decimal uses NearNegativeZero/NearPositiveZero constants that claim to be Constant representing the negative number that is the closest possible Decimal value to -0m/+0m. The actual constant values have scale 27 (instead of 28) so they are 10 times larger than intended.
That entire condition looks odd, I couldn't find any tests to reproduce such values (it looks like FCallDivide refuses to calculate such imprecise results and throws OverflowException).
Are these values and/or logic incorrect? Maybe there are some tests for Desktop that cover these cases?
So I finally found test cases for this bug while writing new tests for dotnet/corert#5926. 5.94499443m % 0.0000000000000000000000000007m = 0.0000000000000000000000000005m but returns 0.0000000000000000000000000002m because the constants have scale 27.
The current Decimal.Remainder implementation does several intermediate calculations that may round or overflow:
decimal.MaxValue % 0.1m overflows.
5 % 0.0000000000000000000000000003m = 0.0000000000000000000000000002m but returns 0.0000000000000000000000000001m because of rounding.
decimal.MaxValue % 7.081881059m = 3.702941036m but returns 4.081881059m because of rounding.
decimal.MaxValue % 2004094637636.6280382536104438m = 1980741879937.1051521151154118m but returns 1980741879937m because of rounding.
I propose writing a new remainder calculation (based on CoreRT's VarDecDiv) as part of dotnet/coreclr#18249, but after CoreCLR and CoreRT decimals are shared because CoreFX tests are shared.
Are there any compatibility concerns with returning more precise results or not throwing overflow exceptions anymore?
Are there any compatibility concerns with returning more precise results or not throwing overflow exceptions anymore?
This is fine. We are not worried about fixing a clear correctness bugs like these in .NET Core. We are not aiming for bug-for-bug compatibility between .NET Core releases.
Activity
[-]decimal.Remainder and NearNegativeZero/NearPositiveZero[/-][+]decimal.Remainder correctness issues[/+]pentp commentedon Jun 11, 2018
So I finally found test cases for this bug while writing new tests for dotnet/corert#5926.
5.94499443m % 0.0000000000000000000000000007m = 0.0000000000000000000000000005mbut returns0.0000000000000000000000000002mbecause the constants have scale 27.The current
Decimal.Remainderimplementation does several intermediate calculations that may round or overflow:decimal.MaxValue % 0.1moverflows.5 % 0.0000000000000000000000000003m = 0.0000000000000000000000000002mbut returns0.0000000000000000000000000001mbecause of rounding.decimal.MaxValue % 7.081881059m = 3.702941036mbut returns4.081881059mbecause of rounding.decimal.MaxValue % 2004094637636.6280382536104438m = 1980741879937.1051521151154118mbut returns1980741879937mbecause of rounding.I propose writing a new remainder calculation (based on CoreRT's
VarDecDiv) as part of dotnet/coreclr#18249, but after CoreCLR and CoreRT decimals are shared because CoreFX tests are shared.Are there any compatibility concerns with returning more precise results or not throwing overflow exceptions anymore?
jkotas commentedon Jun 11, 2018
This is fine. We are not worried about fixing a clear correctness bugs like these in .NET Core. We are not aiming for bug-for-bug compatibility between .NET Core releases.