simple.hpp
Go to the documentation of this file.
00001 
00006 /*****************************************************************************
00007 ** Ifdefs
00008 *****************************************************************************/
00009 
00010 #ifndef ECL_CORE_MATH_SIMPLE_HPP_
00011 #define ECL_CORE_MATH_SIMPLE_HPP_
00012 
00013 /*****************************************************************************
00014 ** Includes
00015 *****************************************************************************/
00016 
00017 #include <cmath>
00018 
00019 /*****************************************************************************
00020 ** Namespaces
00021 *****************************************************************************/
00022 
00023 namespace ecl {
00024 
00025 /*****************************************************************************
00026 ** Functions
00027 *****************************************************************************/
00037 template <typename Scalar>
00038 inline int sign(const Scalar &x) {
00039         // ToDo: should probably check some numeric traits here
00040         // Is this faster? (v > 0) - (v < 0);
00041         if ( x > 0 ) {
00042                 return 1;
00043         } else if ( x < 0 ) {
00044                 return -1;
00045         } else {
00046                 return 0;
00047         }
00048 }
00058 template <typename Scalar>
00059 inline int psign(const Scalar &x) {
00060         // ToDo: should probably check some numeric traits here
00061         if ( x >= 0 ) {
00062                 return 1;
00063         } else {
00064                 return -1;
00065         }
00066 }
00074 template <typename Scalar>
00075 inline Scalar cube_root(const Scalar &x) {
00076         // ToDo: should probably check some numeric traits here
00077         return psign(x)*pow(fabs(x),1.0/3.0);
00078 }
00079 
00080 
00081 } // namespace ecl
00082 
00083 #endif /* ECL_CORE_MATH_SIMPLE_HPP_ */


ecl_math
Author(s): Daniel Stonier
autogenerated on Wed Aug 26 2015 11:27:45