Author: miguel
Date: 2008-02-11 08:21:35 -0500 (Mon, 11 Feb 2008)
New Revision: 95434
Modified:
branches/mono-1-9/mcs/class/corlib/System/ChangeLog
branches/mono-1-9/mcs/class/corlib/System/NumberFormatter.cs
branches/mono-1-9/mcs/class/corlib/Test/System/ChangeLog
branches/mono-1-9/mcs/class/corlib/Test/System/NumberFormatterTest.cs
Log:
Backport Eyal's fixes from 95428 (fixes a regression in ToString R)
Modified: branches/mono-1-9/mcs/class/corlib/System/ChangeLog
===================================================================
--- branches/mono-1-9/mcs/class/corlib/System/ChangeLog 2008-02-11 12:54:56 UTC
(rev 95433)
+++ branches/mono-1-9/mcs/class/corlib/System/ChangeLog 2008-02-11 13:21:35 UTC
(rev 95434)
@@ -1,3 +1,7 @@
+2008-02-11 Eyal Alaluf <[EMAIL PROTECTED]>
+
+ * NumberFormatter.cs: Fix ToString("R") for +-Infinity & NaN.
+
2008-02-08 Sebastien Pouliot <[EMAIL PROTECTED]>
* Random.cs: Explain (and extend) special case in Next(min,max)
Modified: branches/mono-1-9/mcs/class/corlib/System/NumberFormatter.cs
===================================================================
--- branches/mono-1-9/mcs/class/corlib/System/NumberFormatter.cs
2008-02-11 12:54:56 UTC (rev 95433)
+++ branches/mono-1-9/mcs/class/corlib/System/NumberFormatter.cs
2008-02-11 13:21:35 UTC (rev 95434)
@@ -54,6 +54,9 @@
const int DecimalDefPrecision = 100;
const int TenPowersListLength = 19;
+ const double MinRoundtripVal = -1.79769313486231E+308;
+ const double MaxRoundtripVal = 1.79769313486231E+308;
+
#if UNSAFE_TABLES
// The below arrays are taken from
mono/metatdata/number-formatter.h
@@ -1111,20 +1114,39 @@
public string FormatRoundtrip (double origval, NumberFormatInfo
nfi)
{
+ if (_NaN)
+ return nfi.NaNSymbol;
+
+ if (_infinity)
+ if (_positive)
+ return nfi.PositiveInfinitySymbol;
+ else
+ return nfi.NegativeInfinitySymbol;
+
NumberFormatter nfc = GetClone ();
- string shortRep = FormatGeneral (_defPrecision, nfi);
- // Check roundtrip only for "normal" double values.
- if (!_NaN && !_infinity && origval == Double.Parse
(shortRep, nfi))
- return shortRep;
+ if (origval >= MinRoundtripVal && origval <=
MaxRoundtripVal) {
+ string shortRep = FormatGeneral (_defPrecision,
nfi);
+ if (origval == Double.Parse (shortRep, nfi))
+ return shortRep;
+ }
return nfc.FormatGeneral (_defPrecision + 2, nfi);
}
public string FormatRoundtrip (float origval, NumberFormatInfo
nfi)
{
+ if (_NaN)
+ return nfi.NaNSymbol;
+
+ if (_infinity)
+ if (_positive)
+ return nfi.PositiveInfinitySymbol;
+ else
+ return nfi.NegativeInfinitySymbol;
+
NumberFormatter nfc = GetClone ();
string shortRep = FormatGeneral (_defPrecision, nfi);
// Check roundtrip only for "normal" double values.
- if (!_NaN && !_infinity && origval == Single.Parse
(shortRep, nfi))
+ if (origval == Single.Parse (shortRep, nfi))
return shortRep;
return nfc.FormatGeneral (_defPrecision + 2, nfi);
}
Modified: branches/mono-1-9/mcs/class/corlib/Test/System/ChangeLog
===================================================================
--- branches/mono-1-9/mcs/class/corlib/Test/System/ChangeLog 2008-02-11
12:54:56 UTC (rev 95433)
+++ branches/mono-1-9/mcs/class/corlib/Test/System/ChangeLog 2008-02-11
13:21:35 UTC (rev 95434)
@@ -1,3 +1,7 @@
+2008-02-11 Eyal Alaluf <[EMAIL PROTECTED]>
+
+ * NumberFormatterTest.cs: Test +-Infinity & NaN ToString ("R")
+
2008-01-24 Rodrigo Kumpera <[EMAIL PROTECTED]>
* TypeTest.cs (InvokeMember_WithoutDefaultValue): Added test for bug
#348522.
Modified: branches/mono-1-9/mcs/class/corlib/Test/System/NumberFormatterTest.cs
===================================================================
--- branches/mono-1-9/mcs/class/corlib/Test/System/NumberFormatterTest.cs
2008-02-11 12:54:56 UTC (rev 95433)
+++ branches/mono-1-9/mcs/class/corlib/Test/System/NumberFormatterTest.cs
2008-02-11 13:21:35 UTC (rev 95434)
@@ -2957,9 +2957,16 @@
AssertEquals ("#01", "Infinity",
Double.PositiveInfinity.ToString());
AssertEquals ("#02", "-Infinity",
Double.NegativeInfinity.ToString());
AssertEquals ("#03", "NaN", Double.NaN.ToString());
- AssertEquals ("#01", "Infinity",
Single.PositiveInfinity.ToString());
- AssertEquals ("#02", "-Infinity",
Single.NegativeInfinity.ToString());
- AssertEquals ("#03", "NaN", Single.NaN.ToString());
+ AssertEquals ("#04", "Infinity",
Single.PositiveInfinity.ToString());
+ AssertEquals ("#05", "-Infinity",
Single.NegativeInfinity.ToString());
+ AssertEquals ("#06", "NaN", Single.NaN.ToString());
+
+ AssertEquals ("#07", "Infinity",
Double.PositiveInfinity.ToString("R"));
+ AssertEquals ("#08", "-Infinity",
Double.NegativeInfinity.ToString("R"));
+ AssertEquals ("#09", "NaN", Double.NaN.ToString("R"));
+ AssertEquals ("#10", "Infinity",
Single.PositiveInfinity.ToString("R"));
+ AssertEquals ("#11", "-Infinity",
Single.NegativeInfinity.ToString("R"));
+ AssertEquals ("#12", "NaN", Single.NaN.ToString("R"));
}
[Test]
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches