www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/11/20/20:35:58

Date: Sun, 20 Nov 94 18:52:17 -0500
From: dj AT stealth DOT ctron DOT com (DJ Delorie)
To: dolan AT fnoc DOT navy DOT mil
Cc: davis AT amy DOT tch DOT harvard DOT edu, djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: printf or floating point error?????

>   printf( "1) i=%8.8XH, x=%8.8XH, y=%8.8XH, z=%8.8XH\n" , i , x , y , z );
> 
> /* 2) does it behave differently if we only put one variable at a time on
>    the stack? */
> 
>   printf( "2) i=%8.8XH, " , i );
>   printf( "x=%8.8XH, " , x );
>   printf( "y=%8.8XH, " , y );
>   printf( "z=%8.8XH\n" , z );

It will work better, but only by chance and only on some little-endian
machines.  What you're doing is inherently nonportable.

> /* 3) DJ says the floats stack as doubles; do they come off the stack that
>    way? */

Yes.  Printf (well, doprnt() in doprnt.c) pulls them off the stack as
doubles, because it knows about this ANSI rule.

> /* the "g" type claims to print everything, but really doesn't.
>    however, C type coercion does what C casts sometimes do, so this
>    gets out the readable values in another funny way. */

The "g" type prints anything that promotes to double when passed as a
parameter to a "..." spec.

> Well, the behavior is worse than merely stacking an extra four bytes
> per float, apparently a double also uses a different exponent
> structure, because the original double bit pattern is nowhere to be
> seen in the printed floats.

Yes.  Double format uses more bits for exponent AND mantissa.



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019