consteig
Compile-time eigenvalue and eigenvector computation for C++17
Loading...
Searching...
No Matches
sgn.hpp
1#ifndef CONSTMATH_SGN_HPP
2#define CONSTMATH_SGN_HPP
3
4namespace consteig
5{
6
9
15template <typename T> constexpr T sgn(const T x)
16{
17 return ( // positive
18 x > static_cast<T>(0) ? static_cast<T>(1) :
19 // negative
20 x < static_cast<T>(0) ? static_cast<T>(-1)
21 :
22 // else
23 static_cast<T>(0));
24}
25
27
28} // namespace consteig
29
30#endif
constexpr T sgn(const T x)
Signum function: returns +1, -1, or 0.
Definition sgn.hpp:15
constexpr T epsilon()
Machine epsilon for type T.
Definition utilities.hpp:82