Mercurial > octave
changeset 28643:a2cb3dec4bc5
define xis_one_or_zero and xis_zero as templates with specializations
* lo-utils.h, lo-utils.cc (xis_one_or_zero, xis_zero): Replace
existing functions that were defined only for float and double values
with new template functions with specializations.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 19 Aug 2020 23:52:02 -0400 |
parents | 0237b10e3943 |
children | ef0775fdab2c |
files | liboctave/util/lo-utils.cc liboctave/util/lo-utils.h |
diffstat | 2 files changed, 15 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/util/lo-utils.cc Wed Aug 19 23:45:18 2020 -0400 +++ b/liboctave/util/lo-utils.cc Wed Aug 19 23:52:02 2020 -0400 @@ -46,12 +46,6 @@ bool xis_int_or_inf_or_nan (double x) { return octave::math::isnan (x) || octave::math::x_nint (x) == x; } -bool xis_one_or_zero (double x) -{ return x == 0 || x == 1; } - -bool xis_zero (double x) -{ return x == 0; } - bool xtoo_large_for_float (double x) { return (octave::math::isfinite (x) @@ -67,12 +61,6 @@ bool xis_int_or_inf_or_nan (float x) { return octave::math::isnan (x) || octave::math::x_nint (x) == x; } -bool xis_one_or_zero (float x) -{ return x == 0 || x == 1; } - -bool xis_zero (float x) -{ return x == 0; } - // Save a string. char *
--- a/liboctave/util/lo-utils.h Wed Aug 19 23:45:18 2020 -0400 +++ b/liboctave/util/lo-utils.h Wed Aug 19 23:52:02 2020 -0400 @@ -66,15 +66,26 @@ } extern OCTAVE_API bool xis_int_or_inf_or_nan (double x); -extern OCTAVE_API bool xis_one_or_zero (double x); -extern OCTAVE_API bool xis_zero (double x); + +template <typename T> +bool +xis_one_or_zero (const T& x) +{ + return x == T (0) || x == T (1); +} + +template <typename T> +bool +xis_zero (const T& x) +{ + return x == T (0); +} + extern OCTAVE_API bool xtoo_large_for_float (double x); extern OCTAVE_API bool xtoo_large_for_float (const Complex& x); extern OCTAVE_API bool xis_int_or_inf_or_nan (float x); -extern OCTAVE_API bool xis_one_or_zero (float x); -extern OCTAVE_API bool xis_zero (float x); extern OCTAVE_API bool xtoo_large_for_float (float x); extern OCTAVE_API char * strsave (const char *);