VPTissue Reference Manual
signum.h
Go to the documentation of this file.
1 #ifndef MATH_SIGNUM_H_INCLUDED
2 #define MATH_SIGNUM_H_INCLUDED
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include <type_traits>
23 
24 namespace SimPT_Sim {
25 namespace Util {
26 
31 template <typename T> inline constexpr
32 int signum(T x, std::false_type)
33 {
34  return T(0) < x;
35 }
36 
41 template <typename T> inline constexpr
42 int signum(T x, std::true_type)
43 {
44  return (T(0) < x) - (x < T(0));
45 }
46 
51 template <typename T> inline constexpr
52 int signum(T x)
53 {
54  return signum(x, std::is_signed<T>());
55 }
56 
57 } // Util
58 } // SimPT_Sim
59 
60 #endif // end_of_include_guard
constexpr int signum(T x, std::false_type)
Overload for unsigned types.
Definition: signum.h:32
Namespace for the core simulator.