Blaze 3.9
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
48namespace blaze {
49
50//=================================================================================================
51//
52// SIGN SHIM
53//
54//=================================================================================================
55
56//*************************************************************************************************
66template< typename T, typename = EnableIf_t< IsIntegral_v<T> > >
67constexpr 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//*************************************************************************************************
87constexpr 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//*************************************************************************************************
107constexpr 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//*************************************************************************************************
127constexpr 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 EnableIf class template.
Header file for the IsIntegral type trait.
Header file for the IsSigned type trait.
BLAZE_ALWAYS_INLINE SIMDdouble sign(const SIMDdouble &a) noexcept=delete
Sign function for a vector of double precision floating point values.