List:Commits« Previous MessageNext Message »
From:tim Date:December 20 2006 12:42am
Subject:bk commit into 5.0 tree (tsmith:1.2354) BUG#23260
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of tim. When tim does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2006-12-19 17:42:26-07:00, tsmith@stripped +1 -0
  Alternative decimal2double implementation using an algorithm
  more similar to my_strtod() (and maybe even a bit faster due
  to less floating point divisions).
  
  This should at least partially fix Bug #23260 for DECIMALs
  with a moderate number of total digits.
  

  strings/decimal.c@stripped, 2006-12-19 17:42:24-07:00, tsmith@stripped +27 -9
    Alternative decimal2double implementation using an algorithm
    more similar to my_strtod() (and maybe even a bit faster due
    to less floating point divisions).
    
    This should at least partially fix Bug #23260 for DECIMALs
    with a moderate number of total digits.
    

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	tsmith
# Host:	siva.hindu.god
# Root:	/usr/home/tim/m/bk/50-release

--- 1.72/strings/decimal.c	2006-12-19 17:42:33 -07:00
+++ 1.73/strings/decimal.c	2006-12-19 17:42:33 -07:00
@@ -138,6 +138,12 @@ static const dec1 frac_max[DIG_PER_DEC1-
   900000000, 990000000, 999000000,
   999900000, 999990000, 999999000,
   999999900, 999999990 };
+static double scaler10[]= {
+  1.0, 1e10, 1e20, 1e30, 1e40, 1e50, 1e60, 1e70, 1e80, 1e90
+};
+static double scaler1[]= {
+  1.0, 10.0, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9
+};
 
 #ifdef HAVE_purify
 #define sanity(d) DBUG_ASSERT((d)->len > 0)
@@ -946,15 +952,27 @@ fatal_error:
 
 int decimal2double(decimal_t *from, double *to)
 {
-  double x=0, t=DIG_BASE;
-  int intg, frac;
-  dec1 *buf=from->buf;
-
-  for (intg=from->intg; intg > 0; intg-=DIG_PER_DEC1)
-    x=x*DIG_BASE + *buf++;
-  for (frac=from->frac; frac > 0; frac-=DIG_PER_DEC1, t*=DIG_BASE)
-    x+=*buf++/t;
-  *to=from->sign ? -x : x;
+  double result= 0.0;
+  int i, exp= 0;
+  dec1 *buf= from->buf;
+
+  for (i= from->intg; i > 0;  i-= DIG_PER_DEC1)
+    result= result * DIG_BASE + *buf++;
+
+  for (i= from->frac; i > 0; i-= DIG_PER_DEC1) {
+    result= result * DIG_BASE + *buf++;
+    exp+= DIG_PER_DEC1;
+  }
+
+  DBUG_PRINT("info", ("interm.: %f %d %f", result, exp,
+             scaler10[exp / 10] * scaler1[exp % 10]));
+
+  result/= scaler10[exp / 10] * scaler1[exp % 10];
+
+  *to= from->sign ? -result : result;
+
+  DBUG_PRINT("info", ("result: %f (%lx)", *to, *to));
+
   return E_DEC_OK;
 }
 
Thread
bk commit into 5.0 tree (tsmith:1.2354) BUG#23260tim20 Dec