Mail Archives: djgpp-workers/2013/03/07/16:04:26
Am 06.03.2013 22:06, schrieb Eli Zaretskii:
>> Date: Wed, 06 Mar 2013 20:16:42 +0100
>> From: Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
>> CC: Eli Zaretskii <eliz AT gnu DOT org>
>>
>> > Isn't NaN always negative? Do you succeed in printing both negative
>> > and positive NaN with this patch?
>>
>> Yes, I can print both signs with this change.
> And what about reading a signed NaN? Does it produce a value of that
> same sign when printed afterwards?
>
Sorry but I do not fully understand what exactly I shall test.
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
Regards,
Juan M. Guerrero
#include <stdio.h>
typedef struct {
unsigned mantissal:32;
unsigned mantissah:32;
unsigned exponent:15;
unsigned sign:1;
} long_double_t;
typedef union
{
long double ld;
long_double_t ldt;
} _longdouble_union_t;
int main(void)
{
long double v = 1.2345;
_longdouble_union_t nan;
nan.ldt.mantissal = 0x00000001U;
nan.ldt.mantissah = 0xC0000000U;
nan.ldt.exponent = 0x7FFFU;
nan.ldt.sign = 1;
printf("NaN + NaN = %+Lg NaN + NaN = %-Lg NaN + v = %Lg\n",
nan.ld + nan.ld, nan.ld + nan.ld, nan.ld + v);
nan.ldt.sign = 0;
printf("NaN + NaN = %+Lg NaN + NaN = %-Lg NaN + v = %Lg\n",
nan.ld + nan.ld, nan.ld + nan.ld, nan.ld + v);
return 0;
}
- Raw text -