delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/06/29/03:22:12

Date: Fri, 29 Jun 2001 10:20:12 +0300
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
Sender: halo1 AT zahav DOT net DOT il
To: djgpp AT delorie DOT com
Message-Id: <6480-Fri29Jun2001102012+0300-eliz@is.elta.co.il>
X-Mailer: Emacs 20.6 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.9
In-reply-to: <3b3b4e40.213415946@news.primus.ca> (invalid@erehwon.invalid)
Subject: Re: DJGPP reserves wrong int size
References: <9dde68b7 DOT 0106241053 DOT 2a385311 AT posting DOT google DOT com> <200106242138 DOT RAA18013 AT envy DOT delorie DOT com> <3b37e92e DOT 288745911 AT news DOT primus DOT ca> <200106260242 DOT WAA00615 AT envy DOT delorie DOT com> <3b3b4e40 DOT 213415946 AT news DOT primus DOT ca>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> From: invalid AT erehwon DOT invalid (Graaagh the Mighty)
> Newsgroups: comp.os.msdos.djgpp
> Date: Thu, 28 Jun 2001 15:41:40 GMT
> 
> Long doubles seem to be broken in gcc 2.95.2 anyway

They work for me, in GCC 2.95.3.  (I didn't use 2.95.2 long enough to
tell.)

> -- at
> least, when I wrote the stuff I am working on it initially used long
> doubles, and gave bogus results; adding debugging printfs I discovered
> that some values were strangely becoming zeroes that shouldn't have
> been. It worked when I changed every occurrence of "long double" to
> "ldouble", then typedef'd that as "double". Change the typedef to
> "long double" and the zeros reappear.

This is usually a sign of a numeric bug in the code.

> (Actually, I tend to use
> "%1.16f" when debugging FP code, since the default "%f" gives only
> "float" precision output even when doubles and long doubles are
> passed. Clearly this should work fine with long doubles, except that
> even 16 digits of precision might not be enough for many cases.)

For long doubles, the right format for debugging printf's is "%.19g".
Note: "g", not "f", because you want 19 significant digits, not 19
digits after the dot (think about a number like 123456789.987654321).

For the same reason, I suggest to use "%.16g" for doubles.

> I am somewhat curious as to how printf
> knows the format of a double or for that matter int you pass it
> however.

It doesn't; it simply assumes that the format specifier tells the
truth.  That is, if you say "%f", the corresponding argument is a
double, and if you say "%Lf", it's a long double.

- Raw text -


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