summaryrefslogtreecommitdiff
path: root/sql/my_decimal.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/my_decimal.cc')
-rw-r--r--sql/my_decimal.cc34
1 files changed, 26 insertions, 8 deletions
diff --git a/sql/my_decimal.cc b/sql/my_decimal.cc
index 4ef2ae5cf95..1f0ebf32795 100644
--- a/sql/my_decimal.cc
+++ b/sql/my_decimal.cc
@@ -118,7 +118,7 @@ int my_decimal2string(uint mask, const my_decimal *d,
E_DEC_OVERFLOW
*/
-int my_decimal2binary(uint mask, const my_decimal *d, char *bin, int prec,
+int my_decimal2binary(uint mask, const my_decimal *d, uchar *bin, int prec,
int scale)
{
int err1= E_DEC_OK, err2;
@@ -208,25 +208,43 @@ my_decimal *date2my_decimal(MYSQL_TIME *ltime, my_decimal *dec)
}
+void my_decimal_trim(ulong *precision, uint *scale)
+{
+ if (!(*precision) && !(*scale))
+ {
+ *precision= 10;
+ *scale= 0;
+ return;
+ }
+}
+
+
#ifndef DBUG_OFF
/* routines for debugging print */
+#define DIG_PER_DEC1 9
+#define ROUND_UP(X) (((X)+DIG_PER_DEC1-1)/DIG_PER_DEC1)
+
/* print decimal */
void
print_decimal(const my_decimal *dec)
{
- fprintf(DBUG_FILE,
- "\nDecimal: sign: %d intg: %d frac: %d \n\
-%09d,%09d,%09d,%09d,%09d,%09d,%09d,%09d\n",
- dec->sign(), dec->intg, dec->frac,
- dec->buf[0], dec->buf[1], dec->buf[2], dec->buf[3],
- dec->buf[4], dec->buf[5], dec->buf[6], dec->buf[7]);
+ int i, end;
+ char buff[512], *pos;
+ pos= buff;
+ pos+= my_sprintf(buff, (buff, "Decimal: sign: %d intg: %d frac: %d { ",
+ dec->sign(), dec->intg, dec->frac));
+ end= ROUND_UP(dec->frac)+ROUND_UP(dec->intg)-1;
+ for (i=0; i < end; i++)
+ pos+= my_sprintf(pos, (pos, "%09d, ", dec->buf[i]));
+ pos+= my_sprintf(pos, (pos, "%09d }\n", dec->buf[i]));
+ fputs(buff, DBUG_FILE);
}
/* print decimal with its binary representation */
void
-print_decimal_buff(const my_decimal *dec, const byte* ptr, int length)
+print_decimal_buff(const my_decimal *dec, const uchar* ptr, int length)
{
print_decimal(dec);
fprintf(DBUG_FILE, "Record: ");