diff options
author | Han Lee <han.lee@intel.com> | 2017-06-14 09:14:18 -0700 |
---|---|---|
committer | Jan Vorlicek <janvorli@microsoft.com> | 2017-06-14 18:14:18 +0200 |
commit | 395f145ba0c220afb1d85ff8c26f34909d8ea424 (patch) | |
tree | f4b8ecac56be32975dfcda51d66f8d7960f07a56 /src/classlibnative | |
parent | 7b051348604398af834713af786ac7d6ee3e5bc7 (diff) | |
download | coreclr-395f145ba0c220afb1d85ff8c26f34909d8ea424.tar.gz coreclr-395f145ba0c220afb1d85ff8c26f34909d8ea424.tar.bz2 coreclr-395f145ba0c220afb1d85ff8c26f34909d8ea424.zip |
Fix a COMDouble::Round() issue (#12210)
* Fix a COMDouble::Round() issue
fixes https://github.com/dotnet/coreclr/issues/12137
* Add a couple tests for Math.Round(double)
based on https://github.com/dotnet/coreclr/issues/12137
* Use G17 format specifier for printing double values
Diffstat (limited to 'src/classlibnative')
-rw-r--r-- | src/classlibnative/float/floatdouble.cpp | 5 | ||||
-rw-r--r-- | src/classlibnative/float/floatsingle.cpp | 5 |
2 files changed, 4 insertions, 6 deletions
diff --git a/src/classlibnative/float/floatdouble.cpp b/src/classlibnative/float/floatdouble.cpp index 6f593e503c..ba90a57f88 100644 --- a/src/classlibnative/float/floatdouble.cpp +++ b/src/classlibnative/float/floatdouble.cpp @@ -183,10 +183,9 @@ FCIMPL1_V(double, COMDouble::Round, double x) // We had a number that was equally close to 2 integers. // We need to return the even one. - double tempVal = (x + 0.5); - double flrTempVal = floor(tempVal); + double flrTempVal = floor(x + 0.5); - if ((flrTempVal == tempVal) && (fmod(tempVal, 2.0) != 0)) { + if ((x == (floor(x) + 0.5)) && (fmod(flrTempVal, 2.0) != 0)) { flrTempVal -= 1.0; } diff --git a/src/classlibnative/float/floatsingle.cpp b/src/classlibnative/float/floatsingle.cpp index c7b7d4126b..ba48aea709 100644 --- a/src/classlibnative/float/floatsingle.cpp +++ b/src/classlibnative/float/floatsingle.cpp @@ -181,10 +181,9 @@ FCIMPL1_V(float, COMSingle::Round, float x) // We had a number that was equally close to 2 integers. // We need to return the even one. - float tempVal = (x + 0.5f); - float flrTempVal = floorf(tempVal); + float flrTempVal = floorf(x + 0.5f); - if ((flrTempVal == tempVal) && (fmodf(tempVal, 2.0f) != 0)) { + if ((x == (floorf(x) + 0.5f)) && (fmod(flrTempVal, 2.0f) != 0)) { flrTempVal -= 1.0f; } |