Mercurial > octave
changeset 23622:0abe8d85ecce
Use isnan, isinf, isfinite, signbit functions from C++ std lib.
These functions are guaranteed to be part of the std lib since
C++11 which is now a requirement of Octave.
* configure.ac: Remove OCTAVE_CHECK_FUNC_CMATH checks for isnan, isinf,
isfinite, signbit. Remove AC_CHECK_FUNCS tests for finite, isnan, isinf,
signbit, _finite, _isnan. Remove AC_CHECK_DECLS test for signbit.
* acinclude.m4 (OCTAVE_CHECK_FUNC_CMATH) : Remove unused macro.
* lo-mappers.cc (isnan, isfinite, isinf): Change functions to delegate to
std::FUNCTION of the same name rather than possibly calling lo_ieee_FUNCTION.
* lo-ieee.h: Add #include <cmath>.
* lo-ieee.h (__lo_ieee_isnan, __lo_ieee_finite, __lo_ieee_isinf,
__lo_ieee_signbit, __lo_ieee_float_isnan, __lo_ieee_float_finite,
__lo_ieee_float_isinf, __lo_ieee_float_signbit):
Change functions to delegate to std::FUNCTION of the same name.
* lo-ieee.cc (__lo_ieee_isnan, __lo_ieee_finite, __lo_ieee_isinf,
__lo_ieee_signbit, __lo_ieee_float_isnan, __lo_ieee_float_finite,
__lo_ieee_float_isinf, __lo_ieee_float_signbit):
Delete functions.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 16 Jun 2017 15:51:29 -0700 |
parents | cf24eb9758ac |
children | 4feed155a1f2 |
files | configure.ac liboctave/numeric/lo-mappers.cc liboctave/util/lo-ieee.cc liboctave/util/lo-ieee.h m4/acinclude.m4 |
diffstat | 5 files changed, 16 insertions(+), 223 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.ac Fri Jun 16 13:23:47 2017 -0700 +++ b/configure.ac Fri Jun 16 15:51:29 2017 -0700 @@ -2443,26 +2443,6 @@ ]) AC_LANG_POP(C++) -## Look in <cmath> for the IEEE functions isnan, isinf, isfinite that we need. - -OCTAVE_CHECK_FUNC_CMATH(isnan) -OCTAVE_CHECK_FUNC_CMATH(isinf) -OCTAVE_CHECK_FUNC_CMATH(isfinite) -OCTAVE_CHECK_FUNC_CMATH(signbit) - -## Check for Inf and NaN functions - -case $canonical_host_type in - m68k-hp-hpux*) - ## I am told that Inf and NaN don't work on m68k HP sytems. - ;; - *) - AC_CHECK_FUNCS([finite isnan isinf signbit]) - AC_CHECK_FUNCS([_finite _isnan]) - AC_CHECK_DECLS([signbit], , , [#include <math.h>]) - ;; -esac - ## Look in <complex> for C++ variants of math functions that we need. OCTAVE_CHECK_FUNC_COMPLEX(acos)
--- a/liboctave/numeric/lo-mappers.cc Fri Jun 16 13:23:47 2017 -0700 +++ b/liboctave/numeric/lo-mappers.cc Fri Jun 16 15:51:29 2017 -0700 @@ -334,65 +334,14 @@ return octave_frexpf_wrapper (x, expptr); } - bool - isnan (double x) - { -#if defined (HAVE_CMATH_ISNAN) - return std::isnan (x); -#else - return lo_ieee_isnan (x); -#endif - } - - bool - isnan (float x) - { -#if defined (HAVE_CMATH_ISNANF) - return std::isnan (x); -#else - return lo_ieee_isnan (x); -#endif - } - - bool - isfinite (double x) - { -#if defined (HAVE_CMATH_ISFINITE) - return std::isfinite (x); -#else - return lo_ieee_finite (x); -#endif - } + bool isnan (double x) { return std::isnan (x); } + bool isnan (float x) { return std::isnan (x); } - bool - isfinite (float x) - { -#if defined (HAVE_CMATH_ISFINITEF) - return std::isfinite (x); -#else - return lo_ieee_finite (x); -#endif - } + bool isfinite (double x) { return std::isfinite (x); } + bool isfinite (float x) { return std::isfinite (x); } - bool - isinf (double x) - { -#if defined (HAVE_CMATH_ISINF) - return std::isinf (x); -#else - return lo_ieee_isinf (x); -#endif - } - - bool - isinf (float x) - { -#if defined (HAVE_CMATH_ISINFF) - return std::isinf (x); -#else - return lo_ieee_isinf (x); -#endif - } + bool isinf (double x) { return std::isinf (x); } + bool isinf (float x) { return std::isinf (x); } // Sometimes you need a large integer, but not always.
--- a/liboctave/util/lo-ieee.cc Fri Jun 16 13:23:47 2017 -0700 +++ b/liboctave/util/lo-ieee.cc Fri Jun 16 15:51:29 2017 -0700 @@ -46,39 +46,6 @@ #include "mach-info.h" int -__lo_ieee_isnan (double x) -{ -#if defined (HAVE_CMATH_ISNAN) - return std::isnan (x); -#else - // Gnulib provides. - return isnan (x); -#endif -} - -int -__lo_ieee_finite (double x) -{ -#if defined (HAVE_CMATH_ISFINITE) - return std::isfinite (x); -#else - // Gnulib provides. - return finite (x); -#endif -} - -int -__lo_ieee_isinf (double x) -{ -#if defined (HAVE_CMATH_ISINF) - return std::isinf (x); -#else - // Gnulib provides. - return isinf (x); -#endif -} - -int __lo_ieee_is_NA (double x) { lo_ieee_double t; @@ -130,50 +97,6 @@ } int -__lo_ieee_signbit (double x) -{ -#if defined (HAVE_CMATH_SIGNBIT) - return std::signbit (x); -#else - // Gnulib provides. - return signbit (x); -#endif -} - -int -__lo_ieee_float_isnan (float x) -{ -#if defined (HAVE_CMATH_ISNAN) - return std::isnan (x); -#else - // Gnulib provides. - return isnan (x); -#endif -} - -int -__lo_ieee_float_finite (float x) -{ -#if defined (HAVE_CMATH_ISFINITE) - return std::isfinite (x) != 0 && ! __lo_ieee_float_isnan (x); -#else - // Gnulib provides. - return finite (x); -#endif -} - -int -__lo_ieee_float_isinf (float x) -{ -#if defined (HAVE_CMATH_ISINF) - return std::isinf (x); -#else - // Gnulib provides. - return isinf (x); -#endif -} - -int __lo_ieee_float_is_NA (float x) { lo_ieee_float t; @@ -205,17 +128,6 @@ return lo_float_nan; } -int -__lo_ieee_float_signbit (float x) -{ -#if defined (HAVE_CMATH_SIGNBIT) - return std::signbit (x); -#else - // Gnulib provides. - return signbit (x); -#endif -} - void octave_ieee_init (void) {
--- a/liboctave/util/lo-ieee.h Fri Jun 16 13:23:47 2017 -0700 +++ b/liboctave/util/lo-ieee.h Fri Jun 16 15:51:29 2017 -0700 @@ -23,6 +23,8 @@ #if ! defined (octave_lo_ieee_h) #define octave_lo_ieee_h 1 +#include <cmath> + #include "octave-config.h" #if defined (__cplusplus) @@ -70,9 +72,9 @@ extern OCTAVE_API void octave_ieee_init (void); -extern OCTAVE_API int __lo_ieee_isnan (double x); -extern OCTAVE_API int __lo_ieee_finite (double x); -extern OCTAVE_API int __lo_ieee_isinf (double x); +inline int __lo_ieee_isnan (double x) { return std::isnan (x); } +inline int __lo_ieee_finite (double x) { return std::isfinite (x); } +inline int __lo_ieee_isinf (double x) { return std::isinf (x); } extern OCTAVE_API int __lo_ieee_is_NA (double); extern OCTAVE_API int __lo_ieee_is_old_NA (double); @@ -82,11 +84,11 @@ extern OCTAVE_API double lo_ieee_na_value (void); extern OCTAVE_API double lo_ieee_nan_value (void); -extern OCTAVE_API int __lo_ieee_signbit (double); +inline int __lo_ieee_signbit (double x) { return std::signbit (x); } -extern OCTAVE_API int __lo_ieee_float_isnan (float x); -extern OCTAVE_API int __lo_ieee_float_finite (float x); -extern OCTAVE_API int __lo_ieee_float_isinf (float x); +inline int __lo_ieee_float_isnan (float x) { return std::isnan (x); } +inline int __lo_ieee_float_finite (float x) { return std::isfinite (x); } +inline int __lo_ieee_float_isinf (float x) { return std::isinf (x); } extern OCTAVE_API int __lo_ieee_float_is_NA (float); @@ -94,7 +96,7 @@ extern OCTAVE_API float lo_ieee_float_na_value (void); extern OCTAVE_API float lo_ieee_float_nan_value (void); -extern OCTAVE_API int __lo_ieee_float_signbit (float); +inline int __lo_ieee_float_signbit (float x) { return std::signbit (x); } #if defined (__cplusplus) }
--- a/m4/acinclude.m4 Fri Jun 16 13:23:47 2017 -0700 +++ b/m4/acinclude.m4 Fri Jun 16 15:51:29 2017 -0700 @@ -269,56 +269,6 @@ LIBS="$ac_octave_save_LIBS" ]) dnl -dnl Check whether a math mapper function is available in <cmath>. -dnl Will define HAVE_CMATH_FUNC if there is a double variant and -dnl HAVE_CMATH_FUNCF if there is a float variant. -dnl Currently capable of checking for functions with single -dnl argument and returning bool/int/real. -dnl -AC_DEFUN([OCTAVE_CHECK_FUNC_CMATH], [ - ac_safe=`echo "$1" | $SED 'y% ./+-:=%___p___%'` - - AC_CACHE_CHECK([for std::$1 in <cmath>], - [octave_cv_func_cmath_$ac_safe], - [AC_LANG_PUSH(C++) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #include <cmath> - void take_func (bool (*func) (double x)); - void take_func (int (*func) (double x)); - void take_func (double (*func) (double x)); - ]], [[ - take_func(std::$1); - ]])], - [eval "octave_cv_func_cmath_$ac_safe=yes"], - [eval "octave_cv_func_cmath_$ac_safe=no"]) - AC_LANG_POP(C++) - ]) - if eval "test \"`echo '$octave_cv_func_cmath_'$ac_safe`\" = yes"; then - AC_DEFINE(AS_TR_CPP([[HAVE_CMATH_][$1]]), 1, - [Define to 1 if <cmath> provides $1.]) - fi - - AC_CACHE_CHECK([for std::$1 (float variant) in <cmath>], - [octave_cv_func_cmath_f$ac_safe], - [AC_LANG_PUSH(C++) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #include <cmath> - void take_func (bool (*func) (float x)); - void take_func (int (*func) (float x)); - void take_func (float (*func) (float x)); - ]], [[ - take_func(std::$1); - ]])], - [eval "octave_cv_func_cmath_f$ac_safe=yes"], - [eval "octave_cv_func_cmath_f$ac_safe=no"]) - AC_LANG_POP(C++) - ]) - if eval "test \"`echo '$octave_cv_func_cmath_f'$ac_safe`\" = yes"; then - AC_DEFINE(AS_TR_CPP([[HAVE_CMATH_][$1][F]]), 1, - [Define to 1 if <cmath> provides float variant of $1.]) - fi -]) -dnl dnl Check whether a complex-valued function is available in <complex>. dnl Will define HAVE_COMPLEX_STD_FUNC if the function is available in the dnl std namespace and is callable on both std::complex<double> and