Program Listing for File simple.hpp
↰ Return to documentation for file (/tmp/ws/src/ecl_core/ecl_math/include/ecl/math/simple.hpp
)
/*****************************************************************************
** Ifdefs
*****************************************************************************/
#ifndef ECL_CORE_MATH_SIMPLE_HPP_
#define ECL_CORE_MATH_SIMPLE_HPP_
/*****************************************************************************
** Includes
*****************************************************************************/
#include <cmath>
/*****************************************************************************
** Namespaces
*****************************************************************************/
namespace ecl {
/*****************************************************************************
** Functions
*****************************************************************************/
template <typename Scalar>
inline int sign(const Scalar &x) {
// ToDo: should probably check some numeric traits here
// Is this faster? (v > 0) - (v < 0);
// http://stackoverflow.com/questions/1903954/is-there-a-standard-sign-function-signum-sgn-in-c-c
if ( x > 0 ) {
return 1;
} else if ( x < 0 ) {
return -1;
} else {
return 0;
}
}
template <typename Scalar>
inline int psign(const Scalar &x) {
// ToDo: should probably check some numeric traits here
if ( x >= 0 ) {
return 1;
} else {
return -1;
}
}
template <typename Scalar>
inline int nsign(const Scalar &x) {
// ToDo: should probably check some numeric traits here
if ( x > 0 ) {
return 1;
} else {
return -1;
}
}
template <typename Scalar>
inline Scalar cube_root(const Scalar &x) {
// ToDo: should probably check some numeric traits here
return psign(x)*pow(fabs(x),1.0/3.0);
}
} // namespace ecl
#endif /* ECL_CORE_MATH_SIMPLE_HPP_ */