Almost succesfull build on AIX

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Thu, 8 Jul 1999 10:24:15 +0200


>>>>> Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:

    PD> Thomas Vogels <tov@infiniti.ece.cmu.edu> writes:
    >> "Kurt" == Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> writes:

      > >> Here's the problem:
      > >>> 1/0
      > >> [1]INF
      > >>> is.finite(1/0)
      > >> [1] TRUE

    >> Much to my surprise, a 'printf ("%g", 1/.0)' prints INF in a C
    >> program.  Should this not result in a floating point exception?

    PD> Not according to IEEE specs (but integer divide by zero is
    PD> generally unmaskable). The interesting thing is that is.finite
    PD> returns TRUE on the result, and the printing also suggests that the
    PD> infinite value is not recognised internally (if it were, it would
    PD> get printed as
    >> 1/0
    PD> [1] Inf )

    PD> It would be nice to see the actual bit pattern of 1/.0. Could one
    PD> of you do something like

    PD>    x = 1/.0; printf("%0x,%0x\n", ((int *) &x)[0], ((int *) &x)[1]);

    PD> or whatever other obfuscation works on AIX...

I've done more than Peter requested;
namely, the "finite" probing has always been a big problem on AIX,
and I rediscovered my old testing code -- which I enhanced with Peter's HEX
dump proposal:
  [everything in  ftp://stat.ethz.ch/U/maechler/R/AIX-finite-tst.tar.gz !]

    #include <stdio.h>
    #include <math.h>

    #ifdef AIX
    # include <fp.h>
    #endif

    main() {
      double x,x2,x3;
      printf("finite(1.0)= %d (=1, hopefully)\n", finite(1.0));
      x=1./0.; x2= (-1.)/0.;  x3 = 0./0.;
      printf("Inf := 1/0 = %f;\t -Inf := -1/0 = %f;\t NaN:= 0/0 = %f\n",x, x2, x3);
      printf("finite(x), f.(x2), f.(x3): %d %d %d  (should all be 0)\n",
	     finite(x),finite(x2),finite(x3));
      printf("Now the `bits':\n");
      printf(" Inf : %0x,%0x\n", ((int *) &x )[0], ((int *) &x )[1]);
      printf("-Inf : %0x,%0x\n", ((int *) &x2)[0], ((int *) &x2)[1]);
      printf(" NaN : %0x,%0x\n", ((int *) &x3)[0], ((int *) &x3)[1]);

    #ifdef AIX
      printf("FINITE(x), f.(x2), f.(x3): %d %d %d  (should all be 0)\n",
	     FINITE(x),FINITE(x2),FINITE(x3));
    #endif
    }

------------
And I have this in my Makefile  [also available on Web, s.above]

    ## on AIX (percol)
    #CFLAGS = -D_XOPEN_SOURCE -DAIX
    # better for R (defines cosh(.)  AND fd_set(.) (sys/time.h):
    CFLAGS = -D_XOPEN_SOURCE_EXTENDED=1 -DAIX

My Conclusions: 

  - Only if I use these CFLAGS does  finite work properly.
  - The bit pattern are compiler-independent for +-Inf, but NOT for NaN :

Here is gcc [with above CFLAGS],  gcc version 2.7.2.3,  output:
----------------------------------
finite(1.0)= 1 (=1, hopefully)
Inf := 1/0 = INF;	 -Inf := -1/0 = -INF;	 NaN:= 0/0 = NaNQ
finite(x), f.(x2), f.(x3): 0 0 0  (should all be 0)
Now the `bits':
 Inf : 7ff00000,0
-Inf : fff00000,0
 NaN : 7fffffff,ffffffff
FINITE(x), f.(x2), f.(x3): 0 0 0  (should all be 0)
----------------------------------

xlc (the native AIX C compiler) gives the same BUT for the NaN bit pattern
where it has

 NaN : 7ff80000,0

------------------------

Martin Maechler <maechler@stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum SOL G1;	Sonneggstr.33
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1086			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._