summaryrefslogtreecommitdiff
path: root/sql/item_func.cc
diff options
context:
space:
mode:
authorTor Didriksen <tor.didriksen@oracle.com>2011-11-15 10:01:29 +0100
committerTor Didriksen <tor.didriksen@oracle.com>2011-11-15 10:01:29 +0100
commit38138943618ab00d82044a82e0da81527a267a6b (patch)
treea6a20072e4091d6a4b94caaa49cc0401d30a200c /sql/item_func.cc
parenta2f757eabea5b38db5ffcaac10751bbb8475ff06 (diff)
downloadmariadb-git-38138943618ab00d82044a82e0da81527a267a6b.tar.gz
Bug#13261955 TRUNCATE(DBL_MAX) RETURNS DBL_MAX RATHER THAN 'INF'
my_double_round(DBL_MAX, -12, ....) should return 'inf' rather than DBL_MAX The problem is that floor(value/tmp) * tmp is inlined, and optimized away. The solution seems to be to prevent inlining by pre-computing value/tmp and storing it in a variable. No new test case: main.type_float fails without this patch.
Diffstat (limited to 'sql/item_func.cc')
-rw-r--r--sql/item_func.cc18
1 files changed, 12 insertions, 6 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 7257b411ec4..0cd6ff6357e 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -2328,25 +2328,31 @@ double my_double_round(double value, longlong dec, bool dec_unsigned,
/*
tmp2 is here to avoid return the value with 80 bit precision
This will fix that the test round(0.1,1) = round(0.1,1) is true
+ Tagging with volatile is no guarantee, it may still be optimized away...
*/
volatile double tmp2;
tmp=(abs_dec < array_elements(log_10) ?
log_10[abs_dec] : pow(10.0,(double) abs_dec));
+ // Pre-compute these, to avoid optimizing away e.g. 'floor(v/tmp) * tmp'.
+ volatile double value_div_tmp= value / tmp;
+ volatile double value_mul_tmp= value * tmp;
+
if (dec_negative && my_isinf(tmp))
- tmp2= 0;
- else if (!dec_negative && my_isinf(value * tmp))
+ tmp2= 0.0;
+ else if (!dec_negative && my_isinf(value_mul_tmp))
tmp2= value;
else if (truncate)
{
- if (value >= 0)
- tmp2= dec < 0 ? floor(value/tmp)*tmp : floor(value*tmp)/tmp;
+ if (value >= 0.0)
+ tmp2= dec < 0 ? floor(value_div_tmp) * tmp : floor(value_mul_tmp) / tmp;
else
- tmp2= dec < 0 ? ceil(value/tmp)*tmp : ceil(value*tmp)/tmp;
+ tmp2= dec < 0 ? ceil(value_div_tmp) * tmp : ceil(value_mul_tmp) / tmp;
}
else
- tmp2=dec < 0 ? rint(value/tmp)*tmp : rint(value*tmp)/tmp;
+ tmp2=dec < 0 ? rint(value_div_tmp) * tmp : rint(value_mul_tmp) / tmp;
+
return tmp2;
}