ccollins476ad commented on a change in pull request #882: libc: Add support for 
float in printf
URL: https://github.com/apache/mynewt-core/pull/882#discussion_r173255151
 
 

 ##########
 File path: libc/baselibc/src/tinyprintf.c
 ##########
 @@ -337,6 +339,38 @@ size_t tfp_format(FILE *putp, const char *fmt, va_list va)
                 written += putchw(putp, &p);
                 p.bf = bf;
                 break;
+            case 'f':
+                p.base = 10;
+                d = va_arg(va, double);
+                /* Cast to an int to get the integer part of the number */
+                n = (int)d;
+                /* Convert to ascii */
+                i2a(n, &p);
+                /* Ignore left align for integer part */
+                p.left = 0;
+                /* Subtract width for decimal part and decimal point */
+                if (p.width >= 4) {
+                    p.width -= 4;
+                } else {
+                    p.width = 0;
+                }
+                /* Write integer part to console */
+                written += putchw(putp, &p);
+                /* Take the decimal part and multiply by 1000 */
+                n = (d-n)*1000;
+                /* Convert to asii */
 
 Review comment:
   Minor typo: should be "ascii".

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to