Simplify float code.
authorbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 16 Feb 2005 16:51:29 +0000 (16:51 +0000)
committerbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 16 Feb 2005 16:51:29 +0000 (16:51 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@366 38d2e660-2303-0410-9eaa-f027e97ec537

mware/formatwr.c

index 8f30f22b4e911e3fc5cbd532f3ed78a747b0417a..dc590b99fb89ba92151260cbb945a5bd02e63903 100755 (executable)
@@ -53,6 +53,9 @@
 
 /*#*
  *#* $Log$
+ *#* Revision 1.11  2005/02/16 16:51:29  bernie
+ *#* Simplify float code.
+ *#*
  *#* Revision 1.10  2004/10/26 09:01:35  bernie
  *#* Fix spacing.
  *#*
 #include <debug.h> /* ASSERT */
 
 #ifndef CONFIG_PRINTF_N_FORMATTER
-       /*! Enable arcane %n formatter */
+       /*! Disable the arcane %n formatter. */
        #define CONFIG_PRINTF_N_FORMATTER 0
 #endif
 
 #ifndef CONFIG_PRINTF_OCTAL_FORMATTER
-       /*! Enable %o formatter */
+       /*! Disable the %o formatter. */
        #define CONFIG_PRINTF_OCTAL_FORMATTER 0
 #endif
 
-// True if we must keep a count of the number of characters we print
+/* True if we must keep a count of the number of characters we print. */
 #define CONFIG_PRINTF_COUNT_CHARS (CONFIG_PRINTF_RETURN_COUNT || CONFIG_PRINTF_N_FORMATTER)
 
 #if CONFIG_PRINTF
 
 #if CONFIG_PRINTF > PRINTF_NOFLOAT
 /*bernie: save some memory, who cares about floats with lots of decimals? */
-/*#define FRMWRI_BUFSIZE 134*/
-       #error 134 is too much, the code must be fixed to have a lower precision limit
+       #define FRMWRI_BUFSIZE 134
+       #warning 134 is too much, the code must be fixed to have a lower precision limit
 #else
        /*
         * Conservative estimate. Should be (probably) 12 (which is the size necessary
        #define FRMWRI_BUFSIZE 16
 #endif
 
+/* Probably useful for fancy microcontrollers such as the PIC, nobody knows. */
 #ifndef MEM_ATTRIBUTE
 #define MEM_ATTRIBUTE
 #endif
@@ -691,16 +695,16 @@ FLOATING_CONVERSION:
                                {
                                        precision = 6;
                                }
+
                                if (sizeof(double) != sizeof(long double))
                                {
-                                       if ( (fvalue = flags.l_L_modifier ?
-                                                               va_arg(ap,long double) : va_arg(ap,double)) < 0)
-                                       {
-                                               flags.plus_space_flag = PSF_MINUS;
-                                               fvalue = -fvalue;
-                                       }
+                                       fvalue = flags.l_L_modifier ?
+                                               va_arg(ap,long double) : va_arg(ap,double);
                                }
-                               else if ( (fvalue = va_arg(ap,long double)) < 0)
+                               else
+                                       fvalue = va_arg(ap,long double);
+
+                               if (fvalue < 0)
                                {
                                        flags.plus_space_flag = PSF_MINUS;
                                        fvalue = -fvalue;
@@ -719,16 +723,6 @@ FLOATING_CONVERSION:
                                }
                                break;
 
-#else /* CONFIG_PRINTF <= PRINTF_NOFLOAT */
-                       case 'g':
-                       case 'G':
-                       case 'f':
-                       case 'e':
-                       case 'E':
-                               ptr = buf_pointer = bad_conversion;
-                               while (*ptr)
-                                       ptr++;
-                               break;
 #endif /* CONFIG_PRINTF <= PRINTF_NOFLOAT */
 
                        case '\0': /* Really bad place to find NUL in */
@@ -737,7 +731,7 @@ FLOATING_CONVERSION:
                        default:
                                /* Undefined conversion! */
                                ptr = buf_pointer = bad_conversion;
-                               ptr += 3;
+                               ptr += strlen(bad_conversion);
                                break;
 
                }