All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
45 #include <blaze/util/Complex.h>
46 
47 
48 namespace blaze {
49 
50 //=================================================================================================
51 //
52 // EQUAL SHIM
53 //
54 //=================================================================================================
55 
56 //*************************************************************************************************
70 inline bool equal( float a, float b )
71 {
72  // Computing the absolute error
73  if( std::fabs( a - b ) <= 1E-6F )
74  return true;
75 
76  // Computing the relative error
77  float relativeError;
78  if( std::fabs(b) > std::fabs(a) )
79  relativeError = std::fabs( ( a - b ) / b );
80  else
81  relativeError = std::fabs( ( a - b ) / a );
82 
83  if( relativeError <= 5E-4F )
84  return true;
85  return false;
86 }
88 //*************************************************************************************************
89 
90 
91 //*************************************************************************************************
105 inline bool equal( float a, double b )
106 {
107  return equal( a, static_cast<float>( b ) );
108 }
110 //*************************************************************************************************
111 
112 
113 //*************************************************************************************************
127 inline bool equal( float a, long double b )
128 {
129  return equal( a, static_cast<float>( b ) );
130 }
132 //*************************************************************************************************
133 
134 
135 //*************************************************************************************************
149 inline bool equal( double a, float b )
150 {
151  return equal( static_cast<float>( a ), b );
152 }
154 //*************************************************************************************************
155 
156 
157 //*************************************************************************************************
171 inline bool equal( double a, double b )
172 {
173  return std::fabs( a - b ) <= ( 1E-8 * std::fabs( a ) );
174 }
176 //*************************************************************************************************
177 
178 
179 //*************************************************************************************************
193 inline bool equal( double a, long double b )
194 {
195  return std::fabs( a - b ) <= ( 1E-8L * std::fabs( b ) );
196 }
198 //*************************************************************************************************
199 
200 
201 //*************************************************************************************************
215 inline bool equal( long double a, float b )
216 {
217  return equal( static_cast<float>( a ), b );
218 }
220 //*************************************************************************************************
221 
222 
223 //*************************************************************************************************
237 inline bool equal( long double a, double b )
238 {
239  return std::fabs( a - b ) <= ( 1E-8L * std::fabs( a ) );
240 }
242 //*************************************************************************************************
243 
244 
245 //*************************************************************************************************
259 inline bool equal( long double a, long double b )
260 {
261  return std::fabs( a - b ) <= ( 1E-8L * std::fabs( a ) );
262 }
264 //*************************************************************************************************
265 
266 
267 //*************************************************************************************************
280 template< typename T1 // Type of the left-hand side complex value
281  , typename T2 > // Type of the right-hand side scalar value
282 inline bool equal( complex<T1> a, T2 b )
283 {
284  return equal( a.real(), b ) && isDefault( a.imag() );
285 }
287 //*************************************************************************************************
288 
289 
290 //*************************************************************************************************
303 template< typename T1 // Type of the left-hand side scalar value
304  , typename T2 > // Type of the right-hand side complex value
305 inline bool equal( T1 a, complex<T2> b )
306 {
307  return equal( a, b.real() ) && isDefault( b.imag() );
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 complex value
328 inline bool equal( complex<T1> a, complex<T2> b )
329 {
330  return equal( a.real(), b.real() ) && equal( a.imag(), b.imag() );
331 }
333 //*************************************************************************************************
334 
335 
336 //*************************************************************************************************
350 template< typename T1 // Type of the left-hand side value/object
351  , typename T2 > // Type of the right-hand side value/object
352 inline bool equal( const T1& a, const T2& b )
353 {
354  return a == b;
355 }
356 //*************************************************************************************************
357 
358 } // namespace blaze
359 
360 #endif
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4622
const StaticMatrix< Type, 3UL, 3UL, false > fabs(const RotationMatrix< Type > &m)
Returns a matrix containing the absolute values of each single element of m.
Definition: RotationMatrix.h:1102
bool equal(const T1 &a, const T2 &b)
Generic equality check.
Definition: Equal.h:352
Header file for the isDefault shim.
Header file for the complex data type.