Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <array>
#include "ratio.h"
template <
class A_, class B_, class C_,
class D_, class E_, class F_,
class G_, class H_, class I_
>
struct RatioMatrix {
using A = A_;
using B = B_;
using C = C_;
using D = D_;
using E = E_;
using F = F_;
using G = G_;
using H = H_;
using I = I_;
using Determinant = RatioSubtract<
RatioAdd<
RatioMultiply<A, E, I>,
RatioMultiply<B, F, G>,
RatioMultiply<C, D, H>
>,
RatioMultiply<C, E, G>,
RatioMultiply<B, D, I>,
RatioMultiply<A, F, H>
>;
using Inverse = RatioMatrix<
RatioDivide<
RatioSubtract<
RatioMultiply<E, I>,
RatioMultiply<F, H>
>,
Determinant
>,
RatioDivide<
RatioNegate<RatioSubtract<
RatioMultiply<B, I>,
RatioMultiply<C, H>
>>,
Determinant
>,
RatioDivide<
RatioSubtract<
RatioMultiply<B, F>,
RatioMultiply<C, E>
>,
Determinant
>,
RatioDivide<
RatioNegate<RatioSubtract<
RatioMultiply<D, I>,
RatioMultiply<F, G>
>>,
Determinant
>,
RatioDivide<
RatioSubtract<
RatioMultiply<A, I>,
RatioMultiply<C, G>
>,
Determinant
>,
RatioDivide<
RatioNegate<RatioSubtract<
RatioMultiply<A, F>,
RatioMultiply<C, D>
>>,
Determinant
>,
RatioDivide<
RatioSubtract<
RatioMultiply<D, H>,
RatioMultiply<E, G>
>,
Determinant
>,
RatioDivide<
RatioNegate<RatioSubtract<
RatioMultiply<A, H>,
RatioMultiply<B, G>
>>,
Determinant
>,
RatioDivide<
RatioSubtract<
RatioMultiply<A, E>,
RatioMultiply<B, D>
>,
Determinant
>
>;
template <class T>
static constexpr std::array<T, 9> array() {
return std::array<T, 9>{{
static_cast<T>(A::num) / A::den,
static_cast<T>(B::num) / B::den,
static_cast<T>(C::num) / C::den,
static_cast<T>(D::num) / D::den,
static_cast<T>(E::num) / E::den,
static_cast<T>(F::num) / F::den,
static_cast<T>(G::num) / G::den,
static_cast<T>(H::num) / H::den,
static_cast<T>(I::num) / I::den
}};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.