Commit 30ac4901 authored by Alexey Kopytov's avatar Alexey Kopytov

Fix for bug #21205: Different number of digits for float/double/real in --ps-protocol

Various parts of code used different 'precision' arguments for sprintf("%g") when converting
floating point numbers to a string. This led to differences in results in some cases 
depending on whether the text-based or prepared statements protocol is used for a query.

Fixed by changing arguments to sprintf("%g") to always be 15 (DBL_DIG) so that results are
consistent regardless of the protocol.

This patch will be null-merged to 6.0 as the problem does not exists there (fixed by the
patch for WL#2934).
parent 2048bd71
...@@ -125,7 +125,7 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs) ...@@ -125,7 +125,7 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs)
str_charset=cs; str_charset=cs;
if (decimals >= NOT_FIXED_DEC) if (decimals >= NOT_FIXED_DEC)
{ {
uint32 len= my_sprintf(buff,(buff, "%.14g",num));// Enough for a DATETIME uint32 len= my_sprintf(buff,(buff, "%.15g",num));// Enough for a DATETIME
return copy(buff, len, &my_charset_latin1, cs, &dummy_errors); return copy(buff, len, &my_charset_latin1, cs, &dummy_errors);
} }
#ifdef HAVE_FCONVERT #ifdef HAVE_FCONVERT
...@@ -677,7 +677,7 @@ void String::qs_append(const char *str, uint32 len) ...@@ -677,7 +677,7 @@ void String::qs_append(const char *str, uint32 len)
void String::qs_append(double d) void String::qs_append(double d)
{ {
char *buff = Ptr + str_length; char *buff = Ptr + str_length;
str_length+= my_sprintf(buff, (buff, "%.14g", d)); str_length+= my_sprintf(buff, (buff, "%.15g", d));
} }
void String::qs_append(double *d) void String::qs_append(double *d)
......
...@@ -3786,13 +3786,13 @@ static void fetch_float_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, ...@@ -3786,13 +3786,13 @@ static void fetch_float_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field,
#undef NOT_FIXED_DEC #undef NOT_FIXED_DEC
{ {
/* /*
The 14 below is to ensure that the server and client has the same DBL_DIG below is to ensure that the server and client has the same
precisions. This will ensure that on the same machine you get the precisions. This will ensure that on the same machine you get the
same value as a string independent of the protocol you use. same value as a string independent of the protocol you use.
*/ */
sprintf(buff, "%-*.*g", (int) min(sizeof(buff)-1, sprintf(buff, "%-*.*g", (int) min(sizeof(buff)-1,
param->buffer_length), param->buffer_length),
min(14,width), value); min(DBL_DIG, width), value);
end= strcend(buff, ' '); end= strcend(buff, ' ');
*end= 0; *end= 0;
} }
......
...@@ -291,7 +291,7 @@ Note 1003 select astext(startpoint(`test`.`gis_line`.`g`)) AS `AsText(StartPoint ...@@ -291,7 +291,7 @@ Note 1003 select astext(startpoint(`test`.`gis_line`.`g`)) AS `AsText(StartPoint
SELECT fid, AsText(Centroid(g)) FROM gis_polygon ORDER by fid; SELECT fid, AsText(Centroid(g)) FROM gis_polygon ORDER by fid;
fid AsText(Centroid(g)) fid AsText(Centroid(g))
108 POINT(15 15) 108 POINT(15 15)
109 POINT(25.416666666667 25.416666666667) 109 POINT(25.4166666666667 25.4166666666667)
110 POINT(20 10) 110 POINT(20 10)
SELECT fid, Area(g) FROM gis_polygon ORDER by fid; SELECT fid, Area(g) FROM gis_polygon ORDER by fid;
fid Area(g) fid Area(g)
...@@ -325,8 +325,8 @@ fid IsClosed(g) ...@@ -325,8 +325,8 @@ fid IsClosed(g)
116 0 116 0
SELECT fid, AsText(Centroid(g)) FROM gis_multi_polygon ORDER by fid; SELECT fid, AsText(Centroid(g)) FROM gis_multi_polygon ORDER by fid;
fid AsText(Centroid(g)) fid AsText(Centroid(g))
117 POINT(55.588527753042 17.426536064114) 117 POINT(55.5885277530424 17.426536064114)
118 POINT(55.588527753042 17.426536064114) 118 POINT(55.5885277530424 17.426536064114)
119 POINT(2 2) 119 POINT(2 2)
SELECT fid, Area(g) FROM gis_multi_polygon ORDER by fid; SELECT fid, Area(g) FROM gis_multi_polygon ORDER by fid;
fid Area(g) fid Area(g)
......
...@@ -61,7 +61,7 @@ grp sum ...@@ -61,7 +61,7 @@ grp sum
NULL NULL NULL NULL
1 7 1 7
2 20.25 2 20.25
3 45.483163247594 3 45.4831632475944
create table t2 (grp int, a bigint unsigned, c char(10)); create table t2 (grp int, a bigint unsigned, c char(10));
insert into t2 select grp,max(a)+max(grp),max(c) from t1 group by grp; insert into t2 select grp,max(a)+max(grp),max(c) from t1 group by grp;
replace into t2 select grp, a, c from t1 limit 2,1; replace into t2 select grp, a, c from t1 limit 2,1;
...@@ -1195,7 +1195,7 @@ std(s1/s2) ...@@ -1195,7 +1195,7 @@ std(s1/s2)
0.21325764 0.21325764
select std(o1/o2) from bug22555; select std(o1/o2) from bug22555;
std(o1/o2) std(o1/o2)
0.21325763586649 0.213257635866493
select std(e1/e2) from bug22555; select std(e1/e2) from bug22555;
std(e1/e2) std(e1/e2)
0.21325764 0.21325764
...@@ -1221,7 +1221,7 @@ round(std(s1/s2), 17) ...@@ -1221,7 +1221,7 @@ round(std(s1/s2), 17)
0.21325763586649341 0.21325763586649341
select std(o1/o2) from bug22555; select std(o1/o2) from bug22555;
std(o1/o2) std(o1/o2)
0.21325763586649 0.213257635866493
select round(std(e1/e2), 17) from bug22555; select round(std(e1/e2), 17) from bug22555;
round(std(e1/e2), 17) round(std(e1/e2), 17)
0.21325763586649341 0.21325763586649341
...@@ -1246,7 +1246,7 @@ round(std(s1/s2), 17) ...@@ -1246,7 +1246,7 @@ round(std(s1/s2), 17)
0.21325763586649341 0.21325763586649341
select std(o1/o2) from bug22555; select std(o1/o2) from bug22555;
std(o1/o2) std(o1/o2)
0.21325763586649 0.213257635866493
select round(std(e1/e2), 17) from bug22555; select round(std(e1/e2), 17) from bug22555;
round(std(e1/e2), 17) round(std(e1/e2), 17)
0.21325763586649341 0.21325763586649341
......
...@@ -60,7 +60,7 @@ Warnings: ...@@ -60,7 +60,7 @@ Warnings:
Note 1003 select ln(exp(10)) AS `ln(exp(10))`,exp((ln(sqrt(10)) * 2)) AS `exp(ln(sqrt(10))*2)`,ln(-(1)) AS `ln(-1)`,ln(0) AS `ln(0)`,ln(NULL) AS `ln(NULL)` Note 1003 select ln(exp(10)) AS `ln(exp(10))`,exp((ln(sqrt(10)) * 2)) AS `exp(ln(sqrt(10))*2)`,ln(-(1)) AS `ln(-1)`,ln(0) AS `ln(0)`,ln(NULL) AS `ln(NULL)`
select log2(8),log2(15),log2(-2),log2(0),log2(NULL); select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
log2(8) log2(15) log2(-2) log2(0) log2(NULL) log2(8) log2(15) log2(-2) log2(0) log2(NULL)
3 3.9068905956085 NULL NULL NULL 3 3.90689059560852 NULL NULL NULL
explain extended select log2(8),log2(15),log2(-2),log2(0),log2(NULL); explain extended select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
...@@ -68,7 +68,7 @@ Warnings: ...@@ -68,7 +68,7 @@ Warnings:
Note 1003 select log2(8) AS `log2(8)`,log2(15) AS `log2(15)`,log2(-(2)) AS `log2(-2)`,log2(0) AS `log2(0)`,log2(NULL) AS `log2(NULL)` Note 1003 select log2(8) AS `log2(8)`,log2(15) AS `log2(15)`,log2(-(2)) AS `log2(-2)`,log2(0) AS `log2(0)`,log2(NULL) AS `log2(NULL)`
select log10(100),log10(18),log10(-4),log10(0),log10(NULL); select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
log10(100) log10(18) log10(-4) log10(0) log10(NULL) log10(100) log10(18) log10(-4) log10(0) log10(NULL)
2 1.2552725051033 NULL NULL NULL 2 1.25527250510331 NULL NULL NULL
explain extended select log10(100),log10(18),log10(-4),log10(0),log10(NULL); explain extended select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
...@@ -85,7 +85,7 @@ Note 1003 select pow(10,log10(10)) AS `pow(10,log10(10))`,pow(2,4) AS `power(2,4 ...@@ -85,7 +85,7 @@ Note 1003 select pow(10,log10(10)) AS `pow(10,log10(10))`,pow(2,4) AS `power(2,4
set @@rand_seed1=10000000,@@rand_seed2=1000000; set @@rand_seed1=10000000,@@rand_seed2=1000000;
select rand(999999),rand(); select rand(999999),rand();
rand(999999) rand() rand(999999) rand()
0.014231365187309 0.028870999839968 0.0142313651873091 0.028870999839968
explain extended select rand(999999),rand(); explain extended select rand(999999),rand();
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
...@@ -101,7 +101,7 @@ Warnings: ...@@ -101,7 +101,7 @@ Warnings:
Note 1003 select pi() AS `pi()`,format(sin((pi() / 2)),6) AS `format(sin(pi()/2),6)`,format(cos((pi() / 2)),6) AS `format(cos(pi()/2),6)`,format(abs(tan(pi())),6) AS `format(abs(tan(pi())),6)`,format((1 / tan(1)),6) AS `format(cot(1),6)`,format(asin(1),6) AS `format(asin(1),6)`,format(acos(0),6) AS `format(acos(0),6)`,format(atan(1),6) AS `format(atan(1),6)` Note 1003 select pi() AS `pi()`,format(sin((pi() / 2)),6) AS `format(sin(pi()/2),6)`,format(cos((pi() / 2)),6) AS `format(cos(pi()/2),6)`,format(abs(tan(pi())),6) AS `format(abs(tan(pi())),6)`,format((1 / tan(1)),6) AS `format(cot(1),6)`,format(asin(1),6) AS `format(asin(1),6)`,format(acos(0),6) AS `format(acos(0),6)`,format(atan(1),6) AS `format(atan(1),6)`
select degrees(pi()),radians(360); select degrees(pi()),radians(360);
degrees(pi()) radians(360) degrees(pi()) radians(360)
180 6.2831853071796 180 6.28318530717959
SELECT ACOS(1.0); SELECT ACOS(1.0);
ACOS(1.0) ACOS(1.0)
0 0
...@@ -321,7 +321,7 @@ mod(5, cast(-2 as unsigned)) mod(5, 18446744073709551614) mod(5, -2) ...@@ -321,7 +321,7 @@ mod(5, cast(-2 as unsigned)) mod(5, 18446744073709551614) mod(5, -2)
5 5 1 5 5 1
select pow(cast(-2 as unsigned), 5), pow(18446744073709551614, 5), pow(-2, 5); select pow(cast(-2 as unsigned), 5), pow(18446744073709551614, 5), pow(-2, 5);
pow(cast(-2 as unsigned), 5) pow(18446744073709551614, 5) pow(-2, 5) pow(cast(-2 as unsigned), 5) pow(18446744073709551614, 5) pow(-2, 5)
2.1359870359209e+96 2.1359870359209e+96 -32 2.13598703592091e+96 2.13598703592091e+96 -32
CREATE TABLE t1 (a timestamp, b varchar(20), c bit(1)); CREATE TABLE t1 (a timestamp, b varchar(20), c bit(1));
INSERT INTO t1 VALUES('1998-09-23', 'str1', 1), ('2003-03-25', 'str2', 0); INSERT INTO t1 VALUES('1998-09-23', 'str1', 1), ('2003-03-25', 'str2', 0);
SELECT a DIV 900 y FROM t1 GROUP BY y; SELECT a DIV 900 y FROM t1 GROUP BY y;
......
...@@ -1131,10 +1131,10 @@ cast(rtrim(ltrim(' 20.06 ')) as decimal(19,2)) ...@@ -1131,10 +1131,10 @@ cast(rtrim(ltrim(' 20.06 ')) as decimal(19,2))
20.06 20.06
select conv("18383815659218730760",10,10) + 0; select conv("18383815659218730760",10,10) + 0;
conv("18383815659218730760",10,10) + 0 conv("18383815659218730760",10,10) + 0
1.8383815659219e+19 1.83838156592187e+19
select "18383815659218730760" + 0; select "18383815659218730760" + 0;
"18383815659218730760" + 0 "18383815659218730760" + 0
1.8383815659219e+19 1.83838156592187e+19
CREATE TABLE t1 (code varchar(10)); CREATE TABLE t1 (code varchar(10));
INSERT INTO t1 VALUES ('a12'), ('A12'), ('a13'); INSERT INTO t1 VALUES ('a12'), ('A12'), ('a13');
SELECT ASCII(code), code FROM t1 WHERE code='A12'; SELECT ASCII(code), code FROM t1 WHERE code='A12';
......
...@@ -284,7 +284,7 @@ Note 1003 select astext(startpoint(`test`.`gis_line`.`g`)) AS `AsText(StartPoint ...@@ -284,7 +284,7 @@ Note 1003 select astext(startpoint(`test`.`gis_line`.`g`)) AS `AsText(StartPoint
SELECT fid, AsText(Centroid(g)) FROM gis_polygon; SELECT fid, AsText(Centroid(g)) FROM gis_polygon;
fid AsText(Centroid(g)) fid AsText(Centroid(g))
108 POINT(15 15) 108 POINT(15 15)
109 POINT(25.416666666667 25.416666666667) 109 POINT(25.4166666666667 25.4166666666667)
110 POINT(20 10) 110 POINT(20 10)
SELECT fid, Area(g) FROM gis_polygon; SELECT fid, Area(g) FROM gis_polygon;
fid Area(g) fid Area(g)
...@@ -318,8 +318,8 @@ fid IsClosed(g) ...@@ -318,8 +318,8 @@ fid IsClosed(g)
116 0 116 0
SELECT fid, AsText(Centroid(g)) FROM gis_multi_polygon; SELECT fid, AsText(Centroid(g)) FROM gis_multi_polygon;
fid AsText(Centroid(g)) fid AsText(Centroid(g))
117 POINT(55.588527753042 17.426536064114) 117 POINT(55.5885277530424 17.426536064114)
118 POINT(55.588527753042 17.426536064114) 118 POINT(55.5885277530424 17.426536064114)
119 POINT(2 2) 119 POINT(2 2)
SELECT fid, Area(g) FROM gis_multi_polygon; SELECT fid, Area(g) FROM gis_multi_polygon;
fid Area(g) fid Area(g)
...@@ -651,11 +651,11 @@ insert into t1 values ('85984',GeomFromText('MULTIPOLYGON(((-115.006363 ...@@ -651,11 +651,11 @@ insert into t1 values ('85984',GeomFromText('MULTIPOLYGON(((-115.006363
select object_id, geometrytype(geo), ISSIMPLE(GEO), ASTEXT(centroid(geo)) from select object_id, geometrytype(geo), ISSIMPLE(GEO), ASTEXT(centroid(geo)) from
t1 where object_id=85998; t1 where object_id=85998;
object_id geometrytype(geo) ISSIMPLE(GEO) ASTEXT(centroid(geo)) object_id geometrytype(geo) ISSIMPLE(GEO) ASTEXT(centroid(geo))
85998 MULTIPOLYGON 0 POINT(115.31877315203 -36.237472821022) 85998 MULTIPOLYGON 0 POINT(115.318773152032 -36.2374728210215)
select object_id, geometrytype(geo), ISSIMPLE(GEO), ASTEXT(centroid(geo)) from select object_id, geometrytype(geo), ISSIMPLE(GEO), ASTEXT(centroid(geo)) from
t1 where object_id=85984; t1 where object_id=85984;
object_id geometrytype(geo) ISSIMPLE(GEO) ASTEXT(centroid(geo)) object_id geometrytype(geo) ISSIMPLE(GEO) ASTEXT(centroid(geo))
85984 MULTIPOLYGON 0 POINT(-114.87787186923 36.33101763469) 85984 MULTIPOLYGON 0 POINT(-114.877871869233 36.3310176346905)
drop table t1; drop table t1;
create table t1 (fl geometry not null); create table t1 (fl geometry not null);
insert into t1 values (1); insert into t1 values (1);
......
...@@ -291,7 +291,7 @@ Note 1003 select astext(startpoint(`test`.`gis_line`.`g`)) AS `AsText(StartPoint ...@@ -291,7 +291,7 @@ Note 1003 select astext(startpoint(`test`.`gis_line`.`g`)) AS `AsText(StartPoint
SELECT fid, AsText(Centroid(g)) FROM gis_polygon ORDER by fid; SELECT fid, AsText(Centroid(g)) FROM gis_polygon ORDER by fid;
fid AsText(Centroid(g)) fid AsText(Centroid(g))
108 POINT(15 15) 108 POINT(15 15)
109 POINT(25.416666666667 25.416666666667) 109 POINT(25.4166666666667 25.4166666666667)
110 POINT(20 10) 110 POINT(20 10)
SELECT fid, Area(g) FROM gis_polygon ORDER by fid; SELECT fid, Area(g) FROM gis_polygon ORDER by fid;
fid Area(g) fid Area(g)
...@@ -325,8 +325,8 @@ fid IsClosed(g) ...@@ -325,8 +325,8 @@ fid IsClosed(g)
116 0 116 0
SELECT fid, AsText(Centroid(g)) FROM gis_multi_polygon ORDER by fid; SELECT fid, AsText(Centroid(g)) FROM gis_multi_polygon ORDER by fid;
fid AsText(Centroid(g)) fid AsText(Centroid(g))
117 POINT(55.588527753042 17.426536064114) 117 POINT(55.5885277530424 17.426536064114)
118 POINT(55.588527753042 17.426536064114) 118 POINT(55.5885277530424 17.426536064114)
119 POINT(2 2) 119 POINT(2 2)
SELECT fid, Area(g) FROM gis_multi_polygon ORDER by fid; SELECT fid, Area(g) FROM gis_multi_polygon ORDER by fid;
fid Area(g) fid Area(g)
......
...@@ -2790,26 +2790,26 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -2790,26 +2790,26 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
select max(key1) from t1 where key1 <= 0.6158; select max(key1) from t1 where key1 <= 0.6158;
max(key1) max(key1)
0.61580002307892 0.615800023078918
select max(key2) from t2 where key2 <= 1.6158; select max(key2) from t2 where key2 <= 1.6158;
max(key2) max(key2)
1.6158000230789 1.61580002307892
select min(key1) from t1 where key1 >= 0.3762; select min(key1) from t1 where key1 >= 0.3762;
min(key1) min(key1)
0.37619999051094 0.376199990510941
select min(key2) from t2 where key2 >= 1.3762; select min(key2) from t2 where key2 >= 1.3762;
min(key2) min(key2)
1.3761999607086 1.37619996070862
select max(key1), min(key2) from t1, t2 select max(key1), min(key2) from t1, t2
where key1 <= 0.6158 and key2 >= 1.3762; where key1 <= 0.6158 and key2 >= 1.3762;
max(key1) min(key2) max(key1) min(key2)
0.61580002307892 1.3761999607086 0.615800023078918 1.37619996070862
select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5; select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
max(key1) max(key1)
0.61580002307892 0.615800023078918
select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
min(key1) min(key1)
0.37619999051094 0.376199990510941
DROP TABLE t1,t2; DROP TABLE t1,t2;
create table t1(a bigint unsigned, b bigint); create table t1(a bigint unsigned, b bigint);
insert into t1 values (0xfffffffffffffffff, 0xfffffffffffffffff), insert into t1 values (0xfffffffffffffffff, 0xfffffffffffffffff),
......
...@@ -581,7 +581,7 @@ return 2.7182818284590452354| ...@@ -581,7 +581,7 @@ return 2.7182818284590452354|
set @e = e()| set @e = e()|
select e(), @e| select e(), @e|
e() @e e() @e
2.718281828459 2.718281828459 2.71828182845905 2.71828182845905
drop function if exists inc| drop function if exists inc|
create function inc(i int) returns int create function inc(i int) returns int
return i+1| return i+1|
...@@ -618,7 +618,7 @@ create function fun(d double, i int, u int unsigned) returns double ...@@ -618,7 +618,7 @@ create function fun(d double, i int, u int unsigned) returns double
return mul(inc(i), fac(u)) / e()| return mul(inc(i), fac(u)) / e()|
select fun(2.3, 3, 5)| select fun(2.3, 3, 5)|
fun(2.3, 3, 5) fun(2.3, 3, 5)
176.58213176229 176.582131762292
insert into t2 values (append("xxx", "yyy"), mul(4,3), e())| insert into t2 values (append("xxx", "yyy"), mul(4,3), e())|
insert into t2 values (append("a", "b"), mul(2,mul(3,4)), fun(1.7, 4, 6))| insert into t2 values (append("a", "b"), mul(2,mul(3,4)), fun(1.7, 4, 6))|
select * from t2 where s = append("a", "b")| select * from t2 where s = append("a", "b")|
...@@ -5972,9 +5972,9 @@ CREATE TABLE t3 (f1 INT, f2 FLOAT)| ...@@ -5972,9 +5972,9 @@ CREATE TABLE t3 (f1 INT, f2 FLOAT)|
INSERT INTO t3 VALUES (1, 3.4), (1, 2), (1, 0.9), (2, 8), (2, 7)| INSERT INTO t3 VALUES (1, 3.4), (1, 2), (1, 0.9), (2, 8), (2, 7)|
SELECT SUM(f2), bug25373(f1) FROM t3 GROUP BY bug25373(f1) WITH ROLLUP| SELECT SUM(f2), bug25373(f1) FROM t3 GROUP BY bug25373(f1) WITH ROLLUP|
SUM(f2) bug25373(f1) SUM(f2) bug25373(f1)
6.3000000715256 1 6.30000007152557 1
15 2 15 2
21.300000071526 NULL 21.3000000715256 NULL
DROP FUNCTION bug25373| DROP FUNCTION bug25373|
DROP TABLE t3| DROP TABLE t3|
DROP DATABASE IF EXISTS mysqltest1| DROP DATABASE IF EXISTS mysqltest1|
......
...@@ -385,12 +385,12 @@ Warning 1264 Out of range value adjusted for column 'f1' at row 1 ...@@ -385,12 +385,12 @@ Warning 1264 Out of range value adjusted for column 'f1' at row 1
Warning 1264 Out of range value adjusted for column 'f1' at row 2 Warning 1264 Out of range value adjusted for column 'f1' at row 2
select f1 + 0e0 from t1; select f1 + 0e0 from t1;
f1 + 0e0 f1 + 0e0
1.0000000150475e+29 1.00000001504747e+29
-1.0000000150475e+29 -1.00000001504747e+29
1.0000000150475e+30 1.00000001504747e+30
-1.0000000150475e+30 -1.00000001504747e+30
1.0000000150475e+30 1.00000001504747e+30
-1.0000000150475e+30 -1.00000001504747e+30
drop table t1; drop table t1;
create table t1(d double, u bigint unsigned); create table t1(d double, u bigint unsigned);
insert into t1(d) values (9.22337203685479e18), insert into t1(d) values (9.22337203685479e18),
...@@ -401,4 +401,9 @@ u ...@@ -401,4 +401,9 @@ u
9223372036854790144 9223372036854790144
18400000000000000000 18400000000000000000
drop table t1; drop table t1;
CREATE TABLE t1 (f1 DOUBLE);
INSERT INTO t1 VALUES(-1.79769313486231e+308);
SELECT f1 FROM t1;
f1
-1.79769313486231e+308
End of 5.0 tests End of 5.0 tests
...@@ -267,4 +267,12 @@ select u from t1; ...@@ -267,4 +267,12 @@ select u from t1;
drop table t1; drop table t1;
#
# Bug #21205: Different number of digits for float/doble/real in --ps-protocol
#
CREATE TABLE t1 (f1 DOUBLE);
INSERT INTO t1 VALUES(-1.79769313486231e+308);
SELECT f1 FROM t1;
--echo End of 5.0 tests --echo End of 5.0 tests
...@@ -125,7 +125,7 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs) ...@@ -125,7 +125,7 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs)
str_charset=cs; str_charset=cs;
if (decimals >= NOT_FIXED_DEC) if (decimals >= NOT_FIXED_DEC)
{ {
uint32 len= my_sprintf(buff,(buff, "%.14g",num));// Enough for a DATETIME uint32 len= my_sprintf(buff,(buff, "%.15g",num));// Enough for a DATETIME
return copy(buff, len, &my_charset_latin1, cs, &dummy_errors); return copy(buff, len, &my_charset_latin1, cs, &dummy_errors);
} }
#ifdef HAVE_FCONVERT #ifdef HAVE_FCONVERT
...@@ -677,7 +677,7 @@ void String::qs_append(const char *str, uint32 len) ...@@ -677,7 +677,7 @@ void String::qs_append(const char *str, uint32 len)
void String::qs_append(double d) void String::qs_append(double d)
{ {
char *buff = Ptr + str_length; char *buff = Ptr + str_length;
str_length+= my_sprintf(buff, (buff, "%.14g", d)); str_length+= my_sprintf(buff, (buff, "%.15g", d));
} }
void String::qs_append(double *d) void String::qs_append(double *d)
......
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