msvcrt: Calculate floating point decimals in internally used long double precision.

Gregor Schneider grschneider at gmail.com
Mon Nov 23 14:43:31 CST 2009


This patch proposes to calculate the fp digits in scanf with the internally
used long double precision instead of simple float accuracy.
With the current implementation small errors are added with each calculation
step originating from the used float type.
This becomes obvious when parsing to more precise fp types like double or
long double and outputting a large number of digits from the created number.
Example code like the following

double d;
swscanf(L"3.1415", L"%lf", &d);
wprintf(L"%3.12f\n", d);

produces an output of "3.141500000478", while "3.141500000000" would be the
expected result with this precision. The attached patch fixes this problem.


Best regards,

Gregor Schneider
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20091123/b823a0cb/attachment.htm>
-------------- next part --------------
From 17d5dbfbd7e58e1046a2bb0302a516493e8d9e56 Mon Sep 17 00:00:00 2001
From: Gregor Schneider <grschneider at gmail.com>
Date: Mon, 23 Nov 2009 21:09:02 +0100
Subject: [PATCH] msvcrt: Calculate floating point decimals in internally used long double precision.

---
 dlls/msvcrt/scanf.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/dlls/msvcrt/scanf.h b/dlls/msvcrt/scanf.h
index 3eb705b..3b17f1f 100644
--- a/dlls/msvcrt/scanf.h
+++ b/dlls/msvcrt/scanf.h
@@ -266,7 +266,7 @@ _FUNCTION_ {
 		    }
 		    /* handle decimals */
                     if (width!=0 && nch == '.') {
-                        float dec = 1;
+                        long double dec = 1.0L;
                         nch = _GETC_(file);
 			if (width>0) width--;
                         while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) {
-- 
1.6.5.1.1367.gcd48


More information about the wine-patches mailing list