diff options
author | unknown <kaa@kaamos.(none)> | 2008-02-20 00:33:43 +0300 |
---|---|---|
committer | unknown <kaa@kaamos.(none)> | 2008-02-20 00:33:43 +0300 |
commit | 61c31af45d075e1aa1135b502209c04ca890425f (patch) | |
tree | 5543a0d99f0ea26b6a31aabda1379272bf9395dd /sql/item_func.cc | |
parent | 78e19d4283572f1706738980b8242a5e65619caf (diff) | |
download | mariadb-git-61c31af45d075e1aa1135b502209c04ca890425f.tar.gz |
Fix for bug #31236: Inconsistent division by zero behavior for
floating point numbers
Some math functions did not check if the result is a valid number
(i.e. neither of +-inf or nan).
Fixed by validating the result where necessary and returning NULL in
case of invalid result.
BitKeeper/deleted/.del-matherr.c:
Rename: sql/matherr.c -> BitKeeper/deleted/.del-matherr.c
configure.in:
Removed DONT_USE_FINITE, it is not used anywhere.
include/my_global.h:
isfinite() is a C99 macro which absoletes finite(). First try to use
it, then fall back to finite() if the target platform has it,
otherwise use our own implementation.
mysql-test/r/func_math.result:
Added a test case for bug #31236.
mysql-test/r/strict.result:
Fixed a test case which relied on old behavior.
mysql-test/t/func_math.test:
Added a test case for bug #31236.
mysql-test/t/strict.test:
Fixed a test case which relied on old behavior.
sql/field.cc:
No need to check if the finite() or its equivalent is available.
sql/item_func.cc:
Use fix_result() wherever the result can be one of +-inf or nan,
assuming the function arguments are valid numbers.
Removed fix_result() from functions that are defined for all possible
input numbers.
sql/item_func.h:
Moved fix_result() from Item_dec_func to Item_func which is a common
ancestor for Item_dec_func and Item_num_op.
sql/unireg.h:
Removed POSTFIX_ERROR because no code returns it.
Diffstat (limited to 'sql/item_func.cc')
-rw-r--r-- | sql/item_func.cc | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc index 8fd6f0966ad..3d6ed590f81 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1104,7 +1104,7 @@ double Item_func_plus::real_op() double value= args[0]->val_real() + args[1]->val_real(); if ((null_value=args[0]->null_value || args[1]->null_value)) return 0.0; - return value; + return fix_result(value); } @@ -1186,7 +1186,7 @@ double Item_func_minus::real_op() double value= args[0]->val_real() - args[1]->val_real(); if ((null_value=args[0]->null_value || args[1]->null_value)) return 0.0; - return value; + return fix_result(value); } @@ -1224,7 +1224,7 @@ double Item_func_mul::real_op() double value= args[0]->val_real() * args[1]->val_real(); if ((null_value=args[0]->null_value || args[1]->null_value)) return 0.0; - return value; + return fix_result(value); } @@ -1282,7 +1282,7 @@ double Item_func_div::real_op() signal_divide_by_null(); return 0.0; } - return value/val2; + return fix_result(value/val2); } @@ -1655,7 +1655,7 @@ double Item_func_exp::val_real() double value= args[0]->val_real(); if ((null_value=args[0]->null_value)) return 0.0; /* purecov: inspected */ - return exp(value); + return fix_result(exp(value)); } double Item_func_sqrt::val_real() @@ -1674,7 +1674,7 @@ double Item_func_pow::val_real() double val2= args[1]->val_real(); if ((null_value=(args[0]->null_value || args[1]->null_value))) return 0.0; /* purecov: inspected */ - return pow(value,val2); + return fix_result(pow(value,val2)); } // Trigonometric functions @@ -1686,7 +1686,7 @@ double Item_func_acos::val_real() volatile double value= args[0]->val_real(); if ((null_value=(args[0]->null_value || (value < -1.0 || value > 1.0)))) return 0.0; - return fix_result(acos(value)); + return acos(value); } double Item_func_asin::val_real() @@ -1696,7 +1696,7 @@ double Item_func_asin::val_real() volatile double value= args[0]->val_real(); if ((null_value=(args[0]->null_value || (value < -1.0 || value > 1.0)))) return 0.0; - return fix_result(asin(value)); + return asin(value); } double Item_func_atan::val_real() @@ -1712,7 +1712,7 @@ double Item_func_atan::val_real() return 0.0; return fix_result(atan2(value,val2)); } - return fix_result(atan(value)); + return atan(value); } double Item_func_cos::val_real() @@ -1721,7 +1721,7 @@ double Item_func_cos::val_real() double value= args[0]->val_real(); if ((null_value=args[0]->null_value)) return 0.0; - return fix_result(cos(value)); + return cos(value); } double Item_func_sin::val_real() @@ -1730,7 +1730,7 @@ double Item_func_sin::val_real() double value= args[0]->val_real(); if ((null_value=args[0]->null_value)) return 0.0; - return fix_result(sin(value)); + return sin(value); } double Item_func_tan::val_real() |