diff --git a/mysql-test/r/type_newdecimal.result b/mysql-test/r/type_newdecimal.result index 759116684ddebd60c20844a8a62a6eba93c634c0..fc6955f11d2841013556ce943465194a62d27948 100644 --- a/mysql-test/r/type_newdecimal.result +++ b/mysql-test/r/type_newdecimal.result @@ -1478,6 +1478,9 @@ Error 1264 Out of range value for column 'cast(a as DECIMAL(3,2))' at row 1 create table t1 (s varchar(100)); insert into t1 values (0.00000000010000000000000000364321973154977415791655470655996396089904010295867919921875); drop table t1; +SELECT 1.000000000000 * 99.999999999998 / 100 a,1.000000000000 * (99.999999999998 / 100) b; +a b +0.9999999999999800000000000000 0.9999999999999800000000000000 End of 5.0 tests select cast(143.481 as decimal(4,1)); cast(143.481 as decimal(4,1)) diff --git a/mysql-test/t/type_newdecimal.test b/mysql-test/t/type_newdecimal.test index 704531664f93c996b63d98a20e29b5f15aa80512..e052ecfa82beb27f6725062ca2d29b2427a51e91 100644 --- a/mysql-test/t/type_newdecimal.test +++ b/mysql-test/t/type_newdecimal.test @@ -1167,6 +1167,11 @@ create table t1 (s varchar(100)); insert into t1 values (0.00000000010000000000000000364321973154977415791655470655996396089904010295867919921875); drop table t1; +# +# Bug #27984 Long Decimal Maths produces truncated results +# + +SELECT 1.000000000000 * 99.999999999998 / 100 a,1.000000000000 * (99.999999999998 / 100) b; --echo End of 5.0 tests # diff --git a/strings/decimal.c b/strings/decimal.c index 0768c8cd4cab17ca72cc0cacb39628d079c06af8..09d535f3f221ac2d07e2e24ad183e214d6dbee94 100644 --- a/strings/decimal.c +++ b/strings/decimal.c @@ -1523,9 +1523,10 @@ decimal_round(decimal_t *from, decimal_t *to, int scale, dec1 *p0= buf0+intg0+max(frac1, frac0); dec1 *p1= buf1+intg1+max(frac1, frac0); - to->buf[0]= 0; while (buf0 < p0) *(--p1) = *(--p0); + if (unlikely(intg1 > intg0)) + to->buf[0]= 0; intg0= intg1; buf0=to->buf;