Gentoo Logo
Gentoo Spaceship




Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-science
Navigation:
Lists: gentoo-science: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: gentoo-science@g.o
From: Marco Matthies <marco-ml@...>
Subject: Re: question about signbit
Date: Fri, 28 Oct 2005 17:40:07 +0200
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;
}
-- 
gentoo-science@g.o mailing list


Replies:
Re: question about signbit
-- Darren Dale
References:
question about signbit
-- Darren Dale
Re: question about signbit
-- Marco Matthies
Re: question about signbit
-- Darren Dale
Navigation:
Lists: gentoo-science: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
Re: question about signbit
Next by thread:
Re: question about signbit
Previous by date:
Re: New scientific herd tester
Next by date:
Re: question about signbit


Updated Jun 17, 2009

Summary: Archive of the gentoo-science mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.