Below is the list of changes that have just been committed into a local
5.0 repository of hartmut. When hartmut 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-11-10 19:54:01+01:00, hartmut@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-11-10 19:53:54+01:00, hartmut@stripped +26 -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: hartmut
# Host: linux.site
# Root: /home/hartmut/projects/mysql/dev/5.0
--- 1.70/strings/decimal.c 2006-11-10 19:54:11 +01:00
+++ 1.71/strings/decimal.c 2006-11-10 19:54:11 +01:00
@@ -138,6 +138,12 @@
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,26 @@
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 (hartmut:1.2296) BUG#23260 | 'Hartmut Holzgraefe' | 10 Nov |