osdir.com
mailing list archive

Subject: signbit on linux/gcc 3.2+ - msg#00036

List: gnu.octave.bugs

Date: Prev Next Index Thread: Prev Next Index
On 16-Dec-2004, Orion Poplawski <orion@xxxxxxxxxxxxx> wrote:

| Octave uses the autoconf mechanism AC_CHECK_FUNCS() to look for signbit.
| This doesn't work for linux with gcc 3.2+ because signbit is a macro
| in <math.c>, and is only exposed if _GNU_SOURCE, _ISOC99_SOURCE,
| _ISOC9X_SOURCE, or __STDC_VERSION__ >= 199901L. To make things more
| complicated, in c++ if <cmath> is included, the macro is turned off and
| it is replaced with the std::signbit() function.

I didn't know there was a std::signbit function. If there was, then I
don't think we would need all the checks for signbit appearing in
various locations.

| In liboctave/lo-ieee.h, lo_ieee_signbit it declared as follows:
|
| /* 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
|
| So, you end up with lo_ieee_signbit(x) defined as 0. Which seems like a
| pretty bad thing, and it is not advertised as such (no error is generated).
|
| My proposed fix is as follows:
|
| - Change configure.in to check for the signbit *declaration*:
|
| --- configure.in.orig 2004-12-15 17:26:11.082647280 -0700
| +++ configure.in 2004-12-15 17:26:55.482848586 -0700
| @@ -1152,7 +1152,8 @@
| AC_DEFINE(HAVE_ISNAN, 1, [Define if you have isnan().])
| ;;
| *)
| - AC_CHECK_FUNCS(finite isnan isinf copysign signbit)
| + AC_CHECK_FUNCS(finite isnan isinf copysign)
| + AC_CHECK_DECLS(signbit,,,[#include <math.h>])
| ;;
| esac
| --- liboctave/lo-ieee.h.orig 2003-09-05 10:55:42.000000000 -0600
| +++ liboctave/lo-ieee.h 2004-12-16 11:29:10.697873801 -0700
| @@ -23,8 +23,14 @@
| #if !defined (octave_liboctave_ieee_h)
| #define octave_liboctave_ieee_h 1
|
| +#include <math.h>
| +
| #ifdef __cplusplus
| +/* Use standard c++ signbit */
| +#include <cmath>
| +using std::signbit;
| +

I would prefer to avoid including <math.h> in C++ code.

| @@ -82,7 +88,7 @@
| #elif defined (HAVE_COPYSIGN)
| #define lo_ieee_signbit(x) (x < 0 || copysign (1.0, x) < 0)
| #else
| -#define lo_ieee_signbit(x) 0
| +#error "No signbit definition?!"

It is probably bad to completely fail to compile if the system doesn't
have a signbit function/macro.

| Of course, all this probably breaks other platforms.

Yes, for example:

sun-45:9> cat foo.cc
#include <math.h>
#include <cmath>
using std::signbit;
#include <iostream>
int
main (void)
{
std::cerr << signbit (-1.0) << std::endl;

return 0;
}
sun-45:10> CC -V
CC: Sun C++ 5.6 2004/07/15
sun-45:11> CC foo.cc
"foo.cc", line 3: Error: signbit is not a member of std.
"foo.cc", line 8: Error: The function "signbit" must have a prototype.
2 Error(s) detected.

so I don't think I can accept this patch as it is.

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
-------------------------------------------------------------




Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

RE: Possible Error in -ascii save/restore

On 16-Dec-2004, I wrote: | Note the is.tellg() and is.seekg(). I think this is failing when the | filesystem is mounted in text mode because then there is some | translation going on for CRLF pairs. Is this a bug in Octave or the | way the Cygwin text mode filesystem works? All we want Octave to do | here is return to the previous location in the file and read again. Try the following program on a Cygwin filesystem mounted in textmode. When I compile this program with g++ 3.3.x, it prints line 1 line 2 pos = 18 line 3 ne 3 instead of the expected line 1 line 2 pos = 14 line 3 line 3 (or perhaps line 1 line 2 pos = 16 line 3 line 3 if the pointer is also counting the CR characters in the input). Will someone please verify this and report the problem as a bug to the Cygwin or libstdc++ maintainers (whichever is more appropriate, or both)? Thanks, jwe #include <iostream> #include <fstream> static void read_a_line (std::istream& is) { char c; while (is.get (c)) { std::cerr << c; if (c == '\n') break; } } int main (void) { std::ofstream ofoo ("foo.txt"); ofoo << "line 1\nline 2\nline 3\nline 4\n"; ofoo.close (); std::ifstream ifoo ("foo.txt"); // Read the first two lines, including the newlines, echoing them to // std::cerr. read_a_line (ifoo); read_a_line (ifoo); // Mark our position. std::streampos pos = ifoo.tellg (); // Where are we? I would expect 7 characters per line, so we should // be at 14. std::cerr << "pos = " << pos << std::endl; // Read and echo another line. read_a_line (ifoo); // Go back to the saved position then read and echo again. ifoo.seekg (pos); read_a_line (ifoo); ifoo.close (); return 0; } ------------------------------------------------------------- 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 -------------------------------------------------------------

Next Message by Date: click to view message preview

Re: signbit on linux/gcc 3.2+

