Darren Dale wrote:
signbit(-1): -2147483648
isnan(0.0/0): 1
isinf(1.0/0): 1
As other people have already noted, signbit from math.h is behaving as
it should.
Do you know why signbit doesn't yield 1? I wonder if this might be the source
of the problem in Scipy.
I actually had a look at scipy today, and it uses its own signbit
routine -- so looking at what signbit from math.h does is totally
irrelevant. The scipy signbit implementation does say it returns 0 or 1.
I extracted the routine from Lib/special/cephes/isnan.c and constructed
a little test program attached to the mail. On my machine it works as
advertised when defining IBMPC. You can try out the defines for other
machine types. On my machine, using DEC also works -- but using MIEEE or
leaving all undefined gives the results you're seeing, namely all
numbers are reported to have sign 0. So it may be that your machine type
was not #defined correctly. Probably Lib/special/cephes/isnan.c should
have something like:
#if !defined(IBMPC) && !defined(DEC) && !defined(MIEEE)
#error "machine type not defined"
#endif
in front of it to guard against the machine type being undefined (or
perhaps this should go in the .h file of 'cephes'). You can try adding
this to Lib/special/cephes/isnan.c and see if you still can compile or
if it spits out an error.
Cheers,
Marco
Here's the test program with scipy's signbit function:
#include <stdio.h>
#define IBMPC 1
//#define DEC 1
//#define MIEEE 1
int signbit(x)
double x;
{
union
{
double d;
short s[4];
int i[2];
} u;
u.d = x;
if( sizeof(int) == 4 )
{
#ifdef IBMPC
return( u.i[1] < 0 );
#endif
#ifdef DEC
return( u.s[3] < 0 );
#endif
#ifdef MIEEE
return( u.i[0] < 0 );
#endif
}
else
{
#ifdef IBMPC
return( u.s[3] < 0 );
#endif
#ifdef DEC
return( u.s[3] < 0 );
#endif
#ifdef MIEEE
return( u.s[0] < 0 );
#endif
}
}
int main() {
printf("signbit( 1.0) = %d\n", signbit(1.0));
printf("signbit(-1.0) = %d\n", signbit(-1.0));
printf("signbit( 0.0) = %d\n", signbit(0.0));
printf("signbit(-0.0) = %d\n", signbit(-0.0));
return 0;
}
--
[email protected] mailing list