# HG changeset patch # User Matti Hamalainen # Date 1456756505 -7200 # Node ID 04a273cce4fad256ed0d477086fd11f7facc25bf # Parent 1d8ae82304ec80e4ef6a536d55b45fa8df4741bb Initial th_vprintf_put_float() stub. diff -r 1d8ae82304ec -r 04a273cce4fa th_string.c --- 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 *),