Blaze  3.6
Sign.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_SHIMS_SIGN_H_
36 #define _BLAZE_MATH_SHIMS_SIGN_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/util/EnableIf.h>
46 
47 
48 namespace blaze {
49 
50 //=================================================================================================
51 //
52 // SIGN SHIM
53 //
54 //=================================================================================================
55 
56 //*************************************************************************************************
66 template< typename T, typename = EnableIf_t< IsIntegral_v<T> > >
67 inline constexpr T sign( T a ) noexcept
68 {
69  return ( IsSigned_v<T> )
70  ? ( T(0) < a ) - ( a < T(0) )
71  : ( T(0) < a );
72 }
73 //*************************************************************************************************
74 
75 
76 //*************************************************************************************************
87 inline constexpr float sign( float a ) noexcept
88 {
89  if ( 0.0F < a ) return 1.0F;
90  else if( a < 0.0F ) return -1.0F;
91  else return a;
92 }
93 //*************************************************************************************************
94 
95 
96 //*************************************************************************************************
107 inline constexpr double sign( double a ) noexcept
108 {
109  if ( 0.0 < a ) return 1.0;
110  else if( a < 0.0 ) return -1.0;
111  else return a;
112 }
113 //*************************************************************************************************
114 
115 
116 //*************************************************************************************************
127 inline constexpr long double sign( long double a ) noexcept
128 {
129  if ( 0.0L < a ) return 1.0L;
130  else if( a < 0.0L ) return -1.0L;
131  else return a;
132 }
133 //*************************************************************************************************
134 
135 } // namespace blaze
136 
137 #endif
Header file for the IsIntegral type trait.
decltype(auto) sign(const DenseMatrix< MT, SO > &dm)
Applies the sign() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1184
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the EnableIf class template.
Header file for the IsSigned type trait.