Mercurial > octave
changeset 22079:e0dbd81fd9b1
provide wrapper for frexp and frexpf (bug #48363)
* bootstrap.conf (gnulib_modules): Add modules frexp and frexpf.
* liboctave/wrappers/math-wrappers.c, liboctave/wrappers/math-wrappers.h:
New files.
* liboctave/wrappers/module.mk: Add math-wrappers.{c,h}.
* lo-mappers.cc, lo-mappers.h (octave::math::frexp): New functions.
(octave::math::log2): Use them instead of std::frexp.
* data.cc (Feps): Use octave::math::frexp instead of std::frexp.
* oct-inttypes.cc (dblesplit): Likewise.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Sun, 03 Jul 2016 09:54:43 -0700 |
parents | ce69151a2d1b |
children | 43646269998d |
files | bootstrap.conf libinterp/corefcn/data.cc liboctave/numeric/lo-mappers.cc liboctave/numeric/lo-mappers.h liboctave/util/oct-inttypes.cc liboctave/wrappers/math-wrappers.c liboctave/wrappers/math-wrappers.h liboctave/wrappers/module.mk |
diffstat | 8 files changed, 109 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/bootstrap.conf Fri Jul 08 14:05:44 2016 -0400 +++ b/bootstrap.conf Sun Jul 03 09:54:43 2016 -0700 @@ -36,6 +36,8 @@ filemode fnmatch fpucw + frexp + frexpf fseek ftell ftruncate
--- a/libinterp/corefcn/data.cc Fri Jul 08 14:05:44 2016 -0400 +++ b/libinterp/corefcn/data.cc Sun Jul 03 09:54:43 2016 -0700 @@ -4538,7 +4538,7 @@ else { int expon; - std::frexp (val, &expon); + octave::math::frexp (val, &expon); epsval(i) = std::pow (2.0f, static_cast<float> (expon - 24)); } @@ -4562,7 +4562,7 @@ else { int expon; - std::frexp (val, &expon); + octave::math::frexp (val, &expon); epsval(i) = std::pow (2.0, static_cast<double> (expon - 53)); }
--- a/liboctave/numeric/lo-mappers.cc Fri Jul 08 14:05:44 2016 -0400 +++ b/liboctave/numeric/lo-mappers.cc Sun Jul 03 09:54:43 2016 -0700 @@ -33,6 +33,7 @@ #include "lo-math.h" #include "lo-specfun.h" #include "lo-utils.h" +#include "math-wrappers.h" #include "oct-cmplx.h" #include "f77-fcn.h" @@ -257,13 +258,13 @@ double log2 (double x, int& exp) { - return std::frexp (x, &exp); + return frexp (x, &exp); } float log2 (float x, int& exp) { - return std::frexp (x, &exp); + return frexp (x, &exp); } Complex @@ -332,6 +333,16 @@ double round (double x) { return std::round (x); } float round (float x) { return std::round (x); } + double frexp (double x, int *expptr) + { + return octave_frexp_wrapper (x, expptr); + } + + float frexp (float x, int *expptr) + { + return octave_frexpf_wrapper (x, expptr); + } + bool isnan (double x) {
--- a/liboctave/numeric/lo-mappers.h Fri Jul 08 14:05:44 2016 -0400 +++ b/liboctave/numeric/lo-mappers.h Sun Jul 03 09:54:43 2016 -0700 @@ -178,6 +178,9 @@ return std::complex<T> (roundb (real (x)), roundb (imag (x))); } + extern OCTAVE_API double frexp (double x, int *expptr); + extern OCTAVE_API float frexp (float x, int *expptr); + inline bool isnan (bool) { return false; } inline bool isnan (char) { return false; } extern OCTAVE_API bool isnan (double x);
--- a/liboctave/util/oct-inttypes.cc Fri Jul 08 14:05:44 2016 -0400 +++ b/liboctave/util/oct-inttypes.cc Sun Jul 03 09:54:43 2016 -0700 @@ -564,7 +564,7 @@ dblesplit (double x, bool& sign, uint64_t& mtis, int& exp) { sign = x < 0; x = fabs (x); - x = std::frexp (x, &exp); + x = octave::math::frexp (x, &exp); exp -= 52; mtis = static_cast<uint64_t> (ldexp (x, 52)); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/wrappers/math-wrappers.c Sun Jul 03 09:54:43 2016 -0700 @@ -0,0 +1,46 @@ +/* + +Copyright (C) 2016 Mike Miller + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<http://www.gnu.org/licenses/>. + +*/ + +// These functions may be provided by gnulib. We don't include gnulib +// headers directly in Octave's C++ source files to avoid problems that +// may be caused by the way that gnulib overrides standard library +// functions. + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include <math.h> + +#include "math-wrappers.h" + +double +octave_frexp_wrapper (double x, int *expptr) +{ + return frexp (x, expptr); +} + +float +octave_frexpf_wrapper (float x, int *expptr) +{ + return frexpf (x, expptr); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/wrappers/math-wrappers.h Sun Jul 03 09:54:43 2016 -0700 @@ -0,0 +1,40 @@ +/* + +Copyright (C) 2016 Mike Miller + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<http://www.gnu.org/licenses/>. + +*/ + +#if ! defined (octave_math_wrappers_h) +#define octave_math_wrappers_h 1 + +#if defined __cplusplus +extern "C" { +#endif + +double +octave_frexp_wrapper (double x, int *expptr); + +float +octave_frexpf_wrapper (float x, int *expptr); + +#if defined __cplusplus +} +#endif + +#endif
--- a/liboctave/wrappers/module.mk Fri Jul 08 14:05:44 2016 -0400 +++ b/liboctave/wrappers/module.mk Sun Jul 03 09:54:43 2016 -0700 @@ -10,6 +10,7 @@ liboctave/wrappers/getopt-wrapper.h \ liboctave/wrappers/glob-wrappers.h \ liboctave/wrappers/hash-wrappers.h \ + liboctave/wrappers/math-wrappers.h \ liboctave/wrappers/mkostemp-wrapper.h \ liboctave/wrappers/nanosleep-wrapper.h \ liboctave/wrappers/nproc-wrapper.h \ @@ -43,6 +44,7 @@ liboctave/wrappers/getopt-wrapper.c \ liboctave/wrappers/glob-wrappers.c \ liboctave/wrappers/hash-wrappers.c \ + liboctave/wrappers/math-wrappers.c \ liboctave/wrappers/mkostemp-wrapper.c \ liboctave/wrappers/nanosleep-wrapper.c \ liboctave/wrappers/nproc-wrapper.c \