summaryrefslogtreecommitdiff
path: root/strings
diff options
context:
space:
mode:
authorunknown <holyfoot@hf-ibm.(none)>2005-05-05 20:06:49 +0500
committerunknown <holyfoot@hf-ibm.(none)>2005-05-05 20:06:49 +0500
commit6de14a23f7de447e4e6c4b82e2be032b05214c9a (patch)
tree28239d480c5b5f518077513738c6718aafd3584d /strings
parentc0f355762547c01192478b60659038b7751a1ced (diff)
downloadmariadb-git-6de14a23f7de447e4e6c4b82e2be032b05214c9a.tar.gz
A lot of fixes to Precision math
Mostly about precision/decimals of the results of the operations include/decimal.h: decimal interface changed a little sql/field.cc: a lot of precision/decimals related changes to the Field_new_decimal sql/field.h: Field_new_decimal interface changed sql/ha_ndbcluster.cc: f->precision should be used here sql/item.cc: precision/decimals counting related changes sql/item.h: precision/decimals counting related changes sql/item_cmpfunc.cc: precision/decimals counting related changes sql/item_cmpfunc.h: precision/decimals counting related changes sql/item_func.cc: precision/decimals counting related changes sql/item_func.h: precision/decimals counting related changes sql/item_sum.cc: precision/decimals counting related changes sql/item_sum.h: precision/decimals counting related changes sql/my_decimal.cc: precision/decimals counting related changes sql/my_decimal.h: precision/decimals counting related changes sql/mysqld.cc: precision/decimals counting related changes sql/set_var.cc: precision/decimals counting related changes sql/sp_head.cc: dbug_decimal_print was replaced with dbug_decimal_as_string sql/sql_class.h: div_precincrement variable added sql/sql_parse.cc: precision/decimals counting related changes sql/sql_select.cc: precision/decimals counting related changes sql/sql_show.cc: Field::representation_length was removed strings/decimal.c: decimal_actual_fraction was introduced BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted
Diffstat (limited to 'strings')
-rw-r--r--strings/decimal.c26
1 files changed, 9 insertions, 17 deletions
diff --git a/strings/decimal.c b/strings/decimal.c
index 9af95511f6d..52003a930c0 100644
--- a/strings/decimal.c
+++ b/strings/decimal.c
@@ -274,20 +274,20 @@ static dec1 *remove_leading_zeroes(decimal_t *from, int *intg_result)
/*
- Remove ending 0 digits from fraction part
+ Count actual length of fraction part (without ending zeroes)
SYNOPSIS
- decimal_optimize_fraction()
+ decimal_actual_fraction()
from number for processing
*/
-void decimal_optimize_fraction(decimal_t *from)
+int decimal_actual_fraction(decimal_t *from)
{
int frac= from->frac, i;
dec1 *buf0= from->buf + ROUND_UP(from->intg) + ROUND_UP(frac) - 1;
if (frac == 0)
- return;
+ return 0;
i= ((frac - 1) % DIG_PER_DEC1 + 1);
while (frac > 0 && *buf0 == 0)
@@ -302,7 +302,7 @@ void decimal_optimize_fraction(decimal_t *from)
*buf0 % powers10[i++] == 0;
frac--);
}
- from->frac= frac;
+ return frac;
}
@@ -332,23 +332,15 @@ int decimal2string(decimal_t *from, char *to, int *to_len,
int fixed_precision, int fixed_decimals,
char filler)
{
- int len, intg, frac=from->frac, i, intg_len, frac_len, fill;
+ int len, intg, frac= from->frac, i, intg_len, frac_len, fill;
/* number digits before decimal point */
int fixed_intg= (fixed_precision ?
- (fixed_precision -
- (from->sign ? 1 : 0) -
- (fixed_decimals ? 1 : 0) -
- fixed_decimals) :
- 0);
+ (fixed_precision - fixed_decimals) : 0);
int error=E_DEC_OK;
char *s=to;
dec1 *buf, *buf0=from->buf, tmp;
DBUG_ASSERT(*to_len >= 2+from->sign);
- DBUG_ASSERT(fixed_precision == 0 ||
- (fixed_precision < *to_len &&
- fixed_precision > ((from->sign ? 1 : 0) +
- (fixed_decimals ? 1 : 0))));
/* removing leading zeroes */
buf0= remove_leading_zeroes(from, &intg);
@@ -2609,7 +2601,7 @@ void test_fr(const char *s1, const char *orig)
printf("%-40s => ", s);
end= strend(s1);
string2decimal(s1, &a, &end);
- decimal_optimize_fraction(&a);
+ a.frac= decimal_actual_fraction(&a);
print_decimal(&a, orig, 0, 0);
printf("\n");
}
@@ -2947,7 +2939,7 @@ int main()
test_sh("123456789.987654321", 0, "123456789.987654321", 0);
a.len= sizeof(buf1)/sizeof(dec1);
- printf("==== decimal_optimize_fraction ====\n");
+ printf("==== decimal_actual_fraction ====\n");
test_fr("1.123456789000000000", "1.123456789");
test_fr("1.12345678000000000", "1.12345678");
test_fr("1.1234567000000000", "1.1234567");