Strange things in math.h under Intel OSX

"Max Persson" <[email protected]> Fri, 19 May 2006 13:06:31 +0200
Newsgroups gmane.os.opendarwin.general
Message-ID <[email protected]>
Hi there,

It seems like Apple may have done some mistakes in their port
of the standard c library (which I seriously doubt). I bumped in to
this problem when I compiled
some tests for OpenEXR (under Intel OS X on a MacBook Pro). It says
that a function from math.h is invalid. As you may know, there are two
versions of some of the stuff in the std-c library, one for ppc and
the other for i386. math.h is one of them. There is a macro/function
called isnan() that determines if a float is a number or not, and it
was here I bumped into the strange things. I opened up both versions
of math.h and compared the implementation of the isnan() macro...


Here is the one in the i386 math.h:

#define isnan(x)        \
       (       sizeof (x) =3D=3D sizeof(float )    ?       __isnanf(x)     =
\
       :       sizeof (x) =3D=3D sizeof(double)    ?       __isnand(x)     =
\

        :       __isnan (x))


And here is the one from the ppc math.h:

#define      isnan( x )         ( ( sizeof ( (x) ) =3D=3D sizeof(double) )
?           \
                             __isnand ( (double)(x) ) :
                 \
                               ( sizeof ( (x) ) =3D=3D sizeof( float) ) ?
          \
                             __isnanf ( (float)(x) ) :
                \
                             __isnan  ( ( long double )(x) ) )


The one that is used in my particular case is the first of them as I
am on a i386 OS X. What I have learnt, you always put surrounding
parenthesis in macros to prevent them from failing due to strange
input. That is NOT the case in the i386 math.h (along with a couple of
other macros there too).


The input argument in the call to the isnan() macro is in this case:

isnan(pf[y][x])


What I belive is happening here is that the macro gets very confused
with the array access here, because of the missing input parenthesis
in the macro. This is what I got from the compiler to further
strengthen the theory:

testTiledCompression.cpp:59: error: expected unqualified-id before 'sizeof'
testTiledCompression.cpp:59: error: expected `)' before 'sizeof'


But enough talking about this. I do not look for a quick fix here,
what I'm concerned about is that Apple may have delivered a faulty
math.h file for the Intel version of OS X. What do you think about it?


Kind regards,
Max Persson

MFX AB, Sweden
www.mfx.se