From p.dalgaard@biostat.ku.dk  Tue Jul 20 10:50:01 1999
From: p.dalgaard@biostat.ku.dk (Peter Dalgaard BSA)
Date: 20 Jul 1999 11:50:01 +0200
Subject: 0.65/AIX
In-Reply-To: Thomas Vogels's message of "Mon, 19 Jul 1999 21:23:09 -0400"
References: <199907200123.VAA23498@infiniti.ece.cmu.edu>
Message-ID: <x2r9m3fy5y.fsf@blueberry.kubism.ku.dk>

Thomas Vogels <tov@infiniti.ece.cmu.edu> writes:

> "Peter" == Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:
> 
> Peter> Something pretty close to the following should work:
> Peter> 
> Peter> #define R_FINITE(x) ({double y = x; \
> Peter> *((int *) &y) & 0x7ff00000 != 0x7ff00000})
> Peter> 
> Peter> #define ISNAN(x) ({double y = x; \
> Peter> *((int *) &y) & 0x7ff00000 == 0x7ff00000 && \
> Peter> (*((int *) &y) & 0x7fffffff != 0x7ff00000 || *((int *) &y + 1) != 0)}
> 
> Pretty but not close ;-)  Sorry, but I can't compile these macros.  I
> see your point for the local var, but cc and gcc choke on it.

I take it that you fixed the missing ')' in ISNAN? Too bad. Perhaps it
can work without the local "y"? I put it in just to catch cases where
x might be in a register so that you cannot take its address.

> I've looked into /usr/include/fp.h which is included for AIX
> platforms.  (Its version is 1.9)  There are defines for FINITE,
> IS_INF, IS_NAN.  Can we use them?  Roll our own finite()?

That would make very good sense. The code would probably have to go in
an "#if aix" type clause, but so would my suggestion.

> Does it make sense for configure to check, not only whether finite
> exists but also whether it's broken?

It certainly would.
 
> BTW, if you step thru EncodeReal you see that !R_FINITE(x) if false
> for 1/0 (i.e. 1/0 is not detected as not finite).

Yes. If you look at R_FINITE, you'll see that the logic is
essentially: If HAVE_FINITE use finite() else assume non-IEEE and only
check for the internal NA code. So if either finite() misbehaves or
doesn't exist, that will happen.

> Here is first the C code to show what's working what's not.  (I picked
> your stuff and added the calls to the macros.)  This is followed by
> the output when compiled with cc and gcc.  I'm having major headaches
> here with the -D_XOPEN_SOURCE_EXTENDED (details follow).  Maybe we can
> dump finite in favor of FINITE?
> 
> Are  my assumptions about the return values are correct?

They look fine. Would seem that only gcc without the -D_XOPENetc is
having trouble with finite() -- why? could that be a gcc bug?

What happens with isnan(), is that as buggy as finite()?

It looks quite feasible simply to put

#ifdef _AIX
	#define R_FINITE(x) FINITE(X)
	#define R_ISNAN(x)  IS_NAN(X)
#endif

or something like it in Arith.h
-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


0.65/AIX
Peter Dalgaard BSA