summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <sasha@mysql.sashanet.com>2001-08-16 12:01:35 -0600
committerunknown <sasha@mysql.sashanet.com>2001-08-16 12:01:35 -0600
commit6ca8d50cb14ac9171f4e3cf29483c414c93710e8 (patch)
treedcd5183294961fc8a3d569157a27e401d484b2c2 /sql
parent2b8614210d1db003a6827f301dad0321b1a7478e (diff)
downloadmariadb-git-6ca8d50cb14ac9171f4e3cf29483c414c93710e8.tar.gz
fixed bug in Item_func_div::val_int() that broke all functions that
do val_int() on their arguments before starting the computation. Similar fixes are need for +-* and probably several other but I want to make sure Monty is fine with my fix approach before changing a lot of code. Amazingly, this bug is not as critical as you would expect since very few functions do val_int() on their arguments ( from_unixtime(), sec_to_time()), and those not very frequently perform a computation on their floating point arguments. which is probably why no one has yet reported this bug. Another possibility is that the result is usually wrong by no more than 5%, which makes it hard to catch it. I found it when trying to compute mile splits for 30:47 10K - it told me 5:07, and I knew it was wrong because 5:00 mile gives you 31:08. However, if I had not run as many 10K races, I would have easily believed that 30:47 10K is a 5:07 mile pace and would not have noticed the bug. mysql-test/r/func_time.result: another test for sec_to_time that exposes a long outstanding bug mysql-test/t/func_time.test: another test for sec_to_time that exposes a long outstanding bug sql/item_func.cc: fixed bug in Item_func_div::val_int()
Diffstat (limited to 'sql')
-rw-r--r--sql/item_func.cc13
1 files changed, 8 insertions, 5 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 10298ce67f2..1d1a72d35eb 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -309,11 +309,14 @@ double Item_func_div::val()
longlong Item_func_div::val_int()
{
- longlong value=args[0]->val_int();
- longlong val2=args[1]->val_int();
- if ((null_value= val2 == 0 || args[0]->null_value || args[1]->null_value))
- return 0;
- return value/val2;
+ // the integer result of division of two arguments needs to be computed
+ // as a type-cast division of val(), not as diviion of val_int() of each
+ // argument. For example, val_int(41.5/3.4) = val_int(12.206) = 12, but
+ // if you do val_int(41.5)/val_int(3.4), as in the old code, we get 42/3=
+ // 14, which is wrong. This would break sec_to_time(a/b),
+ // from_unixtime(a/b), and
+ // all functions that do val_int() on their arguments
+ return (longlong)val();
}
void Item_func_div::fix_length_and_dec()