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 <blaze/math/Accuracy.h>
45 #include <blaze/math/Functions.h>
46 #include <blaze/util/Complex.h>
47 
48 
49 namespace blaze {
50 
51 //=================================================================================================
52 //
53 // EQUAL SHIM
54 //
55 //=================================================================================================
56 
57 //*************************************************************************************************
71 template< typename T1 // Type of the left-hand side value/object
72  , typename T2 > // Type of the right-hand side value/object
73 inline bool equal( const T1& a, const T2& b )
74 {
75  return a == b;
76 }
77 //*************************************************************************************************
78 
79 
80 //*************************************************************************************************
98 inline bool equal( float a, float b )
99 {
100  const float acc( static_cast<float>( accuracy ) );
101  return ( std::fabs( a - b ) <= max( acc, acc * std::fabs( a ) ) );
102 }
104 //*************************************************************************************************
105 
106 
107 //*************************************************************************************************
125 inline bool equal( float a, double b )
126 {
127  return equal( a, static_cast<float>( b ) );
128 }
130 //*************************************************************************************************
131 
132 
133 //*************************************************************************************************
151 inline bool equal( float a, long double b )
152 {
153  return equal( a, static_cast<float>( b ) );
154 }
156 //*************************************************************************************************
157 
158 
159 //*************************************************************************************************
173 inline bool equal( double a, float b )
174 {
175  return equal( static_cast<float>( a ), b );
176 }
178 //*************************************************************************************************
179 
180 
181 //*************************************************************************************************
199 inline bool equal( double a, double b )
200 {
201  const double acc( static_cast<double>( accuracy ) );
202  return ( std::fabs( a - b ) <= max( acc, acc * std::fabs( a ) ) );
203 }
205 //*************************************************************************************************
206 
207 
208 //*************************************************************************************************
226 inline bool equal( double a, long double b )
227 {
228  return equal( a, static_cast<double>( b ) );
229 }
231 //*************************************************************************************************
232 
233 
234 //*************************************************************************************************
252 inline bool equal( long double a, float b )
253 {
254  return equal( static_cast<float>( a ), b );
255 }
257 //*************************************************************************************************
258 
259 
260 //*************************************************************************************************
278 inline bool equal( long double a, double b )
279 {
280  return equal( static_cast<double>( a ), b );
281 }
283 //*************************************************************************************************
284 
285 
286 //*************************************************************************************************
304 inline bool equal( long double a, long double b )
305 {
306  const long double acc( static_cast<long double>( accuracy ) );
307  return ( std::fabs( a - b ) <= max( acc, acc * std::fabs( a ) ) );
308 }
310 //*************************************************************************************************
311 
312 
313 //*************************************************************************************************
326 template< typename T1 // Type of the left-hand side complex value
327  , typename T2 > // Type of the right-hand side scalar value
328 inline bool equal( complex<T1> a, T2 b )
329 {
330  return equal( real( a ), b ) && equal( imag( a ), T1() );
331 }
333 //*************************************************************************************************
334 
335 
336 //*************************************************************************************************
349 template< typename T1 // Type of the left-hand side scalar value
350  , typename T2 > // Type of the right-hand side complex value
351 inline bool equal( T1 a, complex<T2> b )
352 {
353  return equal( a, real( b ) ) && equal( imag( b ), T2() );
354 }
356 //*************************************************************************************************
357 
358 
359 //*************************************************************************************************
372 template< typename T1 // Type of the left-hand side complex value
373  , typename T2 > // Type of the right-hand side complex value
374 inline bool equal( complex<T1> a, complex<T2> b )
375 {
376  return equal( real( a ), real( b ) ) && equal( imag( a ), imag( b ) );
377 }
379 //*************************************************************************************************
380 
381 } // namespace blaze
382 
383 #endif
Computation accuracy for floating point data types.
Header file for mathematical functions.
const DMatForEachExpr< MT, Imag, SO > imag(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the imaginary part of each single element of dm.
Definition: DMatForEachExpr.h:1251
const ElementType_< MT > max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1716
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
const DMatForEachExpr< MT, Real, SO > real(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the real part of each single element of dm.
Definition: DMatForEachExpr.h:1223
bool equal(const T1 &a, const T2 &b)
Generic equality check.
Definition: Equal.h:73
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.