IsDefault.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_SHIMS_ISDEFAULT_H_
36 #define _BLAZE_MATH_SHIMS_ISDEFAULT_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <cmath>
44 #include <blaze/math/Accuracy.h>
46 #include <blaze/system/Inline.h>
47 #include <blaze/util/Complex.h>
49 
50 
51 namespace blaze {
52 
53 //=================================================================================================
54 //
55 // ISDEFAULT SHIM
56 //
57 //=================================================================================================
58 
59 //*************************************************************************************************
96 template< bool RF // Relaxation flag
97  , typename Type > // Type of the given value/object
98 BLAZE_ALWAYS_INLINE bool isDefault( const Type& v ) noexcept( IsBuiltin<Type>::value )
99 {
100  return v == Type();
101 }
102 //*************************************************************************************************
103 
104 
105 //*************************************************************************************************
117 template< bool RF > // Relaxation flag
118 BLAZE_ALWAYS_INLINE bool isDefault( float v ) noexcept
119 {
120  if( RF == relaxed )
121  return std::fabs( v ) <= accuracy;
122  else
123  return v == 0.0F;
124 }
126 //*************************************************************************************************
127 
128 
129 //*************************************************************************************************
141 template< bool RF > // Relaxation flag
142 BLAZE_ALWAYS_INLINE bool isDefault( double v ) noexcept
143 {
144  if( RF == relaxed )
145  return std::fabs( v ) <= accuracy;
146  else
147  return v == 0.0;
148 }
150 //*************************************************************************************************
151 
152 
153 //*************************************************************************************************
165 template< bool RF > // Relaxation flag
166 BLAZE_ALWAYS_INLINE bool isDefault( long double v ) noexcept
167 {
168  if( RF == relaxed )
169  return std::fabs( v ) <= accuracy;
170  else
171  return v == 0.0L;
172 }
174 //*************************************************************************************************
175 
176 
177 //*************************************************************************************************
189 template< bool RF // Relaxation flag
190  , typename T > // Value type of the complex number
191 BLAZE_ALWAYS_INLINE bool isDefault( const complex<T>& v ) noexcept( IsBuiltin<T>::value )
192 {
193  return isDefault<RF>( real( v ) ) && isDefault<RF>( imag( v ) );
194 }
196 //*************************************************************************************************
197 
198 
199 //*************************************************************************************************
236 template< typename Type > // Type of the given value/object
237 BLAZE_ALWAYS_INLINE bool isDefault( const Type& v ) noexcept( IsBuiltin<Type>::value )
238 {
239  return isDefault<relaxed>( v );
240 }
241 //*************************************************************************************************
242 
243 } // namespace blaze
244 
245 #endif
Computation accuracy for floating point data types.
decltype(auto) real(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the real part of each single element of dm.
Definition: DMatMapExpr.h:1387
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
Header file for the relaxation flag types.
constexpr bool relaxed
Relaxation flag for relaxed semantics.
Definition: RelaxationFlag.h:85
Compile time check for built-in data types.This type trait tests whether or not the given template pa...
Definition: IsBuiltin.h:75
Header file for the IsBuiltin type trait.
Header file for the complex data type.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:628
constexpr Accuracy accuracy
Global Accuracy instance.The blaze::accuracy instance can be used wherever a floating point data type...
Definition: Accuracy.h:902
decltype(auto) imag(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the imaginary part of each single element of dm.
Definition: DMatMapExpr.h:1416
System settings for the inline keywords.