Mail Archives: djgpp/2001/06/28/15:49:37
On Mon, 25 Jun 2001 22:42:11 -0400, DJ Delorie <dj AT delorie DOT com> sat on
a tribble, which squeaked:
>And long doubles should be 16-byte aligned (128 bits)...
I mentioned regular doubles in the earlier posting, rather than long
doubles. Long doubles seem to be broken in gcc 2.95.2 anyway -- 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. I thought at first that maybe I
needed a special formatting symbol to use them properly in printf, but
a libc info a printf soon set me straight -- a short way down the page
it said "'f' -- a floating point number (double or long double)"
indicating that "%f" should work either way. (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.)
Besides, there was the bogus output from the program with long doubles
even without the printfs. The numbers weren't just being read out
bogusly, they were already bogus to begin with... As for where they
came from, they came from passing literals to functions or using them
in assignments -- I hadn't yet written any input code, for testing I
just changed constants and recompiled. In particular, they weren't
coming from scanf, which I know does care more about the size of its
targets, since it will necessarily blow up if you pass it addresses of
spaces of the wrong size... I am somewhat curious as to how printf
knows the format of a double or for that matter int you pass it
however. It might be different bit lengths, and it's a varargs
function, but the above suggests that once it's told it's looking for
a float as opposed to, say, an int, it can tell a double from a long
double...
--
Bill Gates: "No computer will ever need more than 640K of RAM." -- 1980
"There's nobody getting rich writing software that I know of." -- 1980
"This antitrust thing will blow over." -- 1998
Combine neo, an underscore, and one thousand sixty-one to make my hotmail addy.
- Raw text -