Last active
December 27, 2015 07:39
-
-
Save m-ou-se/7291008 to your computer and use it in GitHub Desktop.
std::ratio_power
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename R, int p> | |
struct ratio_power { | |
private: | |
using S = typename std::ratio_multiply<R, R>::type; | |
public: | |
using type = typename std::ratio_multiply< | |
typename ratio_power<R, p%2>::type, | |
typename ratio_power<S, p/2>::type | |
>::type; | |
constexpr static intmax_t num = type::num; | |
constexpr static intmax_t den = type::den; | |
}; | |
template<typename R> | |
struct ratio_power<R, 0> { | |
using type = std::ratio<1>; | |
constexpr static intmax_t num = type::num; | |
constexpr static intmax_t den = type::den; | |
}; | |
template<typename R> | |
struct ratio_power<R, 1> { | |
using type = R; | |
constexpr static intmax_t num = type::num; | |
constexpr static intmax_t den = type::den; | |
}; | |
template<typename R> | |
struct ratio_power<R, -1> { | |
using type = typename std::ratio_divide<std::ratio<1>, R>::type; | |
constexpr static intmax_t num = type::num; | |
constexpr static intmax_t den = type::den; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment