[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Private/NumberFormat C
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Private/NumberFormat CurrencyFormatter.cs,1.1,1.2 FixedPointFormatter.cs,1.2,1.3 Formatter.cs,1.4,1.5 NumberFormatter.cs,1.3,1.4 PercentFormatter.cs,1.3,1.4 RoundTripFormatter.cs,1.2,1.3 ScientificFormatter.cs,1.4,1.5 |
Date: |
Mon, 14 Apr 2003 02:04:29 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat
In directory subversions:/tmp/cvs-serv12314/runtime/System/Private/NumberFormat
Modified Files:
CurrencyFormatter.cs FixedPointFormatter.cs Formatter.cs
NumberFormatter.cs PercentFormatter.cs RoundTripFormatter.cs
ScientificFormatter.cs
Log Message:
Handle NaN, +Infinity, and -Infinity in the number formatters.
Index: CurrencyFormatter.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/CurrencyFormatter.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** CurrencyFormatter.cs 27 Nov 2002 14:37:27 -0000 1.1
--- CurrencyFormatter.cs 14 Apr 2003 06:04:27 -0000 1.2
***************
*** 142,146 ****
int precision = (this.precision == -1) ?
NumberFormatInfo(provider).CurrencyDecimalDigits :
this.precision;
! string rawnumber = FormatAnyRound(o, precision);
//
--- 142,146 ----
int precision = (this.precision == -1) ?
NumberFormatInfo(provider).CurrencyDecimalDigits :
this.precision;
! string rawnumber = FormatAnyRound(o, precision, provider);
//
Index: FixedPointFormatter.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/FixedPointFormatter.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** FixedPointFormatter.cs 27 Nov 2002 20:29:56 -0000 1.2
--- FixedPointFormatter.cs 14 Apr 2003 06:04:27 -0000 1.3
***************
*** 41,45 ****
// Get string
! string rawnumber = FormatAnyRound(o, precision);
StringBuilder ret = new StringBuilder();
--- 41,45 ----
// Get string
! string rawnumber = FormatAnyRound(o, precision, provider);
StringBuilder ret = new StringBuilder();
Index: Formatter.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/Formatter.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** Formatter.cs 17 Mar 2003 17:51:38 -0000 1.4
--- Formatter.cs 14 Apr 2003 06:04:27 -0000 1.5
***************
*** 53,60 ****
NumberFormatInfo(IFormatProvider provider)
{
! return provider == null ?
! System.Globalization.NumberFormatInfo.CurrentInfo :
! (NumberFormatInfo) provider.GetFormat(
typeof(System.Globalization.NumberFormatInfo));
}
--- 53,74 ----
NumberFormatInfo(IFormatProvider provider)
{
! if(provider == null)
! {
! return
System.Globalization.NumberFormatInfo.CurrentInfo;
! }
! else
! {
! NumberFormatInfo nfi =
! (NumberFormatInfo) provider.GetFormat(
typeof(System.Globalization.NumberFormatInfo));
+ if(nfi != null)
+ {
+ return nfi;
+ }
+ else
+ {
+ return
System.Globalization.NumberFormatInfo.CurrentInfo;
+ }
+ }
}
***************
*** 274,278 ****
}
! static protected string FormatAnyRound(Object o, int precision)
{
string ret;
--- 288,293 ----
}
! static protected string FormatAnyRound(Object o, int precision,
!
IFormatProvider provider)
{
string ret;
***************
*** 316,324 ****
{
// Beware rounding code
! if (OToDouble(o) < 0)
{
ret = "-" +
Formatter.FormatFloat(
! -OToDouble(o) + 5 *
Math.Pow(10, -precision - 1)
,precision);
}
--- 331,352 ----
{
// Beware rounding code
! double val = OToDouble(o);
! if (Double.IsNaN(val))
! {
! return NumberFormatInfo(provider).NaNSymbol;
! }
! else if (Double.IsPositiveInfinity(val))
! {
! return
NumberFormatInfo(provider).PositiveInfinitySymbol;
! }
! else if (Double.IsNegativeInfinity(val))
! {
! return
NumberFormatInfo(provider).NegativeInfinitySymbol;
! }
! else if (val < 0)
{
ret = "-" +
Formatter.FormatFloat(
! -val + 5 * Math.Pow(10,
-precision - 1)
,precision);
}
***************
*** 326,330 ****
{
ret = Formatter.FormatFloat(
! OToDouble(o) + 5 * Math.Pow(10,
-precision - 1)
,precision);
}
--- 354,358 ----
{
ret = Formatter.FormatFloat(
! val + 5 * Math.Pow(10,
-precision - 1)
,precision);
}
Index: NumberFormatter.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/NumberFormatter.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** NumberFormatter.cs 29 Nov 2002 00:58:38 -0000 1.3
--- NumberFormatter.cs 14 Apr 2003 06:04:27 -0000 1.4
***************
*** 82,86 ****
int precision = (this.precision == -1) ?
NumberFormatInfo(provider).NumberDecimalDigits :
this.precision;
! string rawnumber = FormatAnyRound(o, precision);
//
--- 82,86 ----
int precision = (this.precision == -1) ?
NumberFormatInfo(provider).NumberDecimalDigits :
this.precision;
! string rawnumber = FormatAnyRound(o, precision, provider);
//
Index: PercentFormatter.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/PercentFormatter.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** PercentFormatter.cs 29 Nov 2002 00:58:38 -0000 1.3
--- PercentFormatter.cs 14 Apr 2003 06:04:27 -0000 1.4
***************
*** 88,92 ****
int precision = (this.precision == -1) ?
NumberFormatInfo(provider).NumberDecimalDigits :
this.precision;
! string rawnumber = FormatAnyRound(o, precision + 2);
//
--- 88,92 ----
int precision = (this.precision == -1) ?
NumberFormatInfo(provider).NumberDecimalDigits :
this.precision;
! string rawnumber = FormatAnyRound(o, precision + 2, provider);
//
Index: RoundTripFormatter.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/RoundTripFormatter.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** RoundTripFormatter.cs 17 Mar 2003 17:51:38 -0000 1.2
--- RoundTripFormatter.cs 14 Apr 2003 06:04:27 -0000 1.3
***************
*** 43,47 ****
// Get initial number
! string rawnumber = FormatAnyRound(o, precision);
StringBuilder ret = new StringBuilder();
--- 43,47 ----
// Get initial number
! string rawnumber = FormatAnyRound(o, precision, provider);
StringBuilder ret = new StringBuilder();
Index: ScientificFormatter.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/ScientificFormatter.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** ScientificFormatter.cs 17 Jan 2003 01:08:46 -0000 1.4
--- ScientificFormatter.cs 14 Apr 2003 06:04:27 -0000 1.5
***************
*** 52,55 ****
--- 52,67 ----
value = OToDouble(o);
+ if (Double.IsNaN(value))
+ {
+ return NumberFormatInfo(provider).NaNSymbol;
+ }
+ else if(Double.IsPositiveInfinity(value))
+ {
+ return
NumberFormatInfo(provider).PositiveInfinitySymbol;
+ }
+ else if(Double.IsNegativeInfinity(value))
+ {
+ return
NumberFormatInfo(provider).NegativeInfinitySymbol;
+ }
if (value < 0)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Private/NumberFormat CurrencyFormatter.cs,1.1,1.2 FixedPointFormatter.cs,1.2,1.3 Formatter.cs,1.4,1.5 NumberFormatter.cs,1.3,1.4 PercentFormatter.cs,1.3,1.4 RoundTripFormatter.cs,1.2,1.3 ScientificFormatter.cs,1.4,1.5,
Rhys Weatherley <address@hidden> <=