diff options
author | unknown <kaa@polly.(none)> | 2007-12-02 13:49:12 +0300 |
---|---|---|
committer | unknown <kaa@polly.(none)> | 2007-12-02 13:49:12 +0300 |
commit | 5fd87abaa81c80cbcc4526bf6424e7ae24362fbd (patch) | |
tree | 237bd06c1a04bd89fe2a1bb442674da48f89eb64 | |
parent | 1f22720c3f6bf28a44ee0e3a9a9abd52e9debe64 (diff) | |
download | mariadb-git-5fd87abaa81c80cbcc4526bf6424e7ae24362fbd.tar.gz |
Windows-specific fixes in floating point tests.
mysql-test/t/insert.test:
Windows implements a different rounding rules in printf("%g"), thus we still need to do replace_result
mysql-test/t/variables.test:
We need to do replace_result because variables are printed by another procedure.
sql/field.cc:
Fixed the code to limit the precision to DBL_DIG.
-rw-r--r-- | mysql-test/t/insert.test | 3 | ||||
-rw-r--r-- | mysql-test/t/variables.test | 2 | ||||
-rw-r--r-- | sql/field.cc | 5 |
3 files changed, 9 insertions, 1 deletions
diff --git a/mysql-test/t/insert.test b/mysql-test/t/insert.test index 3c150d0c3f6..5cb85d32383 100644 --- a/mysql-test/t/insert.test +++ b/mysql-test/t/insert.test @@ -423,6 +423,9 @@ INSERT INTO t1(a,c) VALUES (-1.87e-2, -1.87e-2); INSERT INTO t1(a,c) VALUES (5000e+0, 5000e+0); INSERT INTO t1(a,c) VALUES (-5000e+0, -5000e+0); +# Expected results are "12.2" and "1.2e+78", but Windows returns "12.3" and +# "1.3e+78" due to different rounding rules +--replace_result 12.3 12.2 1.3e+78 1.2e+78 SELECT * FROM t1; DROP TABLE t1; diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index 4b78ea6c026..0ad85a32568 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -51,6 +51,8 @@ select @test, @`test`, @TEST, @`TEST`, @"teSt"; set @select=2,@t5=1.23456; select @`select`,@not_used; set @test_int=10,@test_double=1e-10,@test_string="abcdeghi",@test_string2="abcdefghij",@select=NULL; +# Expected result "1e-10", windows returns "1e-010" +--replace_result 1e-010 1e-10 select @test_int,@test_double,@test_string,@test_string2,@select; set @test_int="hello",@test_double="hello",@test_string="hello",@test_string2="hello"; select @test_int,@test_double,@test_string,@test_string2; diff --git a/sql/field.cc b/sql/field.cc index a9aca5dc6e0..31d2af1bb14 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5953,8 +5953,11 @@ int Field_str::store(double nr) */ if (exp >= (int) digits || exp < -4) digits= max(0, (int) (max_length - 5 - (exp >= 100 || exp <= -100))); + + /* Limit precision to DBL_DIG to avoid garbage past significant digits */ + set_if_smaller(digits, DBL_DIG); - length= (uint) my_sprintf(buff, (buff, "%-.*g", min(digits, DBL_DIG ), nr)); + length= (uint) my_sprintf(buff, (buff, "%-.*g", digits, nr)); #ifdef __WIN__ /* |