math_utils.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef _SCTL_MATH_UTILS_
  2. #define _SCTL_MATH_UTILS_
  3. #include SCTL_INCLUDE(common.hpp)
  4. #include <cmath>
  5. #include <ostream>
  6. namespace SCTL_NAMESPACE {
  7. template <class Real> Real atoreal(const char* str);
  8. template <class Real> inline Real const_pi() { return (Real)3.1415926535897932384626433832795028841L; }
  9. template <class Real> inline Real const_e() { return (Real)2.7182818284590452353602874713526624977L; }
  10. template <class Real> inline Real fabs(const Real a) { return (Real)::fabs(a); }
  11. template <class Real> inline Real sqrt(const Real a) { return (Real)::sqrt(a); }
  12. template <class Real> inline Real sin(const Real a) { return (Real)::sin(a); }
  13. template <class Real> inline Real cos(const Real a) { return (Real)::cos(a); }
  14. template <class Real> inline Real exp(const Real a) { return (Real)::exp(a); }
  15. template <class Real> inline Real log(const Real a) { return (Real)::log(a); }
  16. template <class Real> inline Real pow(const Real b, const Real e) { return (Real)::pow(b, e); }
  17. template <Integer N, class T> constexpr T pow(const T& x) { return N > 1 ? x * pow<(N - 1) * (N > 1)>(x) : N < 0 ? T(1) / pow<(-N) * (N < 0)>(x) : N == 1 ? x : T(1); }
  18. } // end namespace
  19. #ifdef SCTL_QUAD_T
  20. namespace SCTL_NAMESPACE {
  21. typedef SCTL_QUAD_T QuadReal;
  22. inline std::ostream& operator<<(std::ostream& output, const QuadReal q_);
  23. }
  24. inline std::ostream& operator<<(std::ostream& output, const SCTL_QUAD_T q_);
  25. #endif // SCTL_QUAD_T
  26. #include SCTL_INCLUDE(math_utils.txx)
  27. #endif //_SCTL_MATH_UTILS_HPP_