30 template<std::
intmax_t Num, std::
intmax_t Denom = 1>
31 struct C: std::ratio<Num, Denom> {
32 operator double()
const {
33 return double(Num) / double(Denom);
39 template<
class stdratio>
46 template<
class T>
struct is_C {
static const bool value =
false; };
48 template<std::
intmax_t N, std::
intmax_t D>
struct is_C<
C<
N,D> > {
static const bool value =
true; };
62 template<std::
intmax_t Num, std::
intmax_t Denom>
63 inline std::ostream& operator<<(std::ostream& os, const C<Num, Denom>) {
71 inline std::ostream& operator<<(std::ostream& os, const C<1,4>) {
77 inline std::ostream& operator<<(std::ostream& os, const C<1,2>) {
82 inline std::ostream& operator<<(std::ostream& os, const C<3,4>) {
87 inline std::ostream&
operator<<(std::ostream& os,
const pi) { os <<
"π";
return os; }
89 inline std::ostream&
operator<<(std::ostream& os,
const e) { os <<
"e";
return os; }
108 template<std::
intmax_t n1, std::
intmax_t d1, std::
intmax_t n2, std::
intmax_t d2>
111 template<std::
intmax_t n1, std::
intmax_t d1, std::
intmax_t n2, std::
intmax_t d2>
114 template<std::
intmax_t n1, std::
intmax_t d1, std::
intmax_t n2, std::
intmax_t d2>
117 template<std::
intmax_t n1, std::
intmax_t d1, std::
intmax_t n2, std::
intmax_t d2>
120 template<std::
intmax_t n1, std::
intmax_t d1, std::
intmax_t n2, std::
intmax_t d2>
122 {
return std::ratio_equal<std::ratio<n1, d1>, std::ratio<n2, d2> >::value; }
124 template<class T, typename = typename std::enable_if<!is_C<T>::value>::type>
126 template<class T, typename = typename std::enable_if<!is_C<T>::value>::type>
128 template<class T, typename = typename std::enable_if<!is_C<T>::value>::type>
130 template<class T, typename = typename std::enable_if<!is_C<T>::value>::type>
132 template<class T, typename = typename std::enable_if<!is_C<T>::value>::type>
134 template<class T, typename = typename std::enable_if<!is_C<T>::value>::type>
137 template<class T, typename = typename std::enable_if<!is_C<T>::value>::type>
139 template<class T, typename = typename std::enable_if<!is_C<T>::value>::type>
152 inline std::ostream& operator<<(std::ostream& os, const std::complex<T>& c) {
154 return (os << c.real());
156 return (os <<
"(" <<c.real() <<
" - " <<
std::abs(c.imag()) <<
"i)");
157 return (os <<
"(" <<c.real() <<
" + " << c.imag() <<
"i)");
160 template<
class C_arg,
class factor,
class offset = std::ratio<0> >
162 static const bool value = (std::ratio_divide<std::ratio_subtract<std::ratio<C_arg::num, C_arg::den>, std::ratio<offset::num, offset::den> >, std::ratio<factor::num, factor::den> >::den == 1);
166 template<std::intmax_t num, std::intmax_t den,
167 typename =
typename std::enable_if<is_whole_factor<std::ratio<num, den>, pi>::value>::type>
170 template<std::intmax_t num, std::intmax_t den,
171 typename =
typename std::enable_if<is_whole_factor<std::ratio<num, den>,
pi, decltype(
pi() /
C<2>())>::value>::type>
174 template<std::intmax_t num, std::intmax_t den,
175 typename =
typename std::enable_if<is_whole_factor<std::ratio<num, den>, pi>::value>::type>
178 template<std::intmax_t num, std::intmax_t den,
179 typename =
typename std::enable_if<is_whole_factor<std::ratio<num, den>,
pi, decltype(
pi() /
C<2>())>::value>::type>
182 template<std::
intmax_t num, std::
intmax_t den>
185 template<std::
intmax_t num, std::
intmax_t den>
188 template<std::
intmax_t num, std::
intmax_t den>
189 constexpr
C<(1 - 2 * (num < 0)) * num, (1 - 2 * (den < 0)) * den>
abs(
const C<num, den>& a) {
return {}; }
A class which recursively inherits from itself to allow ambiguous function definition ordering...
detail::C_wrap< stator::constant_ratio::e >::type e
A symbolic/compile-time rational approximation of .
C< 0 > Null
A symbolic representation of zero.
auto N(const T &a) -> STATOR_AUTORETURN(simplify< NConfig >(a))
A variant of simplify that converts compile time symbols into numbers.
auto operator-(const Arg &l) -> STATOR_AUTORETURN(C<-1 >() *l) template< class LHS, class RHS, typename=typename std::enable_if< ApplySymbolicOps< LHS, RHS >::value >::type > auto operator+(const LHS &l, const RHS &r) -> STATOR_AUTORETURN((AddOp< decltype(store(l)), decltype(store(r))>(l, r))) template< class LHS, class RHS, typename=typename std::enable_if< ApplySymbolicOps< LHS, RHS >::value >::type > auto operator*(const LHS &l, const RHS &r) -> STATOR_AUTORETURN((MultiplyOp< decltype(store(l)), decltype(store(r))>(l, r))) template< class LHS, class RHS, typename=typename std::enable_if< ApplySymbolicOps< LHS, RHS >::value >::type > auto operator-(const LHS &l, const RHS &r) -> STATOR_AUTORETURN((SubtractOp< decltype(store(l)), decltype(store(r))>(l, r))) template< class LHS, class RHS, typename=typename std::enable_if< ApplySymbolicOps< LHS, RHS >::value >::type > auto operator/(const LHS &l, const RHS &r) -> STATOR_AUTORETURN((DivideOp< decltype(store(l)), decltype(store(r))>(l, r))) template< class LHS, class RHS, typename=typename std::enable_if< ApplySymbolicOps< LHS, RHS >::value >::type > auto pow(const LHS &l, const RHS &r) -> STATOR_AUTORETURN((PowerOp< decltype(store(l)), decltype(store(r))>(l, r)))
Symbolic unary negation operator.
C< i *Factorial< i - 1 >::value::num, 1 > value
constexpr bool operator==(const C< n1, d1 > &, const C< n2, d2 > &)
auto cos(const C< num, den > &a) -> STATOR_AUTORETURN(cos_Cimpl(a, detail::select_overload
A class representing a compile-time rational constant (i.e., std::ratio).
C< stdratio::num, stdratio::den > type
std::ostream & operator<<(std::ostream &os, const C< Num, Denom >)
Output operator for compile-time constant (C types).
constexpr auto operator/(C< n1, d1 >, C< n2, d2 >) -> STATOR_AUTORETURN((typename detail::C_wrap< std::ratio_divide< std::ratio< n1, d1 >, std::ratio< n2, d2 > > >::type()))
Arg operator+(const Arg &l)
Symbolic unary positive operator.
C< 1 > Unity
A symbolic representation of one.
constexpr auto operator*(C< n1, d1 >, C< n2, d2 >) -> STATOR_AUTORETURN((typename detail::C_wrap< std::ratio_multiply< std::ratio< n1, d1 >, std::ratio< n2, d2 > > >::type()))
detail::C_wrap< stator::constant_ratio::pi >::type pi
A symbolic/compile-time rational approximation of .
auto sin(const C< num, den > &a) -> STATOR_AUTORETURN(sin_Cimpl(a, detail::select_overload
#define STATOR_AUTORETURN(EXPR)
A convenience Macro for defining auto return type functions.
The stator symbolic math library.
constexpr Unity cos_Cimpl(const C< num, den > &a, detail::choice< 0 >)
Symbolic Factorial function.
constexpr C<(1 - 2 *(num< 0)) *num,(1 - 2 *(den< 0)) *den > abs(const C< num, den > &a)
C< Factorial< i >::value::den, Factorial< i >::value::num > value
Compile time type-test for compile-time constants C.
constexpr Null sin_Cimpl(const C< num, den > &a, detail::choice< 0 >)
A class used to start the ambiguous function definition ordering calculation.
Symbolic Inverse factorial function.
Conversion operator from std::ratio to C.