@@ -66,8 +66,8 @@ namespace xsimd
6666 clip_hi = 1 .;
6767 for (size_t i = 0 ; i < N; ++i)
6868 {
69- lhs_input[i] = value_type (i) / 4 + value_type (1.2 ) * std::sqrt (value_type (i + 0.25 ));
70- rhs_input[i] = value_type (10.2 ) / (i + 2 ) + value_type (0.25 );
69+ lhs_input[i] = value_type (i) / 4 + value_type (1.2 ) * std::sqrt (value_type (i + 0.25 )) + 1 . ;
70+ rhs_input[i] = value_type (10.2 ) / (i + 2 ) + value_type (0.25 ) + 1 . ;
7171 from_input[i] = rhs_input[i] - value_type (1 );
7272 fmod_res[i] = std::fmod (lhs_input[i], rhs_input[i]);
7373 remainder_res[i] = std::remainder (lhs_input[i], rhs_input[i]);
@@ -81,6 +81,76 @@ namespace xsimd
8181 }
8282 }
8383
84+ namespace detail
85+ {
86+ template <class T , bool is_int = std::is_integral<typename T::value_type>::value>
87+ struct infinity_tester
88+ {
89+ using tester_type = T;
90+ using vector_type = typename T::vector_type;
91+ using res_type = typename T::res_type;
92+
93+ static inline bool isfinite (std::ostream& out,
94+ const std::string& topic,
95+ tester_type& tester,
96+ res_type& res)
97+ {
98+ vector_type lhs = infinity<vector_type>();
99+ vector_type vres = select (xsimd::isfinite (lhs), vector_type (1 .), vector_type (0 .));
100+ detail::store_vec (vres, res);
101+ bool success = check_almost_equal (topic, res, tester.inf_res , out);
102+ typename res_type::value_type scalar_cond_res = xsimd::isfinite (lhs[0 ])?1 .:0 .;
103+ success &= check_almost_equal (topic, scalar_cond_res, tester.inf_res [0 ], out);
104+ return success;
105+ }
106+
107+ static inline bool isinf (std::ostream& out,
108+ const std::string& topic,
109+ tester_type& tester,
110+ res_type& res)
111+
112+ {
113+ vector_type lhs = infinity<vector_type>();
114+ vector_type vres = select (xsimd::isinf (lhs), vector_type (0 .), vector_type (1 .));
115+ detail::store_vec (vres, res);
116+ bool success = check_almost_equal (topic, res, tester.inf_res , out);
117+ typename res_type::value_type scalar_cond_res = xsimd::isinf (lhs[0 ])?0 .:1 .;
118+ success &= check_almost_equal (topic, scalar_cond_res, tester.inf_res [0 ], out);
119+ return success;
120+ }
121+ };
122+
123+ template <class T >
124+ struct infinity_tester <T, true >
125+ {
126+ using tester_type = T;
127+ using vector_type = typename T::vector_type;
128+ using res_type = typename T::res_type;
129+
130+ static inline bool isfinite (std::ostream& out,
131+ const std::string& topic,
132+ tester_type& tester,
133+ res_type&)
134+ {
135+ vector_type lhs (1 .);
136+ typename res_type::value_type scalar_cond_res = xsimd::isfinite (lhs[0 ])?0 .:1 .;
137+ bool success = check_almost_equal (topic, scalar_cond_res, tester.inf_res [0 ], out);
138+ return true ;
139+ }
140+
141+ static inline bool isinf (std::ostream& out,
142+ const std::string& topic,
143+ tester_type& tester,
144+ res_type&)
145+ {
146+ vector_type lhs (1 .);
147+ typename res_type::value_type scalar_cond_res = xsimd::isfinite (lhs[0 ])?1 .:0 .;
148+ bool success = check_almost_equal (topic, scalar_cond_res, tester.inf_res [0 ], out);
149+ return true ;
150+ }
151+ };
152+ }
153+
84154 template <class T >
85155 bool test_simd_basic_math (std::ostream& out, T& tester)
86156 {
@@ -152,28 +222,15 @@ namespace xsimd
152222 detail::store_vec (vres, res);
153223 tmp_success = check_almost_equal (topic, res, tester.finite_res , out);
154224 success = success && tmp_success;
155- lhs = infinity<vector_type>();
156- vres = select (isfinite (lhs), vector_type (1 .), vector_type (0 .));
157- detail::store_vec (vres, res);
158- tmp_success = check_almost_equal (topic, res, tester.inf_res , out);
159- success = success && tmp_success;
160- scalar_cond_res = xsimd::isfinite (lhs[0 ])?1 .:0 .;
161- success &= check_almost_equal (topic, scalar_cond_res, tester.inf_res [0 ], out);
225+ success = success && detail::infinity_tester<T>::isfinite (out, topic, tester, res);
162226
163227 topic = " isinf : " ;
164228 lhs = vector_type (12 .);
165229 vres = select (isinf (lhs), vector_type (0 .), vector_type (1 .));
166230 detail::store_vec (vres, res);
167231 tmp_success = check_almost_equal (topic, res, tester.finite_res , out);
168232 success = success && tmp_success;
169- lhs = infinity<vector_type>();
170- vres = select (isinf (lhs), vector_type (0 .), vector_type (1 .));
171- detail::store_vec (vres, res);
172- tmp_success = check_almost_equal (topic, res, tester.inf_res , out);
173- success = success && tmp_success;
174- scalar_cond_res = xsimd::isinf (lhs[0 ])?0 .:1 .;
175- success &= check_almost_equal (topic, scalar_cond_res, tester.inf_res [0 ], out);
176-
233+
177234 topic = " nextafter: " ;
178235 detail::load_vec (lhs, tester.from_input );
179236 detail::load_vec (rhs, tester.rhs_input );
0 commit comments