// 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;
}
// 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;
}
TestLibrary.TestFramework.LogInformation("[Positive]");
retVal = PosTest1() && retVal;
retVal = PosTest2() && retVal;
+ retVal = PosTest3() && retVal;
+ retVal = PosTest4() && retVal;
retVal = NegTest1() && retVal;
return retVal;
}
+
+ public bool PosTest3()
+ {
+ bool retVal = true;
+
+ // Test based on https://github.com/dotnet/coreclr/issues/12137
+ TestLibrary.TestFramework.BeginScenario("PosTest3: Verify Round(System.double) when decimal part of arg is very close to -0.5 .");
+
+ double doubleVal = -.50000000000000011102230246251565404236316680908203;
+ double expectedVal = -1.0;
+
+ if (Math.Round(doubleVal) != expectedVal)
+ {
+ Console.WriteLine("actual value = {0:G17}", Math.Round(doubleVal));
+ Console.WriteLine("expected value = {0:G17}", expectedVal);
+ TestLibrary.TestFramework.LogError("001.1", "Return value is wrong!");
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+ public bool PosTest4()
+ {
+ bool retVal = true;
+
+ // Test based on https://github.com/dotnet/coreclr/issues/12137
+ TestLibrary.TestFramework.BeginScenario("PosTest4: Verify Round(System.double) when decimal part of arg is very close to 0.5 .");
+
+ double doubleVal = 0.50000000000000011102230246251565404236316680908203;
+ double expectedVal = 1.0;
+
+ if (Math.Round(doubleVal) != expectedVal)
+ {
+ Console.WriteLine("actual value = {0:G17}", Math.Round(doubleVal));
+ Console.WriteLine("expected value = {0:G17}", expectedVal);
+ TestLibrary.TestFramework.LogError("001.1", "Return value is wrong!");
+ retVal = false;
+ }
+
+ return retVal;
+ }
#endregion
#region Nagetive Test Cases