Fix a COMDouble::Round() issue#12210
Conversation
|
@tannergooding PTAL |
|
@tannergooding BTW, if you are not the right person to review this, it would be great if you would please pull in the right person(s). Thanks! |
|
Taking a look now. |
|
It is important to note that the MSDN page for
However, the actual behavior, which is on the general
The secondary portion (rounding midpoint values to the nearest even number) is important for just this scenario and the exact behavior taken here. Additionally, as an FYI, the original (unmodified) code from Desktop was hanblee@08786f2#diff-884cab80438864e5dc66c7e4c1a3c723L467, which is identical behavior to implementation currently checked in. When completely "unrolled" the current implementation is doing (floor(x + 0.5) == (x + 0.5)) && (fmod((x + 0.5), 2.0) != 0)and the newly proposed implementation is doing: (x == (floor(x) + 0.5)) && (fmod(floor(x + 0.5), 2.0) != 0)The previous algorithm would end up comparing "precisely 1" vs "precisely 1". This is definitely an improvement as it should only do the midpoint rounding calculation when x is exactly midpoint (as best as can be represented by IEEE double-precision floating-point values, anyways). |
|
It would be great if you could add a couple tests covering this scenario (CoreFX is the primary repo for managed tests, but there are some tests in CoreCLR as well: https://github.com/dotnet/coreclr/tree/32f0f9721afb584b4a14d69135bea7ddc129f755/tests/src/CoreMangLib/cti/system/math) |
|
FYI. @janvorli, @AndyAyersMS, @jkotas who have reviewed these types of changes previously. |
Good point. Will do. |
|
|
||
| if (Math.Round(doubleVal) != expectedVal) | ||
| { | ||
| Console.WriteLine("actual value = " + Math.Round(doubleVal)); |
There was a problem hiding this comment.
Could you use the G17 format specifier when printing here and below?
> double doubleVal = 0.50000000000000011102230246251565404236316680908203;
> Console.WriteLine(doubleVal)
0.5
> Console.WriteLine("{0:G17}", doubleVal)
0.50000000000000011
|
Thanks! This will need someone from the CoreCLR team to give final approval before it can be merged. |
|
Got it! |
|
@janvorli PTAL |
fixes https://github.com/dotnet/coreclr/issues/12137