Mercurial > hg > octave-lyh
changeset 11234:2718e1fdf82f
IEEE math initialization tweaks
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Nov 2010 21:52:51 -0500 |
parents | 1dfbcc9eee92 |
children | 9900d375e585 |
files | ChangeLog configure.ac liboctave/ChangeLog liboctave/lo-ieee.cc liboctave/lo-ieee.h src/ChangeLog src/octave.cc src/sysdep.cc |
diffstat | 8 files changed, 28 insertions(+), 82 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,10 @@ +2010-11-10 John W. Eaton <jwe@octave.org> + + * configure.ac: Don't check for nan.h. + 2010-11-10 John W. Eaton <jwe@octave.org> * configure.ac (AH_BOTTOM): Eliminate special case for __DECCXX: - (WARN_CXXFLAGS): 2010-11-10 John W. Eaton <jwe@octave.org>
--- a/configure.ac +++ b/configure.ac @@ -1526,11 +1526,10 @@ ### C headers -AC_CHECK_HEADERS(curses.h direct.h dlfcn.h \ - floatingpoint.h grp.h ieeefp.h inttypes.h locale.h memory.h nan.h \ - ncurses.h poll.h pthread.h pwd.h sunmath.h sys/ioctl.h \ - sys/param.h sys/poll.h sys/resource.h sys/select.h \ - sys/utsname.h termcap.h) +AC_CHECK_HEADERS(curses.h direct.h dlfcn.h floatingpoint.h grp.h \ + ieeefp.h inttypes.h locale.h memory.h ncurses.h poll.h pthread.h \ + pwd.h sunmath.h sys/ioctl.h sys/param.h sys/poll.h sys/resource.h \ + sys/select.h sys/utsname.h termcap.h) ### C++ headers
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,10 @@ +2010-11-10 John W. Eaton <jwe@octave.org> + + * lo-ieee.cc (octave_ieee_init): Don't initialize octave_Inf, + octave_NaN, and octave_NA to DBL_MAX. Don't initialize + octave_Float_Inf, octave_Float_NaN, and octave_Float_NA to FLT_MAX. + (octave_ieee_init): Simplify using std::numeric_limits template. + 2010-11-10 John W. Eaton <jwe@octave.org> * syswait.h: Delete special cases for NeXT systems.
--- a/liboctave/lo-ieee.cc +++ b/liboctave/lo-ieee.cc @@ -25,37 +25,17 @@ #include <config.h> #endif -#include <cfloat> #include <cstdlib> -#if defined (HAVE_FLOATINGPOINT_H) -#include <floatingpoint.h> -#endif - -#if defined (HAVE_IEEEFP_H) -#include <ieeefp.h> -#endif - -#if defined (HAVE_NAN_H) -#include <nan.h> -#endif +#include <limits> #include "lo-error.h" #include "lo-ieee.h" -#include "lo-math.h" #include "mach-info.h" void octave_ieee_init (void) { - // Default values. DBL_MAX is not right for NaN and NA, but do you - // have a better suggestion? If you don't have IEEE floating point - // values, there are many parts of Octave that will not work - // correctly. - - octave_Inf = octave_NaN = octave_NA = DBL_MAX; - octave_Float_Inf = octave_Float_NaN = octave_Float_NA = FLT_MAX; - oct_mach_info::float_format ff = oct_mach_info::native_float_format (); switch (ff) @@ -63,41 +43,13 @@ case oct_mach_info::flt_fmt_ieee_big_endian: case oct_mach_info::flt_fmt_ieee_little_endian: { - // Don't optimize away tmp_inf / tmp_inf to generate octave_NaN. - - volatile double tmp_inf; + octave_NaN = std::numeric_limits<double>::quiet_NaN (); + octave_Inf = std::numeric_limits<double>::infinity (); -#if defined (__alpha__) && defined (__osf__) - extern unsigned int DINFINITY[2]; - tmp_inf = (*(X_CAST(double *, DINFINITY))); -#else - double tmp = 1e+10; - tmp_inf = tmp; - for (;;) - { - tmp_inf *= 1e+10; - if (tmp_inf == tmp) - break; - tmp = tmp_inf; - } -#endif + octave_Float_NaN = std::numeric_limits<float>::quiet_NaN (); + octave_Float_Inf = std::numeric_limits<float>::infinity (); -#if defined (__alpha__) && defined (__osf__) - extern unsigned int DQNAN[2]; - octave_NaN = (*(X_CAST(double *, DQNAN))); -#elif defined (__NetBSD__) - octave_NaN = nan (""); -#else - octave_NaN = tmp_inf / tmp_inf; - // try to ensure that lo_ieee_sign gives false for a NaN. - if (lo_ieee_signbit (octave_NaN)) - octave_NaN = -octave_NaN; - -#endif - - octave_Inf = tmp_inf; - - // This is patterned after code in R. + // The following is patterned after code in R. if (ff == oct_mach_info::flt_fmt_ieee_big_endian) { @@ -116,25 +68,6 @@ octave_NA = t.value; - volatile float float_tmp_inf; - - float float_tmp = 1e+10; - float_tmp_inf = float_tmp; - for (;;) - { - float_tmp_inf *= 1e+10; - if (float_tmp_inf == float_tmp) - break; - float_tmp = float_tmp_inf; - } - -#if defined (__NetBSD__) - octave_Float_NaN = nanf (""); -#else - octave_Float_NaN = float_tmp_inf / float_tmp_inf; -#endif - octave_Float_Inf = float_tmp_inf; - lo_ieee_float tf; tf.word = LO_IEEE_NA_FLOAT; octave_Float_NA = tf.value;
--- a/liboctave/lo-ieee.h +++ b/liboctave/lo-ieee.h @@ -70,7 +70,6 @@ #define LO_IEEE_NA_LW 0x40000000 #define LO_IEEE_NA_FLOAT 0x7FC207A2 - extern OCTAVE_API void octave_ieee_init (void); extern OCTAVE_API int __lo_ieee_isnan (double x);
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-11-10 John W. Eaton <jwe@octave.org> + + * octave.cc (octave_main): Call octave_ieee_init here. + * sysdep.cc (sysdep_init): Not here. + 2010-11-10 John W. Eaton <jwe@octave.org> * sysdep.cc: Eliminate special case for __DECCXX.
--- a/src/octave.cc +++ b/src/octave.cc @@ -604,6 +604,8 @@ sysdep_init (); + octave_ieee_init (); + // The idea here is to force xerbla to be referenced so that we will // link to our own version instead of the one provided by the BLAS // library. But octave_NaN should never be -1, so we should never