diff options
Diffstat (limited to 'strings/decimal.c')
-rw-r--r-- | strings/decimal.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/strings/decimal.c b/strings/decimal.c index 3176cf6afa7..0559dd97613 100644 --- a/strings/decimal.c +++ b/strings/decimal.c @@ -991,12 +991,18 @@ int decimal2double(decimal_t *from, double *to) int double2decimal(double from, decimal_t *to) { /* TODO: fix it, when we'll have dtoa */ - char s[400], *end; - sprintf(s, "%.16G", from); - end= strend(s); - return string2decimal(s, to, &end); + char buff[400], *end; + int length, res; + DBUG_ENTER("double2decimal"); + length= my_sprintf(buff, (buff, "%.16G", from)); + DBUG_PRINT("info",("from: %g from_as_str: %s", from, buff)); + end= buff+length; + res= string2decimal(buff, to, &end); + DBUG_PRINT("exit", ("res: %d", res)); + DBUG_RETURN(res); } + static int ull2dec(ulonglong from, decimal_t *to) { int intg1, error=E_DEC_OK; @@ -1184,7 +1190,7 @@ int decimal2longlong(decimal_t *from, longlong *to) 7E F2 04 37 2D FB 2D */ -int decimal2bin(decimal_t *from, char *to, int precision, int frac) +int decimal2bin(decimal_t *from, uchar *to, int precision, int frac) { dec1 mask=from->sign ? -1 : 0, *buf1=from->buf, *stop1; int error=E_DEC_OK, intg=precision-frac, @@ -1200,7 +1206,7 @@ int decimal2bin(decimal_t *from, char *to, int precision, int frac) fsize1=frac1*sizeof(dec1)+dig2bytes[frac1x]; const int orig_isize0= isize0; const int orig_fsize0= fsize0; - char *orig_to= to; + uchar *orig_to= to; buf1= remove_leading_zeroes(from, &from_intg); @@ -1290,10 +1296,10 @@ int decimal2bin(decimal_t *from, char *to, int precision, int frac) } if (fsize0 > fsize1) { - char *to_end= orig_to + orig_fsize0 + orig_isize0; + uchar *to_end= orig_to + orig_fsize0 + orig_isize0; while (fsize0-- > fsize1 && to < to_end) - *to++=(uchar)mask; + *to++= (uchar)mask; } orig_to[0]^= 0x80; @@ -1319,19 +1325,19 @@ int decimal2bin(decimal_t *from, char *to, int precision, int frac) E_DEC_OK/E_DEC_TRUNCATED/E_DEC_OVERFLOW */ -int bin2decimal(char *from, decimal_t *to, int precision, int scale) +int bin2decimal(const uchar *from, decimal_t *to, int precision, int scale) { int error=E_DEC_OK, intg=precision-scale, intg0=intg/DIG_PER_DEC1, frac0=scale/DIG_PER_DEC1, intg0x=intg-intg0*DIG_PER_DEC1, frac0x=scale-frac0*DIG_PER_DEC1, intg1=intg0+(intg0x>0), frac1=frac0+(frac0x>0); dec1 *buf=to->buf, mask=(*from & 0x80) ? 0 : -1; - char *stop; - char *d_copy; + const uchar *stop; + uchar *d_copy; int bin_size= decimal_bin_size(precision, scale); sanity(to); - d_copy= (char *)my_alloca(bin_size); + d_copy= (uchar*) my_alloca(bin_size); memcpy(d_copy, from, bin_size); d_copy[0]^= 0x80; from= d_copy; |