2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Data / System.Data.SqlTypes / SqlDecimal.cs
index 29e5dd46f764f604a4010796719b7725ace25776..85e33561c69900eaabfafab059244793f1846237 100644 (file)
@@ -8,6 +8,29 @@
 // (C) Copyright 2002 Tim Coleman
 //
 
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using Mono.Data.Tds.Protocol;
 using System;
 using System.Text;
@@ -264,7 +287,9 @@ namespace System.Data.SqlTypes
 
                public static SqlDecimal ConvertToPrecScale (SqlDecimal n, int precision, int scale)
                {
-                       return new SqlDecimal ((byte)precision, (byte)scale, n.IsPositive, n.Data);
+//                     return new SqlDecimal ((byte)precision, (byte)scale, n.IsPositive, n.Data);
+                       // FIXME: precision
+                       return AdjustScale (n, scale - n.scale, true);
                }
 
                public static SqlDecimal Divide (SqlDecimal x, SqlDecimal y)
@@ -542,6 +567,7 @@ namespace System.Data.SqlTypes
                        int texp = 0;
                        int rc = 0;
                        byte prec = 0; // precision
+                       bool positive = ! (x.positive ^ y.positive);
 
                        prec = x.Precision >= y.Precision ? x.Precision : y.Precision;
                        DecimalDivSub (ref x, ref y, ref lo, ref hi, ref texp);
@@ -574,7 +600,7 @@ namespace System.Data.SqlTypes
                        int resultMi2 = (int)(hi);
                        int resultHi = (int)(hi >> 32);
 
-                       return new SqlDecimal (prec, (byte)sc, true, resultLo,
+                       return new SqlDecimal (prec, (byte)sc, positive, resultLo,
                                                       resultMi, resultMi2,
                                                       resultHi);
                }
@@ -624,9 +650,9 @@ namespace System.Data.SqlTypes
 
                                        // 10^i/2^i=5^i 
                                        factor = constantsDecadeInt32Factors [i] >> i; 
-                                       System.Console.WriteLine ("***");
+//                                     System.Console.WriteLine ("***");
                                        Mult128By32 (ref clo, ref chi, factor, 0);
-                                       System.Console.WriteLine ((((double)chi) * Math.Pow (2,64) + clo));
+//                                     System.Console.WriteLine ((((double)chi) * Math.Pow (2,64) + clo));
 
                                }