Problems with printing double-values with printf and sprintf

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Sep 7 10:37:53 UTC 2009


Sebastian Huber wrote:
> The calculation in dtoa.c line 295 is wrong because the values for Exp_shift1
> and Exp_mask are invalid for the little endian ARM (this is only a good guess
> at the moment).  Exp_shift1 has the value 20 and should have the value 23.
> These values are defined in
> 
> ./newlib/libc/stdio/vfieeefp.h
> ./newlib/libc/stdlib/mprec.h
> 
> It looks like the __IEEE_LITTLE_ENDIAN is undefined.

My previous analysis is wrong.

The define __IEEE_LITTLE_ENDIAN is correctly defined.  The Exp_shift1 etc.
defines are correct.

It seems that GCC uses the legacy ARM FPA model for its software floating-point
implementation.  That means (excerpt from the corresponding ARM document):

Little-endian double-precision values are neither pure little-endian nor pure
big-endian.

This differs from that more recent VFP (Vectored Floatin-Point architecture).

In IEEE 754 we have the following double format:

least significant word (lsw): fraction [31:0]
moast significant word (msw): sign | exponent | fraction [51:32]

This will be stored in different ways:

                 VFP LE    VFP BE    FPA
lower address       lsw       msw    msw
higher address      msw       lsw    lsw

Thus we need to modify the word0() (returns msw) and word1() (returns lsw)
defines in mprec.h for ARM with FPA floating-point model:

#define word0(x) (x.i[0])
#define word1(x) (x.i[1])

-- 
Sebastian Huber, embedded brains GmbH

Address : Obere Lagerstr. 30, D-82178 Puchheim, Germany
Phone   : +49 89 18 90 80 79-6
Fax     : +49 89 18 90 80 79-9
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.



More information about the users mailing list