patch from GvG, it fixing the bug for calc = when it showing e-309, Bug 1195, it...
[reactos.git] / reactos / lib / crt / stdio / vfwprint.c
index 262b2d1..03b542a 100644 (file)
@@ -1,20 +1,6 @@
 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
 
-#ifdef __USE_W32API
-#undef __USE_W32API
-#endif
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <malloc.h>
-#include <internal/file.h>
-
-
-int _isnanl(double x);
-int _isinfl(double x);
-int _isnan(double x);
-int _isinf(double x);
-
+#include <precomp.h>
 
 int
 __vfwprintf(FILE *fp, const wchar_t *fmt0, va_list argp);
@@ -67,15 +53,9 @@ vfwprintf(FILE *f, const wchar_t *fmt, va_list ap)
  * Appropiated for the reactos kernel, March 1998 -- David Welch
  */
 
-#include <stdarg.h>
-
-#include <ctype.h>
-#include <string.h>
-#include <stdio.h>
 #include <math.h>
 #include <internal/ieee.h>
 
-
 #define ZEROPAD                1       /* pad with zero */
 #define SIGN           2       /* unsigned/signed long */
 #define PLUS           4       /* show plus */
@@ -229,16 +209,28 @@ static int numberf(FILE * f, double __n, wchar_t exp_sign,  int size, int precis
        } n;
 
        n.__n = &__n;
+    if ( exp_sign == L'g' || exp_sign == L'G' || exp_sign == L'e' || exp_sign == L'E' ) 
+    {
+        if ( 0 == n.n->mantissal && 0 == n.n->mantissah && 0 == n.n->exponent )
+        {
+            ie = 0;
+        }
+        else
+        {
+            ie = ((unsigned int)n.n->exponent - (unsigned int)0x3ff);
+        }
+
+        exponent = ie/3.321928;
+    }
 
-       if ( exp_sign == L'g' || exp_sign == L'G' || exp_sign == L'e' || exp_sign == L'E' ) {
-               ie = ((unsigned int)n.n->exponent - (unsigned int)0x3ff);
-               exponent = ie/3.321928;
-       }
 
        if ( exp_sign == L'g' || exp_sign == L'G' ) {
                type |= ZEROTRUNC;
                if ( exponent < -4 || fabs(exponent) >= precision )
                         exp_sign -= 2; // g -> e and G -> E
+               else
+                        exp_sign = 'f';
        }
 
        if ( exp_sign == L'e' ||  exp_sign == L'E' ) {
@@ -386,7 +378,11 @@ static int numberf(FILE * f, double __n, wchar_t exp_sign,  int size, int precis
                tmp = buf;
                if ( type & ZEROTRUNC && ((type & SPECIAL) != SPECIAL) ) {
                        j = 0;
-                       while ( j < i && ( *tmp == L'0' || *tmp == L'.' )) {
+                       while ( j < i && *tmp == L'0' ) {
+                                       tmp++;
+                                       i--;
+                       }
+                       if ( j < i && *tmp == L'.' ) {
                                        tmp++;
                                        i--;
                        }