Permalink
Browse files

Fix for bug #3661.

Before this fix midpoint rounding mode was lost in case digits = 0.
Now this case is checked on the managed side and Round2 is only
used for digits > 0.
  • Loading branch information...
1 parent 311616e commit 99d6e93a71d3c6a1c10c5dc786cee2019145e5b2 @konrad-kruczynski konrad-kruczynski committed Mar 11, 2012
Showing with 6 additions and 2 deletions.
  1. +4 −0 mcs/class/corlib/System/Math.cs
  2. +2 −0 mcs/class/corlib/Test/System/MathTest.cs
  3. +0 −2 mono/metadata/sysmath.c
@@ -351,6 +351,8 @@ public static double Round (double value, int digits)
{
if (digits < 0 || digits > 15)
throw new ArgumentOutOfRangeException (Locale.GetText ("Value is too small or too big."));
+ if (digits == 0)
+ return Round (value);
return Round2(value, digits, false);
}
@@ -376,6 +378,8 @@ public static double Round (double value, int digits, MidpointRounding mode)
{
if ((mode != MidpointRounding.ToEven) && (mode != MidpointRounding.AwayFromZero))
throw new ArgumentException ("The value '" + mode + "' is not valid for this usage of the type MidpointRounding.", "mode");
+ if (digits == 0)
+ return Round (value, mode);
if (mode == MidpointRounding.ToEven)
return Round (value, digits);
@@ -965,6 +965,8 @@ public void TestDoubleRound3 ()
Assert.AreEqual (-63987.83593942D, Math.Round (-63987.83593942D, 8, MidpointRounding.ToEven), "#3B");
Assert.AreEqual (-63987.83593942D, Math.Round (-63987.83593942D, 8, MidpointRounding.AwayFromZero), "#3C");
+
+ Assert.AreEqual (1, Math.Round (0.5, 0, MidpointRounding.AwayFromZero));
}
#endif
@@ -66,8 +66,6 @@ gdouble ves_icall_System_Math_Round2 (gdouble value, gint32 digits, gboolean awa
return HUGE_VAL;
if (value == -HUGE_VAL)
return -HUGE_VAL;
- if (digits == 0)
- return ves_icall_System_Math_Round(value);
p = pow(10, digits);
#if defined (HAVE_ROUND) && defined (HAVE_RINT)
if (away_from_zero)

0 comments on commit 99d6e93

Please sign in to comment.