Blaze 3.9
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>
48#include <blaze/util/Complex.h>
49#include <blaze/util/EnableIf.h>
50
51
52namespace blaze {
53
54//=================================================================================================
55//
56// EQUAL SHIM
57//
58//=================================================================================================
59
60//*************************************************************************************************
74template< RelaxationFlag RF // Relaxation flag
75 , typename T1 // Type of the left-hand side value/object
76 , typename T2 // Type of the right-hand side value/object
77 , typename = EnableIf_t< IsScalar_v<T1> && IsScalar_v<T2> > >
78constexpr bool equal( const T1& a, const T2& b )
79{
80 return a == b;
81}
82//*************************************************************************************************
83
84
85//*************************************************************************************************
103template< RelaxationFlag RF > // Relaxation flag
104inline bool equal( float a, float b )
105{
106 if( RF == relaxed ) {
107 const float acc( static_cast<float>( accuracy ) );
108 return ( std::fabs( a - b ) <= max( acc, acc * std::fabs( a ) ) );
109 }
110 else {
111 return a == b;
112 }
113}
115//*************************************************************************************************
116
117
118//*************************************************************************************************
136template< RelaxationFlag RF > // Relaxation flag
137inline bool equal( float a, double b )
138{
139 return equal<RF>( a, static_cast<float>( b ) );
140}
142//*************************************************************************************************
143
144
145//*************************************************************************************************
163template< RelaxationFlag RF > // Relaxation flag
164inline bool equal( float a, long double b )
165{
166 return equal<RF>( a, static_cast<float>( b ) );
167}
169//*************************************************************************************************
170
171
172//*************************************************************************************************
186template< RelaxationFlag RF > // Relaxation flag
187inline bool equal( double a, float b )
188{
189 return equal<RF>( static_cast<float>( a ), b );
190}
192//*************************************************************************************************
193
194
195//*************************************************************************************************
213template< RelaxationFlag RF > // Relaxation flag
214inline bool equal( double a, double b )
215{
216 if( RF == relaxed ) {
217 const double acc( static_cast<double>( accuracy ) );
218 return ( std::fabs( a - b ) <= max( acc, acc * std::fabs( a ) ) );
219 }
220 else {
221 return a == b;
222 }
223}
225//*************************************************************************************************
226
227
228//*************************************************************************************************
246template< RelaxationFlag RF > // Relaxation flag
247inline bool equal( double a, long double b )
248{
249 return equal<RF>( a, static_cast<double>( b ) );
250}
252//*************************************************************************************************
253
254
255//*************************************************************************************************
273template< RelaxationFlag RF > // Relaxation flag
274inline bool equal( long double a, float b )
275{
276 return equal<RF>( static_cast<float>( a ), b );
277}
279//*************************************************************************************************
280
281
282//*************************************************************************************************
300template< RelaxationFlag RF > // Relaxation flag
301inline bool equal( long double a, double b )
302{
303 return equal<RF>( static_cast<double>( a ), b );
304}
306//*************************************************************************************************
307
308
309//*************************************************************************************************
327template< RelaxationFlag RF > // Relaxation flag
328inline bool equal( long double a, long double b )
329{
330 if( RF == relaxed ) {
331 const long double acc( static_cast<long double>( accuracy ) );
332 return ( std::fabs( a - b ) <= max( acc, acc * std::fabs( a ) ) );
333 }
334 else {
335 return a == b;
336 }
337}
339//*************************************************************************************************
340
341
342//*************************************************************************************************
355template< RelaxationFlag RF // Relaxation flag
356 , typename T1 // Type of the left-hand side complex value
357 , typename T2 > // Type of the right-hand side scalar value
358inline bool equal( complex<T1> a, T2 b )
359{
360 return equal<RF>( real( a ), b ) && equal<RF>( imag( a ), T1() );
361}
363//*************************************************************************************************
364
365
366//*************************************************************************************************
379template< RelaxationFlag RF // Relaxation flag
380 , typename T1 // Type of the left-hand side scalar value
381 , typename T2 > // Type of the right-hand side complex value
382inline bool equal( T1 a, complex<T2> b )
383{
384 return equal<RF>( a, real( b ) ) && equal<RF>( imag( b ), T2() );
385}
387//*************************************************************************************************
388
389
390//*************************************************************************************************
403template< RelaxationFlag RF // Relaxation flag
404 , typename T1 // Type of the left-hand side complex value
405 , typename T2 > // Type of the right-hand side complex value
406inline bool equal( complex<T1> a, complex<T2> b )
407{
408 return equal<RF>( real( a ), real( b ) ) && equal<RF>( imag( a ), imag( b ) );
409}
411//*************************************************************************************************
412
413
414//*************************************************************************************************
428template< typename T1 // Type of the left-hand side value/object
429 , typename T2 > // Type of the right-hand side value/object
430constexpr bool equal( const T1& a, const T2& b )
431{
432 return equal<relaxed>( a, b );
433}
434//*************************************************************************************************
435
436} // namespace blaze
437
438#endif
Computation accuracy for floating point data types.
Header file for the complex data type.
Header file for the EnableIf class template.
Header file for the IsScalar type trait.
Header file for the relaxation flag enumeration.
Complex data type of the Blaze library.
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1375
decltype(auto) real(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the real part of each single element of dm.
Definition: DMatMapExpr.h:1529
decltype(auto) imag(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the imaginary part of each single element of dm.
Definition: DMatMapExpr.h:1557
constexpr bool equal(const T1 &a, const T2 &b)
Generic equality check.
Definition: Equal.h:430
RelaxationFlag
Relaxation flag for strict or relaxed semantics.
Definition: RelaxationFlag.h:66
constexpr Accuracy accuracy
Global Accuracy instance.
Definition: Accuracy.h:907
@ relaxed
Flag for relaxed semantics.
Definition: RelaxationFlag.h:68
Header file for the generic max algorithm.