Bug #12860 Difference in zero padding of exponent between Unix and Windows
Submitted: 29 Aug 2005 19:01 Modified: 28 Apr 2010 1:52
Reporter: Kent Boortz Email Updates:
Status: Closed Impact on me:
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1, 5.0 OS:Windows (Windows)
Assigned to: Alexey Kopytov CPU Architecture:Any

[29 Aug 2005 19:01] Kent Boortz
Floating point values are output differently on Unix and Windows,
caused by a difference in padding of the exponent part. On Unix
the exponent is always two digits, padded with zero if needed, on
Windows tree digits padded with zeroes if needed.

While this is not that serious, it is the same value, this causes
inconsistency for tools used, one being the mysql-test test tool.
It uses a simplistic compare of the expected output and the actual
output, and this fails because of formatting differences.

How to repeat:
Run the mysql-test-run.pl script on Unix and Windows, using a test
case that outputs a float like

  create table t1 (c char(6));
  insert into t1 values (2e6),(2e-5);
  select * from t1;

that on Unix will output


but on Windows will give


Suggested fix:
Use the same output function on Unix and Windows, that use the
same padding. If any padding is to be used in the output at all.
[1 Sep 2005 1:33] Jim Winstead
the problem here is that *printf() functions in the vc library always use three digits for the exponent, but glibc (and other unix c library implementations) only use a third digit when necessary.

short of switching to our own *printf() implementation, i'm not sure how we can address this.
[8 Oct 2005 23:12] Kent Boortz
I found that I have an old unfinished patch, not sure if it
fully solves the problem or if it is good enough.

===== libmysql/libmysql.c 1.290 vs edited =====
--- 1.290/libmysql/libmysql.c   2005-02-22 14:08:06 +01:00
+++ edited/libmysql/libmysql.c  2005-10-09 00:29:54 +02:00
@@ -3587,6 +3587,17 @@
       sprintf(buff, "%-*.*g", (int) min(sizeof(buff)-1,
              min(14,width), value);
+#ifdef __WIN__
+      {
+        char *exp_p= strpbrk(buff+1, "+-"); /* Skip possibly initial +/- */
+        if (exp_p++ && *exp_p == '0')
+        {
+          /* VC++ sprintf() has minimum three digits exponent, Unix two */
+          *(exp_p++) = *(exp_p + 1);
+          *(exp_p++) = *(exp_p + 1);
+        }
+      }
       end= strcend(buff, ' ');
       *end= 0;
[7 Dec 2007 16:56] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:


ChangeSet@1.2521, 2007-12-07 19:56:17+03:00, kaa@polly.(none) +48 -0
  WL #2934 "Make/find library for doing float/double to string conversions
  and vice versa"
  Initial import of the dtoa.c code and custom wrappers around it to allow
  its usage from the server code.
  Conversion of FLOAT/DOUBLE values to DECIMAL ones or strings and vice
  versa has been significantly reworked. As the new algoritms are more
  precise than the older ones, results of such conversions may not always
  match those obtained from older server versions. This in turn may break
  compatibility for some applications.
  This patch also fixes the following bugs:
  - bug #12860 "Difference in zero padding of exponent between Unix and
  - bug #21497 "DOUBLE truncated to unusable value"
  - bug #26788 "mysqld (debug) aborts when inserting specific numbers into
  char fields"
  - bug #24541 "Data truncated..." on decimal type columns without any
  good reason"
[7 Dec 2007 23:08] Bugs System
Pushed into 6.0.5-alpha
[7 Dec 2007 23:10] Bugs System
Pushed into 5.1.23-rc
[7 Dec 2007 23:10] Bugs System
Pushed into 5.0.54
[8 Dec 2007 19:45] Alexey Kopytov
Fixed in 5.0/5.1 by the patch for bug #26788. Fixed in 6.0 by the patch for WL #2934.
[25 Jan 2008 12:40] Bugs System
Pushed into 6.0.5-alpha
[25 Jan 2008 19:56] Paul DuBois
Noted in 5.0.54, 5.1.23, 6.0.5 changelogs.

Zero-padding of exponent values was not the same across platforms.
[7 Jan 2010 16:32] Paul DuBois
Setting report to NDI pending push to Celosia.
[24 Feb 2010 20:28] Paul DuBois
Alexey, it might be in mysql-next-mr, but it isn't "pushed" until Celosia has been pushed to a release tree.
[24 Feb 2010 20:28] Paul DuBois
Setting report to Need Merge pending push of Celosia to release tree.
[6 Mar 2010 11:02] Bugs System
Pushed into 5.5.3-m3 (revid:alik@sun.com-20100306103849-hha31z2enhh7jwt3) (version source revid:vvaintroub@fedora12-20091225154921-x25a5pyw1pxiwobv) (merge vers: 5.5.99) (pib:16)
[6 Mar 2010 18:54] Paul DuBois
Noted in 5.5.3 changelog.
[27 Apr 2010 9:48] Bugs System
Pushed into 5.5.5-m3 (revid:alik@sun.com-20100427093804-a2k3rrjpwu5jegu8) (version source revid:alik@sun.com-20100427093804-a2k3rrjpwu5jegu8) (merge vers: 5.5.5-m3) (pib:16)
[27 Apr 2010 9:51] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100427094036-38frbg3famdlvjup) (version source revid:alik@sun.com-20100427093825-92wc8b22d4yg34ju) (pib:16)
[28 Apr 2010 1:52] Paul DuBois
Already fixed in 5.5.x.