Mail Archives: djgpp-workers/2013/03/11/12:24:25
According to Juan Manuel Guerrero:
[A lot of NaN discussion snipped.]
> I have run the code snippet below on linux and using djgpp.
> I think when the additions are passed as arguments to printf
> the "signed " NaN is read. Both give the same result like below:
>
> NaN + NaN = -nan NaN + NaN = -nan NaN + v = -nan
> NaN + NaN = +nan NaN + NaN = nan NaN + v = nan
First let me clearly state that I appreciate your work on DJGPP. It
seems that it's only you and Andris that have time to work on DJGPP
nowadays. Thank you!
Now over to the NaNs.
Just because Linux's libc does one thing, it's not automatically the
right/best/whatever way to do it.
While the sign of the NaN might help to diagnose what went wrong it's
not enough. Preferably _all_ the bits of the NaN should be presented.
IIRC, that is allowed, but it been a while since I was messing with
this. I thought I did it for DJGPP, but I can't see anything in the
code about that, or perhaps I'm looking at the wrong places. It can be
that I never finished it so I didn't send it. Or perhaps it was just
for my own debugging I was messing with NaNs.
Anyway, IIRC you are allowed to print "NaN(some representation of the
bits of the NaN)" when you print a NaN as long as your *scanf() accept
it as well.
So I suggest if you really want to make the printing of NaNs better do
that.
My plan was to just dump the bits of the whole floating point number
(just be make implementing it easy), something like (pseudocode)
print_double(double d) {
if( isnan(d) ) {
printf("NaN(0x%x)", (unsigned long long)d);
} else {
printf("%d", d);
}
}
scanf_double(char string, double *d_p) {
unsinged long long ull;
if( 1 == sscanf(string, "NaN(%llx)", &ull ) {
ull |= 0x<whatever bits that must be set to make a NaN>;
*d_p = *(double *)&ull;
} elsif( 1 == sscanf(string, "nan(%llx)", &ull ) {
/* Same as above. */
} elsif( X == sscanf(string, <more variations of NaN> ...) {
...
}
}
With that you can forget about the sign as you'll see that by looking
at the bit patterns. And it sure is much better than what you're
trying to copy from Linux's libc.
I just don't see the point of printing only the sign and not the other
interesting bits (the mantissa IIRC).
Of course I can be totally wrong. It's been many years since I was
looking at this.
And you're free to do whatever you like. In particular as _YOU_'re the
one doing any work on DJGPP's libc.
Thank you!
--
MartinS
- Raw text -