msvcrt: _fcvt, _ecvt, and _gcvt always use scientific notation. _fcvt and _ecvt mistakenly add decimal point.

Stephen Moehle smoehle at comcast.net
Sat Oct 14 16:06:25 CDT 2006


I noticed that the Topo program (map viewing/printing from National 
Geographic, version 3.4.3) was displaying coordinates using scientific 
notation and was using two decimal points. So instead of displaying 
38.098 for the lattitude, I was seeing 3..8098e+01. I believe this also 
fixes  Bug 6413 in WineHQ Bugzilla.

From: Stephen Moehle <smoehle at comcast.net>

Changelog
msvcrt: _fcvt and _ecvt should used fixed point ('f' printf format) and 
not scientific notation ('e' format) and should not add a decimal point 
to the output. _gcvt should use the 'g' format to switch between fixed 
and scientific depending on the input number.

---
 dlls/msvcrt/math.c |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index f06166b..4406f67 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -860,10 +860,16 @@ char * CDECL _ecvt( double number, int n
     if (!data->efcvt_buffer)
         data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
 
-    snprintf(data->efcvt_buffer, 80, "%.*e", ndigits /* FIXME wrong */, 
number);
+    snprintf(data->efcvt_buffer, 80, "%.*f", ndigits /* FIXME wrong */, 
number);
     *sign = (number < 0);
     dec = strchr(data->efcvt_buffer, '.');
-    *decpt = (dec) ? dec - data->efcvt_buffer : -1;
+    if (dec) {
+        *decpt = dec - data->efcvt_buffer;
+        memmove(dec, dec + 1, strlen(dec));
+    }
+    else {
+        *decpt = -1;
+    }
     return data->efcvt_buffer;
 }
 
@@ -878,10 +884,16 @@ char * CDECL _fcvt( double number, int n
     if (!data->efcvt_buffer)
         data->efcvt_buffer = MSVCRT_malloc( 80 ); /* ought to be enough */
 
-    snprintf(data->efcvt_buffer, 80, "%.*e", ndigits, number);
+    snprintf(data->efcvt_buffer, 80, "%.*f", ndigits, number);
     *sign = (number < 0);
     dec = strchr(data->efcvt_buffer, '.');
-    *decpt = (dec) ? dec - data->efcvt_buffer : -1;
+    if (dec) {
+        *decpt = dec - data->efcvt_buffer;
+        memmove(dec, dec + 1, strlen(dec));
+    }
+    else {
+        *decpt = -1;
+    }
     return data->efcvt_buffer;
 }
 
@@ -892,7 +904,7 @@ char * CDECL _fcvt( double number, int n
  */
 char * CDECL _gcvt( double number, int ndigit, char *buff )
 {
-    sprintf(buff, "%.*E", ndigit, number);
+    sprintf(buff, "%.*g", ndigit, number);
     return buff;
 }
 
-- 
1.4.2.3




More information about the wine-patches mailing list