dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Private NumberParser.


From: Jonathan Springer <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Private NumberParser.cs,1.7,1.8
Date: Sun, 02 Feb 2003 11:39:21 -0500

Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private
In directory subversions:/tmp/cvs-serv6199/runtime/System/Private

Modified Files:
        NumberParser.cs 
Log Message:


Floating point and decimal parsing/formatting fixes.



Index: NumberParser.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberParser.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** NumberParser.cs     17 Jan 2003 01:08:45 -0000      1.7
--- NumberParser.cs     2 Feb 2003 16:39:18 -0000       1.8
***************
*** 1022,1035 ****
                                                                       
NumberFormatInfo nfi)
        {
!               //  Double does not parse floating point numbers
                if ((style & NumberStyles.AllowHexSpecifier) != 0)
                        throw new FormatException(_("Format_HexNotSupported"));
  
                StringBuilder sb = new StringBuilder(RawString(s, style, nfi));
- 
                bool negative = StripSign(sb, nfi);
  
                //  Parse up to the decimal
!               decimal work = (decimal)EatDigits(sb);
  
                //  Parse after the decimal
--- 1022,1040 ----
                                                                       
NumberFormatInfo nfi)
        {
!               //  Decimal does not parse floating point numbers
                if ((style & NumberStyles.AllowHexSpecifier) != 0)
                        throw new FormatException(_("Format_HexNotSupported"));
  
                StringBuilder sb = new StringBuilder(RawString(s, style, nfi));
                bool negative = StripSign(sb, nfi);
+               decimal work = 0.0m;
  
                //  Parse up to the decimal
!               while (sb.Length > 0 && sb[0] >= '0' && sb[0] <= '9')
!               {
!                       work *= 10;
!                       work += (uint)(sb[0] - '0');
!                       sb.Remove(0, 1);
!               }
  
                //  Parse after the decimal
***************
*** 1037,1049 ****
                                && 
sb.ToString().StartsWith(nfi.NumberDecimalSeparator))
                {
-                       uint fracDigits;
                        sb.Remove(0, nfi.NumberDecimalSeparator.Length);
!                       fracDigits = EatDigits(sb);
!                       if (fracDigits != 0) 
                        {
!                               int i;
!                               int exp = (int)(-Math.Log10(fracDigits))-1;
!                               if (exp < 0) for (i=0; i<-exp; i++) work /= 10;
!                               if (exp > 0) for (i=0; i<exp; i++) work *= 10;
                        }       
                }
--- 1042,1057 ----
                                && 
sb.ToString().StartsWith(nfi.NumberDecimalSeparator))
                {
                        sb.Remove(0, nfi.NumberDecimalSeparator.Length);
! 
!                       decimal temp;
!                       int i, j;
!                       for (i = -1; 
!                                       sb.Length > 0 && sb[0] >= '0' && sb[0] 
<= '9' ; 
!                                       i--)
                        {
!                               temp = (decimal)((uint)(sb[0] - '0'));
!                               for (j = 0; j > i; j--) temp *= 0.1m;
!                               work += temp;
!                               sb.Remove(0, 1);
                        }       
                }
***************
*** 1052,1078 ****
                if (sb.Length > 0 && (sb[0] == 'e' || sb[0] == 'E') ) 
                {
!                       uint exp;
!                       bool negExponent;
                        sb.Remove(0, 1);
                        if (sb.ToString().StartsWith(nfi.PositiveSign)) 
                        {
                                sb.Remove(0, nfi.PositiveSign.Length);
                        } 
                        else if (sb.ToString().StartsWith(nfi.NegativeSign)) 
                        {
                                sb.Remove(0, nfi.NegativeSign.Length);
                        } 
!                       else 
                        {
!                               //  Darn it, we're supposed to have a sign.
!                               throw new 
FormatException(_("Format_ExponentRequiresSign"));
                        }
!                       exp= EatDigits(sb);
!                       if (exp!= 0) 
                        {
!                               int i;
!                               if (exp< 0) for (i=0; i<-exp; i++) work /= 10;
!                               if (exp> 0) for (i=0; i>exp; i++) work *= 10;
                        }
                }
  
--- 1060,1092 ----
                if (sb.Length > 0 && (sb[0] == 'e' || sb[0] == 'E') ) 
                {
!                       uint exp = 0;
!                       bool negExponent = false;
!                       decimal mult;
! 
                        sb.Remove(0, 1);
+ 
                        if (sb.ToString().StartsWith(nfi.PositiveSign)) 
                        {
+                               mult = 10.0m;
                                sb.Remove(0, nfi.PositiveSign.Length);
                        } 
                        else if (sb.ToString().StartsWith(nfi.NegativeSign)) 
                        {
+                               mult = 0.1m;
                                sb.Remove(0, nfi.NegativeSign.Length);
                        } 
!                       else
                        {
!                               mult = 10.0m;
                        }
! 
!                   while (sb.Length > 0 && sb[0] >= '0' && sb[0] <= '9')
                        {
!                               exp *= 10;
!                               exp += (uint)(sb[0] - '0');
!                               sb.Remove(0, 1);
                        }
+ 
+                       for (int i=0; i<exp; i++) work *= mult;
                }
  
***************
*** 1098,1102 ****
                                                                     
NumberFormatInfo nfi)
        {
!               //  Double does not parse floating point numbers
                if ((style & NumberStyles.AllowHexSpecifier) != 0)
                        throw new FormatException(_("Format_HexNotSupported"));
--- 1112,1116 ----
                                                                     
NumberFormatInfo nfi)
        {
!               //  Double does not parse hex numbers
                if ((style & NumberStyles.AllowHexSpecifier) != 0)
                        throw new FormatException(_("Format_HexNotSupported"));
***************
*** 1107,1111 ****
  
                //  Parse up to the decimal
!               double work;
                while (sb.Length > 0 && sb[0] >= '0' && sb[0] <= '9')
                {
--- 1121,1125 ----
  
                //  Parse up to the decimal
!               double work = 0.0d;
                while (sb.Length > 0 && sb[0] >= '0' && sb[0] <= '9')
                {
***************
*** 1119,1123 ****
                                && 
sb.ToString().StartsWith(nfi.NumberDecimalSeparator))
                {
-                       uint fracDigits;
                        sb.Remove(0, nfi.NumberDecimalSeparator.Length);
                        for (int i = -1; 
--- 1133,1136 ----
***************
*** 1145,1148 ****
--- 1158,1162 ----
                                sb.Remove(0, nfi.NegativeSign.Length);
                        } 
+                       /*  --- Removed in response to bug #2222
                        else 
                        {
***************
*** 1150,1153 ****
--- 1164,1168 ----
                                throw new 
FormatException(_("Format_ExponentRequiresSign"));
                        }
+                       */
  
                    while (sb.Length > 0 && sb[0] >= '0' && sb[0] <= '9')





reply via email to

[Prev in Thread] Current Thread [Next in Thread]