confused by liboctave/util/lo-ieee.cc

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

confused by liboctave/util/lo-ieee.cc

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


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: confused by liboctave/util/lo-ieee.cc

John W. Eaton
Administrator
On 06/16/2017 01:17 PM, Rik wrote:
> 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

I suppose not, if C++11 says they should exist.  The only case we should
have to worry about is if we need to replace one of these functions
because of some known bug, but that's a separate issue.

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

I guess we should just deprecate these functions now if isnan is a
standard function that we can expect to exist on all platforms that we
care about.

> Second, if the #if defined checks should remain, shouldn't they differ
> between float and double versions?

Yes, that's probably just an oversight.

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

I don't think we should.  Let's just use the std:: functions directly
now and eliminate our wrappers.

 > In
> the extracted code below, the case of doubles just uses std::isfinite, but
> the float version is more complicated.

I don't know why there was a difference.

jwe



Loading...