Problems with printing double-values with printf and sprintf

Christian Mauderer Christian.Mauderer at embedded-brains.de
Mon Aug 17 14:17:18 UTC 2009


Ralf Corsepius wrote:
> On 08/17/2009 12:34 PM, Christian Mauderer wrote:
>
>> I'm using the newlib 1.17.0 with RTEMS 4.10 patches out of the
>> rtems-4.10-newlib-common-1.17.0-44.suse10.3 rpm.
>>
>> I'm using the following CFLAGS:
>> -mcpu=arm7tdmi-s -mstructure-size-boundary=8 -mapcs-frame -mthumb -Os -g
>
> Well, that's a lot of obscure flags, of which each may cause your
> problem.
>
> => We need to further isolate the problem.
>
> Can you try to build and excute something similar to this:
> printf( "%f\n", 1.2345 );
>
> while permuting the CFLAGS you are using, esp.
> -mcpu=arm7tdmi-s, -mapcs-frame and -mthumb?
>
> Ralf
I've build and executed a program which executes the following lines of
code:
  printf("Integer: %i, float: %f, string: %s\n", 12, 123.456, "test");
  printf("1.23 as .1f: %.1f\n", 1.23);
  printf("1.23 as 3.1f: %2.6f\n", 1.23);
  printf("0.05 as .1f: %.1f\n",0.05);
  printf("0.05 as .2f: %.2f\n",0.05);
  printf("0.05 as .3f: %.3f\n",0.05);
  printf("0.05 as e: %e\n",0.05);
  printf("0.05 as Lf: %Lf\n",(long double)0.05);

The system was NOT hanging like by the paranoia-test. It only generated
the following wrong results:
Integer: 12, float: 0.000000, string: test
1.23 as .1f:
802989250985742742207845819700380436420399389058479568434380621585033994529185836030072044434160138121917650611455316625745668022884355023417524394806249308798010496840832160
1.23 as 3.1f:
80298925098574274220784581970038043642039938905847956843438062158503399452918583603007204443416013812191765061145531662574566802288435502341752439480624930879801049684083210
0.05 as .1f: -0.0
0.05 as .2f: -0.00
0.05 as .3f: -0.000
0.05 as e: -0.000001e-187
0.05 as Lf: -0.000000

This was the same with and without the CFLAGS (-mcpu=arm7tdmi-s
-mstructure-size-boundary=8 -mapcs-frame -mthumb). Even the long number
(1.23 as .1f: 802989...) was the same. The long number will probably go
on, but my terminal-emulator was to small.

Kind regards,
Christian Mauderer

-- 
Christian Mauderer, embedded brains GmbH

Address : Obere Lagerstr. 30, D-82178 Puchheim, Germany
Phone   : +49 89 18 90 80 79-1
Fax     : +49 89 18 90 80 79-9
E-Mail  : christian.mauderer 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