From bug-request at octave dot org Fri Dec 17 09:05:29 2004 Subject: Re: signbit on linux/gcc 3.2+ From: "John W. Eaton" To: Orion Poplawski Cc: bug at octave dot org Date: Fri, 17 Dec 2004 10:06:06 -0500 On 16-Dec-2004, Orion Poplawski wrote: | --- octave-2.1.64/configure.in.orig 2004-11-11 22:40:15.000000000 -0700 | +++ octave-2.1.64/configure.in 2004-12-16 16:34:16.209266151 -0700 | at @ -1153,6 +1153,7 @@ | ;; | *) | AC_CHECK_FUNCS(finite isnan isinf copysign signbit) | + AC_CHECK_DECLS(signbit,,,[#include ]) | ;; | esac This is OK, so I've included it. | --- octave-2.1.64/liboctave/lo-ieee.h.orig 2003-09-05 | 10:55:42.000000000 -0600 | +++ octave-2.1.64/liboctave/lo-ieee.h 2004-12-16 16:34:01.509814447 -0700 | at @ -24,6 +24,13 @@ | #define octave_liboctave_ieee_h 1 | | +/* Use c++ signbit */ | +#include | +/* GNUC puts it in std:: */ | +#ifdef __GNUC__ | +using std::signbit; | +#endif | + This won't work because lo-ieee.h is included by lo-cieee.c, which is not C++. Also, I'd rather not assume we know that GCC will always put signbit in the std namespace, since that seems like it could change (is it supposed to be in std?) in some future version and may not even be true for some older versions of GCC that are still used to compile Octave. I thought the following change would be good liboctave/ChangeLog: 2004-12-17 John W. Eaton * lo-cieee.c (lo_ieee_signbit): New function. * lo-ieee.h: Provide decl. Don't define lo_ieee_signbit as a macro here. From Orion Poplawski . Index: lo-cieee.c =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/lo-cieee.c,v retrieving revision 1.6 diff -u -r1.6 lo-cieee.c --- lo-cieee.c 5 Sep 2003 16:55:42 -0000 1.6 +++ lo-cieee.c 17 Dec 2004 14:56:56 -0000 at @ -153,6 +153,30 @@ return octave_NaN; } +#if ! (defined (signbit) || defined (HAVE_DECL_SIGNBIT)) && defined (HAVE_SIGNBIT) +extern int signbit (double); +#endif + +int +lo_ieee_signbit (double x) +{ +/* In the following definitions, only check x < 0 explicitly to avoid + a function call when it looks like signbit or copysign are actually + functions. */ + +#if defined (signbit) + return signbit (x); +#elif defined (HAVE_SIGNBIT) + return (x < 0 || signbit (x)); +#elif defined (copysign) + return (copysign (1.0, x) < 0); +#elif defined (HAVE_COPYSIGN) + return (x < 0 || copysign (1.0, x) < 0); +#else + return x < 0; +#endif +} + /* ;;; Local Variables: *** ;;; mode: C++ *** Index: lo-ieee.h =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/lo-ieee.h,v retrieving revision 1.13 diff -u -r1.13 lo-ieee.h --- lo-ieee.h 5 Sep 2003 16:55:42 -0000 1.13 +++ lo-ieee.h 17 Dec 2004 14:56:56 -0000 at @ -66,24 +66,7 @@ extern double lo_ieee_na_value (void); extern double lo_ieee_nan_value (void); -/* In the following definitions, only check x < 0 explicitly to avoid - a function call when it looks like signbit or copysign are actually - functions. */ - -#if defined (signbit) -#define lo_ieee_signbit(x) signbit (x) -#elif defined (HAVE_SIGNBIT) -#if defined (__MINGW32__) -extern int signbit (double); -#endif -#define lo_ieee_signbit(x) (x < 0 || signbit (x)) -#elif defined (copysign) -#define lo_ieee_signbit(x) (copysign (1.0, x) < 0) -#elif defined (HAVE_COPYSIGN) -#define lo_ieee_signbit(x) (x < 0 || copysign (1.0, x) < 0) -#else -#define lo_ieee_signbit(x) 0 -#endif +extern int lo_ieee_signbit (double); #ifdef __cplusplus } and it will work, but on my system (Debian, GCC 3.3.4) it will use the return (x < 0 || copysign (1.0, x) < 0); version, because signbit is only defined in math.h when the compiler is in C99 mode. Do we want to try to enable that (I'd guess not yet) or should we just check for __signbit in the configure script? jwe ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------