[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
confused by liboctave/util/lo-ieee.cc
From: |
Rik |
Subject: |
confused by liboctave/util/lo-ieee.cc |
Date: |
Fri, 16 Jun 2017 10:17:53 -0700 |
While working on other things I stumbled upon lo-ieee.cc and I have some
questions about the implementation.
First, now that C++11 is an Octave requirement, do we really need to check
for standard functions being in the cmath library? It seems like a hard
requirement that the corresponding C and C++ libraries implement what is in
C++11. Example code is
--- Code #1 ---
int
__lo_ieee_isnan (double x)
{
#if defined (HAVE_CMATH_ISNAN)
return std::isnan (x);
#else
// Gnulib provides.
return isnan (x);
#endif
}
--- End Code #1 ---
Second, if the #if defined checks should remain, shouldn't they differ
between float and double versions? In configure.ac the m4 test that
creates the HAVE_CMATH_XXX definitions is
--- Configure Code ---
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], [
--- End Configure Code ---
The code in lo-ieee.cc, however, is not using the definition with an 'F'
suffix. See the example for isnan below which maybe should be using
HAVE_CMATH_ISNANF.
--- Code #2 ---
int
__lo_ieee_float_isnan (float x)
{
#if defined (HAVE_CMATH_ISNAN)
return std::isnan (x);
#else
// Gnulib provides.
return isnan (x);
#endif
}
--- End Code #2 ---
Finally, if we're relying on the C++ std library which contains templated
versions of functions, why do we need to have special code for floats? In
the extracted code below, the case of doubles just uses std::isfinite, but
the float version is more complicated.
--- Code #3 ---
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_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
}
--- End Code #3 ---
--Rik
- confused by liboctave/util/lo-ieee.cc,
Rik <=