On 2011-08-30 08:33-0700 Dan Kegel wrote:

Today I discovered .. that the scanf family of functions was
introducing float (32-bit floating-point) noise into double (64-bit
floating-point) results.

I see it here, too:

$ sudo apt-get install mingw32
$ i586-mingw32msvc-gcc test_fscanf.c
$ echo "1.1e+01
1.1e+00
1.1e-01
1.1e-02
1.1e-03
1.1e-04" | ~/wine-git/wine a.exe
1.10000000000000000e+001
1.10000000000000009e+000
1.10000001639127737e-001
1.10000003278255491e-002
1.10000004917383261e-003
1.10000006556511075e-004

You can work around it with 'winetricks vcrun6', after which the test
program outputs:
1.10000000000000000e+001
1.10000000000000010e+000
1.10000000000000000e-001
1.09999999999999990e-002
1.10000000000000010e-003
1.10000000000000000e-004

So the problem is in wine's msvcrt.dll.

You could narrow it down further by printing out the raw byte strings
for the numbers
and then sprinking that printout through the path from when scanf is
called to where printf returns.
(Or, I suppose, step through it with a debugger instead.)

But the best place to report the bug is http://bugs.winehq.org

Hi Dan:

Thanks for these hints.  It was good to know of that workaround
involving downloading a Microsoft library to replace the one from wine
in case I needed it.  However, I prefer a direct fix if possible so I
looked further and finally found the code in question in the
_FUNCTION_ routine in wine-1.3.27/dlls/msvcrt/scanf.h.  Sure enough it
has an inappropriate float in it which appears to be the source of the trouble.

Therefore, I tried this patch:

--- scanf.h_original    2011-08-30 12:35:25.000000000 -0700
+++ scanf.h     2011-08-30 12:36:23.000000000 -0700
@@ -346,7 +346,7 @@
                    /* handle exponent */
                    if (width!=0 && (nch == 'e' || nch == 'E')) {
                        int exponent = 0, negexp = 0;
-                       float expcnt;
+                       double expcnt;
                         nch = _GETC_(file);
                        if (width>0) width--;
                        /* possible sign on the exponent */

rebuilt wine-1.3.27, and I now have this result:

bash.exe-3.1$ echo "1.1e+01
1.1e+00
1.1e-01
1.1e-02
1.1e-03
1.1e-04" | ./a.exe
 1.10000000000000000e+001
 1.10000000000000009e+000
 1.10000000000000001e-001
 1.10000000000000011e-002
 1.10000000000000028e-003
 1.10000000000000031e-004

Pretty good, if I do say so myself, for someone who has only a
superficial understanding of the scanf code!

I will follow up with a proper bug report at http://bugs.winehq.org so
this patch isn't lost.

But before I do that I am going to charge ahead with ephcom2 build and
tests to make sure this scanf function family fix for wine-1.3.27
works in that much more complicated case as well.

Best wishes, and thanks again for the hints.

Alan

__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


Reply via email to