[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Private/NumberFormat F
From: |
Jonathan Springer <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Private/NumberFormat Formatter.cs,1.3,1.4 RoundTripFormatter.cs,1.1,1.2 |
Date: |
Mon, 17 Mar 2003 12:51:40 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat
In directory subversions:/tmp/cvs-serv26040/runtime/System/Private/NumberFormat
Modified Files:
Formatter.cs RoundTripFormatter.cs
Log Message:
Refinements/Fixes of FP Formatting/Parsing.
Index: Formatter.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/Formatter.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** Formatter.cs 2 Feb 2003 16:39:18 -0000 1.3
--- Formatter.cs 17 Mar 2003 17:51:38 -0000 1.4
***************
*** 395,408 ****
if (value == 0.0) return ".";
! StringBuilder ret =
! new
StringBuilder(FormatInteger((ulong)Math.Floor(value)));
! double fraction = (value - Math.Floor(value)) * 10.0;
! for (int i=0; i < precision && fraction > 0.0; i++)
{
! ret.Append(decimalDigits[(int)Math.Floor(fraction)]);
! fraction = (fraction - Math.Floor(fraction)) * 10;
}
! return ret.ToString();
}
--- 395,440 ----
if (value == 0.0) return ".";
! //
! int exponent = (int)Math.Floor(Math.Log10(Math.Abs(value)));
! double work = value * Math.Pow(10, 16 - exponent);
!
! //
! // Build a numeric representation, sans decimal point.
! //
! StringBuilder sb =
! new
StringBuilder(FormatInteger((ulong)Math.Floor(work)));
! sb.Remove(sb.Length-1, 1); // Ditch the trailing decimal
point
! if (sb.Length > precision + exponent + 1)
{
! sb.Remove(precision+exponent+1,
sb.Length-(precision+exponent+1));
! }
!
! //
! // Cases for reinserting the decimal point.
! //
! if (exponent >= -1 && exponent < sb.Length)
! {
! sb.Insert(exponent+1,'.');
}
! else if (exponent < -1)
! {
! sb.Insert(0,new String('0',-exponent - 1));
! sb.Insert(0,".");
! }
! else
! {
! sb.Append(new String('0', exponent - sb.Length + 1));
! sb.Append('.');
! }
!
! //
! // Remove trailing zeroes.
! //
! while (sb[sb.Length-1] == '0') {
! sb.Remove(sb.Length-1, 1);
! }
!
! return sb.ToString();
}
Index: RoundTripFormatter.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/RoundTripFormatter.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** RoundTripFormatter.cs 27 Nov 2002 14:37:27 -0000 1.1
--- RoundTripFormatter.cs 17 Mar 2003 17:51:38 -0000 1.2
***************
*** 38,53 ****
// Calculate precision
int precision;
! if (o is Single)
! {
! precision = 9;
! }
! else if (o is Double)
! {
! precision = 17;
! }
! else
! {
! throw new FormatException(_("Format_TypeException"));
! }
// Get initial number
--- 38,44 ----
// Calculate precision
int precision;
! if (o is Single) precision = 7;
! else if (o is Double) precision = 15;
! else throw new FormatException(_("Format_TypeException"));
// Get initial number
***************
*** 61,76 ****
}
! if (rawnumber[0] == '.')
! {
! ret.Append('0');
! }
! else
! {
!
ret.Append(rawnumber.Substring(0,rawnumber.IndexOf('.')));
! }
ret.Append(NumberFormatInfo(provider).NumberDecimalSeparator);
!
! ret.Append(rawnumber.Substring(rawnumber.IndexOf('.')+1,
precision));
return ret.ToString();
--- 52,66 ----
}
! // Create portion before the decimal point
! if (rawnumber[0] == '.') ret.Append('0');
! else ret.Append(rawnumber.Substring(0,rawnumber.IndexOf('.')));
+ // Insert decimal point
ret.Append(NumberFormatInfo(provider).NumberDecimalSeparator);
!
! // Append the portion of the number following the decimal point
! int decpt = rawnumber.IndexOf('.')+1;
! ret.Append(rawnumber.Substring(decpt,
!
Math.Min(rawnumber.Length-decpt, precision)));
return ret.ToString();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Private/NumberFormat Formatter.cs,1.3,1.4 RoundTripFormatter.cs,1.1,1.2,
Jonathan Springer <address@hidden> <=