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/NumberFormat F


From: Jonathan Springer <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Private/NumberFormat Formatter.cs,1.2,1.3 GeneralFormatter.cs,1.4,1.5 HexadecimalFormatter.cs,1.2,1.3
Date: Sun, 02 Feb 2003 11:39:21 -0500

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

Modified Files:
        Formatter.cs GeneralFormatter.cs HexadecimalFormatter.cs 
Log Message:


Floating point and decimal parsing/formatting fixes.



Index: Formatter.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/Formatter.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Formatter.cs        29 Nov 2002 00:58:38 -0000      1.2
--- Formatter.cs        2 Feb 2003 16:39:18 -0000       1.3
***************
*** 290,301 ****
                {
                        // Rounding code
-                       int i;
                        decimal r;
  
!                       for (i=0, r=5; i<= precision; i++) 
                        {
!                               r /= 10;
                        }
  
                        if ((decimal)o < 0)
                        {
--- 290,302 ----
                {
                        // Rounding code
                        decimal r;
+                       int i;
  
!                       for (i=0, r=0.5m; i < precision; i++) 
                        {
!                               r *= 0.1m;
                        }
  
+                       //  Pick the call based on the inputs negativity.
                        if ((decimal)o < 0)
                        {
***************
*** 306,310 ****
                                ret = Formatter.FormatDecimal((decimal)o+r);
                        }
!                       ret = ret.Substring(0, ret.IndexOf('.')+precision+1);
                }
                else if (IsFloat(o))
--- 307,315 ----
                                ret = Formatter.FormatDecimal((decimal)o+r);
                        }
! 
!                       if (ret.Length - ret.IndexOf('.') > precision + 1) 
!                       {
!                               ret = ret.Substring(0, 
ret.IndexOf('.')+precision+1);
!                       }
                }
                else if (IsFloat(o))
***************
*** 353,372 ****
        static protected string FormatDecimal(decimal value)
        {
!               if (value == 0) return ".";
  
                int [] bits = Decimal.GetBits(value);
            int scale = (bits[3] >> 16) & 0xff;
!               decimal work = value * scale;
                StringBuilder ret = new StringBuilder();
!           
!               while (work >= 0) {
!                       ret.Insert(0, decimalDigits, (int)(work % 10), 1);
!                       work = Decimal.Truncate(work/10);
                }
  
!               if (ret.Length < scale) {
                        ret.Insert(0, "0", ret.Length - scale);
                }
  
                ret.Insert(ret.Length - scale, '.');
  
--- 358,389 ----
        static protected string FormatDecimal(decimal value)
        {
!               //  Guard clause(s)
!               if (value == 0.0m) return ".";
  
+               //  Variable declarations
                int [] bits = Decimal.GetBits(value);
            int scale = (bits[3] >> 16) & 0xff;
!               uint lowOrderBits;                      // temporary storage 
for low-order bits
!               decimal work = value;
                StringBuilder ret = new StringBuilder();
! 
!               //  Scale the decimal
!               for (int i = 0; i<scale; i++) work *= 10.0m;
!          
!               //  Pick off one digit at a time
!               while (work > 0.0m) 
!               {
!                       ret.Insert(0, decimalDigits[
!                                       (int)(work - 
Decimal.Truncate(work*0.1m)*10.0m)]);
!                       work = Decimal.Truncate(work * 0.1m);
                }
  
!               //  Pad out significant digits
!               if (ret.Length < scale) 
!               {
                        ret.Insert(0, "0", ret.Length - scale);
                }
  
+               //  Insert a decimal point
                ret.Insert(ret.Length - scale, '.');
  

Index: GeneralFormatter.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/GeneralFormatter.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** GeneralFormatter.cs 17 Jan 2003 01:08:46 -0000      1.4
--- GeneralFormatter.cs 2 Feb 2003 16:39:18 -0000       1.5
***************
*** 97,101 ****
                else
                {
!                       exponent = (int) Math.Floor(Math.Log10(OToDouble(o)));
                }
  
--- 97,101 ----
                else
                {
!                       exponent = (int) 
Math.Floor(Math.Log10(Math.Abs(OToDouble(o))));
                }
  

Index: HexadecimalFormatter.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Private/NumberFormat/HexadecimalFormatter.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** HexadecimalFormatter.cs     29 Nov 2002 00:58:38 -0000      1.2
--- HexadecimalFormatter.cs     2 Feb 2003 16:39:18 -0000       1.3
***************
*** 55,73 ****
        private string Format (long value)
        {
!               if (value >= 0) return Format((ulong) value);
  
!               //  This is a bona-fide negative number, but we're going
!               //  to work it in two's complement.
!               ulong uvalue;
!               StringBuilder buf = new StringBuilder();
  
!               for (uvalue = unchecked((ulong)value);  
!                       uvalue < System.UInt64.MaxValue;
!                       uvalue = unchecked((ulong) ((long)uvalue) >> 4))  // 
Signed shift
!               {
!                       buf.Insert(0, digits[uvalue % 16]);
!               }
  
!               return buf.ToString().PadLeft(precision, '0');
        }
  
--- 55,65 ----
        private string Format (long value)
        {
!               StringBuilder s = new StringBuilder(Format(unchecked((ulong) 
value)));
  
!               if (value >= 0) return s.ToString();
  
!               while (s[0] == digits[15]) s.Remove(0,1);
  
!               return s.ToString().PadLeft(precision, digits[15]);
        }
  





reply via email to

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