Mail Archives: djgpp/1997/06/09/21:08:36
Vic wrote:
>Philip Ibis wrote:
>> It might be due to the fact that I'm using v2.00, if so, then, oops.
>I'm using 2.01 .
>> Anyways... The following program gives my system a wedgie.
>On mine it crashes. Tracebacks attached to the mail.
>> ---- snip snip ---
>> #include <stdio.h>
>> #include <string.h>
>> int main(void)
>> {
>> double n;
>> memset(&n,0xFF,sizeof(double)); /* contrived, sure */
>> printf("%f\n",n);
>> }
>
I'd say it's a good guess that a double made of 0xFF's is not a valid
floating point number. I don't claim to be an 80x87 guru but I know you
can't just load any old garbage into a FPU register and expect it to work.
The reason it crases inside printf is that printf was the unlucky one who
had to do floating point stuff to it :) (Before it just hung around on the
stack.)
I can't see any reason why you'd want to have a double of 0xFF's. This is
why you convert to doubles with = and not memset(). Floating point numbers
are formatted all funny, with mantissas, exponents, and all that good stuff.
:) If you want the largest allowable double, you have MAXDOUBLE from
<values.h>. If you're *really* interested, you could read some IEEE
standards. (yeah, right.)
So, in answer to the problem, "don't do that, then." ;-)
--------------------
Nate Eldredge
eldredge AT ap DOT net
- Raw text -