.. _program_listing_file__tmp_ws_src_ecl_core_ecl_math_include_ecl_math_simple.hpp: Program Listing for File simple.hpp =================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/ecl_core/ecl_math/include/ecl/math/simple.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /***************************************************************************** ** Ifdefs *****************************************************************************/ #ifndef ECL_CORE_MATH_SIMPLE_HPP_ #define ECL_CORE_MATH_SIMPLE_HPP_ /***************************************************************************** ** Includes *****************************************************************************/ #include /***************************************************************************** ** Namespaces *****************************************************************************/ namespace ecl { /***************************************************************************** ** Functions *****************************************************************************/ template 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 inline int psign(const Scalar &x) { // ToDo: should probably check some numeric traits here if ( x >= 0 ) { return 1; } else { return -1; } } template inline int nsign(const Scalar &x) { // ToDo: should probably check some numeric traits here if ( x > 0 ) { return 1; } else { return -1; } } template 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_ */