www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2013/03/07/16:04:26

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
X-Recipient: djgpp-workers AT delorie DOT com
X-Authenticated: #27081556
X-Provags-ID: V01U2FsdGVkX1+MFiVjR5WMUgx6lhuvEB5OViPmn8fdfUcDWE2TUf
ObnxqusVVI10zb
Message-ID: <513900D2.6040106@gmx.de>
Date: Thu, 07 Mar 2013 22:04:18 +0100
From: Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121025 Thunderbird/16.0.2
MIME-Version: 1.0
To: Eli Zaretskii <eliz AT gnu DOT org>
CC: djgpp-workers AT delorie DOT com
Subject: Re: Printing sign of NaN.
References: <51364BCD DOT 1030807 AT gmx DOT de> <83y5e11pn7 DOT fsf AT gnu DOT org> <5137961A DOT 4000505 AT gmx DOT de> <83mwug1bnn DOT fsf AT gnu DOT org>
In-Reply-To: <83mwug1bnn.fsf@gnu.org>
X-Y-GMX-Trusted: 0
Reply-To: djgpp-workers AT delorie DOT com

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 -


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