changeset 375:04a273cce4fa

Initial th_vprintf_put_float() stub.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 29 Feb 2016 16:35:05 +0200
parents 1d8ae82304ec
children ff8a991fdb2d
files th_string.c
diffstat 1 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/th_string.c	Mon Feb 29 16:12:10 2016 +0200
+++ b/th_string.c	Mon Feb 29 16:35:05 2016 +0200
@@ -280,6 +280,26 @@
 }
 
 
+static int th_vprintf_put_float(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
+    va_list ap, int f_flags, int f_width, int f_prec)
+{
+    double pval = va_arg(ap, double);   // This needs to be double for type promotion to occur
+    int64_t val;
+
+    // This is a hack, trying to avoid dereferencing a type-punned
+    // pointer and all that stuff related to strict aliasing (although
+    // double and int64_t should be same size and have same aliasing rules.)
+    memcpy(&val, &pval, sizeof(int64_t));
+
+    // We have sign, exponent and mantissa
+    BOOL f_sign    = (val >> 63) & 0x01;
+    int64_t d_exp  = (val >> 52) & 0x7ff;
+    uint64_t d_man = val & 0x0fffffffffffff;
+
+    return 0;
+}
+
+
 static char * th_printf_altfmt_oct(const int flags)
 {
     (void) flags;
@@ -436,13 +456,10 @@
 
                 case 'f':
                 case 'F':
-                    return -112;
-/*
                     if ((ret = th_vprintf_put_float(ctx, vputch, ap,
                         f_flags, f_width, f_prec)) == EOF)
                         goto out;
                     break;
-*/
 
                 case 's':
                     if ((ret = th_vprintf_put_str(ctx, vputch, va_arg(ap, char *),