From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.gentoo.org ([140.105.134.102] helo=robin.gentoo.org) by nuthatch.gentoo.org with esmtp (Exim 4.50) id 1EVWIV-0001kE-JA for garchives@archives.gentoo.org; Fri, 28 Oct 2005 15:37:40 +0000 Received: from robin.gentoo.org (localhost [127.0.0.1]) by robin.gentoo.org (8.13.5/8.13.5) with SMTP id j9SFavFF000781; Fri, 28 Oct 2005 15:36:57 GMT Received: from mail.gmx.net (pop.gmx.de [213.165.64.20]) by robin.gentoo.org (8.13.5/8.13.5) with SMTP id j9SFat06021613 for ; Fri, 28 Oct 2005 15:36:56 GMT Received: (qmail invoked by alias); 28 Oct 2005 15:36:54 -0000 Received: from d047019.adsl.hansenet.de (EHLO [192.168.2.189]) [80.171.47.19] by mail.gmx.net (mp021) with SMTP; 28 Oct 2005 17:36:54 +0200 X-Authenticated: #25576946 Message-ID: <43624657.4060301@gmx.net> Date: Fri, 28 Oct 2005 17:40:07 +0200 From: Marco Matthies User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051014) X-Accept-Language: en-us, en Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-science@gentoo.org Reply-to: gentoo-science@lists.gentoo.org MIME-Version: 1.0 To: gentoo-science@lists.gentoo.org Subject: Re: [gentoo-science] question about signbit References: <200510221416.03348.dd55@cornell.edu> <435AA97C.7020103@gmx.net> <200510270852.35524.dd55@cornell.edu> In-Reply-To: <200510270852.35524.dd55@cornell.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Archives-Salt: 312e2b9f-4432-4953-b5e4-994b25ada7ac X-Archives-Hash: 1f39bc74ba6909b22cd3b685afca13c1 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 #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@gentoo.org mailing list