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         // http://stackoverflow.com/questions/1903954/is-there-a-standard-sign-function-signum-sgn-in-c-c
00042         if ( x > 0 ) {
00043                 return 1;
00044         } else if ( x < 0 ) {
00045                 return -1;
00046         } else {
00047                 return 0;
00048         }
00049 }
00050 
00060 template <typename Scalar>
00061 inline int psign(const Scalar &x) {
00062         // ToDo: should probably check some numeric traits here
00063         if ( x >= 0 ) {
00064                 return 1;
00065         } else {
00066                 return -1;
00067         }
00068 }
00069 
00079 template <typename Scalar>
00080 inline int nsign(const Scalar &x) {
00081         // ToDo: should probably check some numeric traits here
00082         if ( x > 0 ) {
00083                 return 1;
00084         } else {
00085                 return -1;
00086         }
00087 }
00088 
00096 template <typename Scalar>
00097 inline Scalar cube_root(const Scalar &x) {
00098         // ToDo: should probably check some numeric traits here
00099         return psign(x)*pow(fabs(x),1.0/3.0);
00100 }
00101 
00102 
00103 } // namespace ecl
00104 
00105 #endif /* ECL_CORE_MATH_SIMPLE_HPP_ */


ecl_math
Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:21:34