simple.hpp
Go to the documentation of this file.
1 
6 /*****************************************************************************
7 ** Ifdefs
8 *****************************************************************************/
9 
10 #ifndef ECL_CORE_MATH_SIMPLE_HPP_
11 #define ECL_CORE_MATH_SIMPLE_HPP_
12 
13 /*****************************************************************************
14 ** Includes
15 *****************************************************************************/
16 
17 #include <cmath>
18 
19 /*****************************************************************************
20 ** Namespaces
21 *****************************************************************************/
22 
23 namespace ecl {
24 
25 /*****************************************************************************
26 ** Functions
27 *****************************************************************************/
37 template <typename Scalar>
38 inline int sign(const Scalar &x) {
39  // ToDo: should probably check some numeric traits here
40  // Is this faster? (v > 0) - (v < 0);
41  // http://stackoverflow.com/questions/1903954/is-there-a-standard-sign-function-signum-sgn-in-c-c
42  if ( x > 0 ) {
43  return 1;
44  } else if ( x < 0 ) {
45  return -1;
46  } else {
47  return 0;
48  }
49 }
50 
60 template <typename Scalar>
61 inline int psign(const Scalar &x) {
62  // ToDo: should probably check some numeric traits here
63  if ( x >= 0 ) {
64  return 1;
65  } else {
66  return -1;
67  }
68 }
69 
79 template <typename Scalar>
80 inline int nsign(const Scalar &x) {
81  // ToDo: should probably check some numeric traits here
82  if ( x > 0 ) {
83  return 1;
84  } else {
85  return -1;
86  }
87 }
88 
96 template <typename Scalar>
97 inline Scalar cube_root(const Scalar &x) {
98  // ToDo: should probably check some numeric traits here
99  return psign(x)*pow(fabs(x),1.0/3.0);
100 }
101 
102 
103 } // namespace ecl
104 
105 #endif /* ECL_CORE_MATH_SIMPLE_HPP_ */
Embedded control libraries.
int sign(const Scalar &x)
A sign function for numerical values.
Definition: simple.hpp:38
int psign(const Scalar &x)
A sign function for numerical values (positive return if arg is zero).
Definition: simple.hpp:61
Scalar cube_root(const Scalar &x)
The real solution to a cube root.
Definition: simple.hpp:97
int nsign(const Scalar &x)
A sign function for numerical values (negative return if arg is zero).
Definition: simple.hpp:80


ecl_math
Author(s): Daniel Stonier
autogenerated on Mon Feb 28 2022 22:18:37