Equal.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_SHIMS_EQUAL_H_
36 #define _BLAZE_MATH_SHIMS_EQUAL_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <cmath>
44 #include <boost/math/special_functions/next.hpp>
45 #include <blaze/math/Accuracy.h>
47 #include <blaze/util/Complex.h>
48 
49 
50 namespace blaze {
51 
52 //=================================================================================================
53 //
54 // EQUAL SHIM
55 //
56 //=================================================================================================
57 
58 //*************************************************************************************************
76 inline bool equal( float a, float b )
77 {
78  return ( std::fabs( a - b ) <= 4E-6 ) ||
79  ( std::fabs( boost::math::float_distance( a, b ) ) <= 6.0F );
80 }
82 //*************************************************************************************************
83 
84 
85 //*************************************************************************************************
103 inline bool equal( float a, double b )
104 {
105  return equal( a, static_cast<float>( b ) );
106 }
108 //*************************************************************************************************
109 
110 
111 //*************************************************************************************************
129 inline bool equal( float a, long double b )
130 {
131  return equal( a, static_cast<float>( b ) );
132 }
134 //*************************************************************************************************
135 
136 
137 //*************************************************************************************************
151 inline bool equal( double a, float b )
152 {
153  return equal( static_cast<float>( a ), b );
154 }
156 //*************************************************************************************************
157 
158 
159 //*************************************************************************************************
177 inline bool equal( double a, double b )
178 {
179  return ( std::fabs( a - b ) <= accuracy ) ||
180  ( std::fabs( boost::math::float_distance( a, b ) ) <= 4.0 );
181 }
183 //*************************************************************************************************
184 
185 
186 //*************************************************************************************************
204 inline bool equal( double a, long double b )
205 {
206  return std::fabs( a - b ) <= ( 1E-8L * std::fabs( b ) );
207 }
209 //*************************************************************************************************
210 
211 
212 //*************************************************************************************************
230 inline bool equal( long double a, float b )
231 {
232  return equal( static_cast<float>( a ), b );
233 }
235 //*************************************************************************************************
236 
237 
238 //*************************************************************************************************
256 inline bool equal( long double a, double b )
257 {
258  return equal( static_cast<double>( a ), b );
259 }
261 //*************************************************************************************************
262 
263 
264 //*************************************************************************************************
282 inline bool equal( long double a, long double b )
283 {
284  return ( std::fabs( a - b ) <= accuracy ) ||
285  ( std::fabs( boost::math::float_distance( a, b ) ) <= 4.0L );
286 }
288 //*************************************************************************************************
289 
290 
291 //*************************************************************************************************
304 template< typename T1 // Type of the left-hand side complex value
305  , typename T2 > // Type of the right-hand side scalar value
306 inline bool equal( complex<T1> a, T2 b )
307 {
308  return equal( a.real(), b ) && isDefault( a.imag() );
309 }
311 //*************************************************************************************************
312 
313 
314 //*************************************************************************************************
327 template< typename T1 // Type of the left-hand side scalar value
328  , typename T2 > // Type of the right-hand side complex value
329 inline bool equal( T1 a, complex<T2> b )
330 {
331  return equal( a, b.real() ) && isDefault( b.imag() );
332 }
334 //*************************************************************************************************
335 
336 
337 //*************************************************************************************************
350 template< typename T1 // Type of the left-hand side complex value
351  , typename T2 > // Type of the right-hand side complex value
352 inline bool equal( complex<T1> a, complex<T2> b )
353 {
354  return equal( a.real(), b.real() ) && equal( a.imag(), b.imag() );
355 }
357 //*************************************************************************************************
358 
359 
360 //*************************************************************************************************
374 template< typename T1 // Type of the left-hand side value/object
375  , typename T2 > // Type of the right-hand side value/object
376 inline bool equal( const T1& a, const T2& b )
377 {
378  return a == b;
379 }
380 //*************************************************************************************************
381 
382 } // namespace blaze
383 
384 #endif
Computation accuracy for floating point data types.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
bool equal(const T1 &a, const T2 &b)
Generic equality check.
Definition: Equal.h:376
Header file for the isDefault shim.
const Accuracy accuracy
Global Accuracy instance.The blaze::accuracy instance can be used wherever a floating point data type...
Definition: Accuracy.h:901
Header file for the complex data type.