comparison liboctave/util/lo-utils.h @ 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 83172e1c77f2
children 8b0675c2cfe0
comparison
equal deleted inserted replaced
28642:0237b10e3943 28643:a2cb3dec4bc5
64 64
65 return zero; 65 return zero;
66 } 66 }
67 67
68 extern OCTAVE_API bool xis_int_or_inf_or_nan (double x); 68 extern OCTAVE_API bool xis_int_or_inf_or_nan (double x);
69 extern OCTAVE_API bool xis_one_or_zero (double x); 69
70 extern OCTAVE_API bool xis_zero (double x); 70 template <typename T>
71 bool
72 xis_one_or_zero (const T& x)
73 {
74 return x == T (0) || x == T (1);
75 }
76
77 template <typename T>
78 bool
79 xis_zero (const T& x)
80 {
81 return x == T (0);
82 }
83
71 extern OCTAVE_API bool xtoo_large_for_float (double x); 84 extern OCTAVE_API bool xtoo_large_for_float (double x);
72 85
73 extern OCTAVE_API bool xtoo_large_for_float (const Complex& x); 86 extern OCTAVE_API bool xtoo_large_for_float (const Complex& x);
74 87
75 extern OCTAVE_API bool xis_int_or_inf_or_nan (float x); 88 extern OCTAVE_API bool xis_int_or_inf_or_nan (float x);
76 extern OCTAVE_API bool xis_one_or_zero (float x);
77 extern OCTAVE_API bool xis_zero (float x);
78 extern OCTAVE_API bool xtoo_large_for_float (float x); 89 extern OCTAVE_API bool xtoo_large_for_float (float x);
79 90
80 extern OCTAVE_API char * strsave (const char *); 91 extern OCTAVE_API char * strsave (const char *);
81 92
82 extern OCTAVE_API std::string octave_fgets (std::FILE *); 93 extern OCTAVE_API std::string octave_fgets (std::FILE *);