John W. Eaton wrote: On 16-Dec-2004, Orion Poplawski <orion@xxxxxxxxxxxxx> wrote: | Octave uses the autoconf mechanism AC_CHECK_FUNCS() to look for signbit. | This doesn't work for linux with gcc 3.2+ because signbit is a macro | in <math.c>, and is only exposed if _GNU_SOURCE, _ISOC99_SOURCE, | _ISOC9X_SOURCE, or __STDC_VERSION__ >= 199901L. To make things more | complicated, in c++ if <cmath> is included, the macro is turned off and | it is replaced with the std::signbit() function. I didn't know there was a std::signbit function. If there was, then I don't think we would need all the checks for signbit appearing in various locations. Well, it's a GNUism: #if _GLIBCPP_USE_C99 #if !_GLIBCPP_USE_C99_FP_MACROS_DYNAMIC // These are possible macros imported from C99-land. For strict // conformance, remove possible C99-injected names from the global // namespace, and sequester them in the __gnu_cxx extension namespace. (which is then imported into std::) And with GNU <cmath> you are pretty much stuck with std::signbit because it undefines the signbit macro. -- Orion Poplawski System Administrator 303-415-9701 x222 Colorado Research Associates/NWRA FAX: 303-415-9702 3380 Mitchell Lane, Boulder CO 80301 http://www.co-ra.com ------------------------------------------------------------- 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 -------------------------------------------------------------

Previous Message by Thread: click to view message preview

signbit on linux/gcc 3.2+

Octave uses the autoconf mechanism AC_CHECK_FUNCS() to look for signbit. This doesn't work for linux with gcc 3.2+ because signbit is a macro in <math.c>, and is only exposed if _GNU_SOURCE, _ISOC99_SOURCE, _ISOC9X_SOURCE, or __STDC_VERSION__ >= 199901L. To make things more complicated, in c++ if <cmath> is included, the macro is turned off and it is replaced with the std::signbit() function. In liboctave/lo-ieee.h, lo_ieee_signbit it declared as follows: /* 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 So, you end up with lo_ieee_signbit(x) defined as 0. Which seems like a pretty bad thing, and it is not advertised as such (no error is generated). My proposed fix is as follows: - Change configure.in to check for the signbit *declaration*: --- configure.in.orig 2004-12-15 17:26:11.082647280 -0700 +++ configure.in 2004-12-15 17:26:55.482848586 -0700 @@ -1152,7 +1152,8 @@ AC_DEFINE(HAVE_ISNAN, 1, [Define if you have isnan().]) ;; *) - AC_CHECK_FUNCS(finite isnan isinf copysign signbit) + AC_CHECK_FUNCS(finite isnan isinf copysign) + AC_CHECK_DECLS(signbit,,,[#include <math.h>]) ;; esac --- liboctave/lo-ieee.h.orig 2003-09-05 10:55:42.000000000 -0600 +++ liboctave/lo-ieee.h 2004-12-16 11:29:10.697873801 -0700 @@ -23,8 +23,14 @@ #if !defined (octave_liboctave_ieee_h) #define octave_liboctave_ieee_h 1 +#include <math.h> + #ifdef __cplusplus +/* Use standard c++ signbit */ +#include <cmath> +using std::signbit; + extern "C" { #endif /* Octave's idea of infinity. */ @@ -72,7 +78,7 @@ #if defined (signbit) #define lo_ieee_signbit(x) signbit (x) -#elif defined (HAVE_SIGNBIT) +#elif defined (HAVE_DECL_SIGNBIT) #if defined (__MINGW32__) extern int signbit (double); #endif @@ -82,7 +88,7 @@ #elif defined (HAVE_COPYSIGN) #define lo_ieee_signbit(x) (x < 0 || copysign (1.0, x) < 0) #else -#define lo_ieee_signbit(x) 0 +#error "No signbit definition?!" #endif #ifdef __cplusplus - Somewhere someone would still need to define _GNU_SOURCE or _ISO_C99SOURCE or some such. Not sure how you want to handle this. I do it when I run configure, but it probably should be automatic. - This will flag an error rather than define lo_ieee_signbit(x) as zero. Of course, all this probably breaks other platforms. -- Orion Poplawski System Administrator 303-415-9701 x222 Colorado Research Associates/NWRA FAX: 303-415-9702 3380 Mitchell Lane, Boulder CO 80301 http://www.co-ra.com ------------------------------------------------------------- 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 -------------------------------------------------------------

Next Message by Thread: click to view message preview

Re: signbit on linux/gcc 3.2+

John W. Eaton wrote: On 16-Dec-2004, Orion Poplawski <orion@xxxxxxxxxxxxx> wrote: | Octave uses the autoconf mechanism AC_CHECK_FUNCS() to look for signbit. | This doesn't work for linux with gcc 3.2+ because signbit is a macro | in <math.c>, and is only exposed if _GNU_SOURCE, _ISOC99_SOURCE, | _ISOC9X_SOURCE, or __STDC_VERSION__ >= 199901L. To make things more | complicated, in c++ if <cmath> is included, the macro is turned off and | it is replaced with the std::signbit() function. I didn't know there was a std::signbit function. If there was, then I don't think we would need all the checks for signbit appearing in various locations. Well, it's a GNUism: #if _GLIBCPP_USE_C99 #if !_GLIBCPP_USE_C99_FP_MACROS_DYNAMIC // These are possible macros imported from C99-land. For strict // conformance, remove possible C99-injected names from the global // namespace, and sequester them in the __gnu_cxx extension namespace. (which is then imported into std::) And with GNU <cmath> you are pretty much stuck with std::signbit because it undefines the signbit macro. -- Orion Poplawski System Administrator 303-415-9701 x222 Colorado Research Associates/NWRA FAX: 303-415-9702 3380 Mitchell Lane, Boulder CO 80301 http://www.co-ra.com ------------------------------------------------------------- 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 -------------------------------------------------------------
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by