Commit 13665252 authored by ram@gw.mysql.r18.ru's avatar ram@gw.mysql.r18.ru

A fix (bug #6138: MOD operator should not round non-integral argument).

parent 701b6463
...@@ -174,3 +174,12 @@ SELECT GREATEST(d,d) FROM t1 WHERE k=2; ...@@ -174,3 +174,12 @@ SELECT GREATEST(d,d) FROM t1 WHERE k=2;
GREATEST(d,d) GREATEST(d,d)
NULL NULL
DROP TABLE t1; DROP TABLE t1;
select 1197.90 mod 50;
1197.90 mod 50
47.90
select 5.1 mod 3, 5.1 mod -3, -5.1 mod 3, -5.1 mod -3;
5.1 mod 3 5.1 mod -3 -5.1 mod 3 -5.1 mod -3
2.1 2.1 -2.1 -2.1
select 5 mod 3, 5 mod -3, -5 mod 3, -5 mod -3;
5 mod 3 5 mod -3 -5 mod 3 -5 mod -3
2 2 -2 -2
...@@ -94,3 +94,16 @@ CREATE TABLE t1 (d varchar(6), k int); ...@@ -94,3 +94,16 @@ CREATE TABLE t1 (d varchar(6), k int);
INSERT INTO t1 VALUES (NULL, 2); INSERT INTO t1 VALUES (NULL, 2);
SELECT GREATEST(d,d) FROM t1 WHERE k=2; SELECT GREATEST(d,d) FROM t1 WHERE k=2;
DROP TABLE t1; DROP TABLE t1;
#
# Bug #6138: mod and doubles
#
select 1197.90 mod 50;
select 5.1 mod 3, 5.1 mod -3, -5.1 mod 3, -5.1 mod -3;
#
# Test for mod and signed integers
#
select 5 mod 3, 5 mod -3, -5 mod 3, -5 mod -3;
...@@ -651,11 +651,11 @@ void Item_func_int_div::fix_length_and_dec() ...@@ -651,11 +651,11 @@ void Item_func_int_div::fix_length_and_dec()
double Item_func_mod::val() double Item_func_mod::val()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
double value= floor(args[0]->val()+0.5); double x= args[0]->val();
double val2=floor(args[1]->val()+0.5); double y= args[1]->val();
if ((null_value=val2 == 0.0 || args[0]->null_value || args[1]->null_value)) if ((null_value= (y == 0.0) || args[0]->null_value || args[1]->null_value))
return 0.0; /* purecov: inspected */ return 0.0; /* purecov: inspected */
return fmod(value,val2); return fmod(x, y);
} }
longlong Item_func_mod::val_int() longlong Item_func_mod::val_int()
...@@ -670,10 +670,7 @@ longlong Item_func_mod::val_int() ...@@ -670,10 +670,7 @@ longlong Item_func_mod::val_int()
void Item_func_mod::fix_length_and_dec() void Item_func_mod::fix_length_and_dec()
{ {
max_length=args[1]->max_length; Item_num_op::fix_length_and_dec();
decimals=0;
maybe_null=1;
find_num_type();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment