comparison liboctave/util/lo-utils.h @ 31608:23664317f0d3

maint: merge stable to default
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 20:05:44 -0800
parents dfa5d9c3ae72 aac27ad79be6
children 5f11de0e7440
comparison
equal deleted inserted replaced
31606:dfa5d9c3ae72 31608:23664317f0d3
36 #include "oct-cmplx.h" 36 #include "oct-cmplx.h"
37 #include "quit.h" 37 #include "quit.h"
38 38
39 OCTAVE_BEGIN_NAMESPACE(octave) 39 OCTAVE_BEGIN_NAMESPACE(octave)
40 40
41 // Generic any/all test functionality with arbitrary predicate. 41 // Generic any/all test functionality with arbitrary predicate.
42 42
43 template <typename F, typename T, bool zero> 43 template <typename F, typename T, bool zero>
44 bool 44 bool
45 any_all_test (F fcn, const T *m, octave_idx_type len) 45 any_all_test (F fcn, const T *m, octave_idx_type len)
46 { 46 {
47 octave_idx_type i; 47 octave_idx_type i;
48 48
49 for (i = 0; i < len - 3; i += 4) 49 for (i = 0; i < len - 3; i += 4)
50 { 50 {
51 octave_quit (); 51 octave_quit ();
52 52
53 if (fcn (m[i]) != zero 53 if (fcn (m[i]) != zero
54 || fcn (m[i+1]) != zero 54 || fcn (m[i+1]) != zero
55 || fcn (m[i+2]) != zero 55 || fcn (m[i+2]) != zero
56 || fcn (m[i+3]) != zero) 56 || fcn (m[i+3]) != zero)
57 return ! zero; 57 return ! zero;
58 } 58 }
59 59
60 octave_quit (); 60 octave_quit ();
61 61
62 for (; i < len; i++) 62 for (; i < len; i++)
63 if (fcn (m[i]) != zero) 63 if (fcn (m[i]) != zero)
64 return ! zero; 64 return ! zero;
65 65
66 return zero; 66 return zero;
67 } 67 }
68 68
69 extern OCTAVE_API bool xis_int_or_inf_or_nan (double x); 69 extern OCTAVE_API bool xis_int_or_inf_or_nan (double x);
70 70
71 template <typename T> 71 template <typename T>
72 bool is_one_or_zero (const T& x) 72 bool is_one_or_zero (const T& x)
73 { 73 {
74 return x == T (0) || x == T (1); 74 return x == T (0) || x == T (1);
75 } 75 }
76 76
77 template <typename T> 77 template <typename T>
78 bool is_zero (const T& x) 78 bool is_zero (const T& x)
79 { 79 {
80 return x == T (0); 80 return x == T (0);
81 } 81 }
82 82
83 extern OCTAVE_API bool too_large_for_float (double x); 83 extern OCTAVE_API bool too_large_for_float (double x);
84 84
85 extern OCTAVE_API bool too_large_for_float (const Complex& x); 85 extern OCTAVE_API bool too_large_for_float (const Complex& x);
86 86
87 extern OCTAVE_API bool is_int_or_inf_or_nan (float x); 87 extern OCTAVE_API bool is_int_or_inf_or_nan (float x);
88 extern OCTAVE_API bool too_large_for_float (float x); 88 extern OCTAVE_API bool too_large_for_float (float x);
89 89
90 extern OCTAVE_API char * strsave (const char *); 90 extern OCTAVE_API char * strsave (const char *);
91 91
92 extern OCTAVE_API std::string fgets (std::FILE *); 92 extern OCTAVE_API std::string fgets (std::FILE *);
93 extern OCTAVE_API std::string fgetl (std::FILE *); 93 extern OCTAVE_API std::string fgetl (std::FILE *);
94 94
95 extern OCTAVE_API std::string fgets (std::FILE *, bool& eof); 95 extern OCTAVE_API std::string fgets (std::FILE *, bool& eof);
96 extern OCTAVE_API std::string fgetl (std::FILE *, bool& eof); 96 extern OCTAVE_API std::string fgetl (std::FILE *, bool& eof);
97 97
98 template <typename T> OCTAVE_API T read_value (std::istream& is); 98 template <typename T> OCTAVE_API T read_value (std::istream& is);
99 99
100 template <> OCTAVE_API double read_value (std::istream& is); 100 template <> OCTAVE_API double read_value (std::istream& is);
101 template <> OCTAVE_API Complex read_value (std::istream& is); 101 template <> OCTAVE_API Complex read_value (std::istream& is);
102 template <> OCTAVE_API float read_value (std::istream& is); 102 template <> OCTAVE_API float read_value (std::istream& is);
103 template <> OCTAVE_API FloatComplex read_value (std::istream& is); 103 template <> OCTAVE_API FloatComplex read_value (std::istream& is);
104 104
105 template <typename T> OCTAVE_API void write_value (std::ostream& os, const T& value); 105 template <typename T> OCTAVE_API void write_value (std::ostream& os, const T& value);
106 106
107 template <> OCTAVE_API void write_value (std::ostream& os, const double& value); 107 template <> OCTAVE_API void write_value (std::ostream& os, const double& value);
108 template <> OCTAVE_API void write_value (std::ostream& os, const Complex& value); 108 template <> OCTAVE_API void write_value (std::ostream& os, const Complex& value);
109 template <> OCTAVE_API void write_value (std::ostream& os, const float& value); 109 template <> OCTAVE_API void write_value (std::ostream& os, const float& value);
110 template <> OCTAVE_API void write_value (std::ostream& os, const FloatComplex& value); 110 template <> OCTAVE_API void write_value (std::ostream& os, const FloatComplex& value);
111 111
112 OCTAVE_BEGIN_NAMESPACE(math) 112 OCTAVE_BEGIN_NAMESPACE(math)
113 113
114 extern OCTAVE_API bool int_multiply_overflow (int a, int b, int *r); 114 extern OCTAVE_API bool int_multiply_overflow (int a, int b, int *r);
115 115
116 extern OCTAVE_API bool 116 extern OCTAVE_API bool
117 int_multiply_overflow (long int a, long int b, long int *r); 117 int_multiply_overflow (long int a, long int b, long int *r);
118 118
119 #if defined (OCTAVE_HAVE_LONG_LONG_INT) 119 #if defined (OCTAVE_HAVE_LONG_LONG_INT)
120 extern OCTAVE_API bool 120 extern OCTAVE_API bool
121 int_multiply_overflow (long long int a, long long int b, long long int *r); 121 int_multiply_overflow (long long int a, long long int b, long long int *r);
122 #endif 122 #endif
123 123
124 extern OCTAVE_API bool 124 extern OCTAVE_API bool
125 int_multiply_overflow (unsigned int a, unsigned int b, unsigned int *r); 125 int_multiply_overflow (unsigned int a, unsigned int b, unsigned int *r);
126 126
127 extern OCTAVE_API bool 127 extern OCTAVE_API bool
128 int_multiply_overflow (unsigned long int a, unsigned long int b, 128 int_multiply_overflow (unsigned long int a, unsigned long int b,
129 unsigned long int *r); 129 unsigned long int *r);
130 130
131 #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT) 131 #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
132 extern OCTAVE_API bool 132 extern OCTAVE_API bool
133 int_multiply_overflow (unsigned long long int a, unsigned long long int b, 133 int_multiply_overflow (unsigned long long int a, unsigned long long int b,
134 unsigned long long int *r); 134 unsigned long long int *r);
135 #endif 135 #endif
136 136
137 OCTAVE_END_NAMESPACE(math) 137 OCTAVE_END_NAMESPACE(math)
138 OCTAVE_END_NAMESPACE(octave) 138 OCTAVE_END_NAMESPACE(octave)
139 139