wuzp
Wrong Unit? Zero Points! Compile-time checks for units, coordinate systems and points vs. vectors.
Loading...
Searching...
No Matches
Rational.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "wuzp/core/internal/rational_operations.hpp"
5
6namespace wuzp {
7
8template <int DividendV_, int DivisorV_>
9using Rational = typename internal::ReduceRational<DividendV_, DivisorV_>::type;
10
11template <int DividendV_, int DivisorV_>
12struct Identity<internal::ReducedRational<DividendV_, DivisorV_>> {
13 using type = Rational<1, 1>;
14};
15
16template <int DividendLhsV_, int DivisorLhsV_, int DividendRhsV_, int DivisorRhsV_>
17struct Sum<internal::ReducedRational<DividendLhsV_, DivisorLhsV_>, internal::ReducedRational<DividendRhsV_, DivisorRhsV_>> {
18 using type = Rational<DividendLhsV_ * DivisorRhsV_ + DividendRhsV_ * DivisorLhsV_, DivisorLhsV_ * DivisorRhsV_>;
19};
20
21template <int DividendLhsV_, int DivisorLhsV_, int DividendRhsV_, int DivisorRhsV_>
22struct Difference<internal::ReducedRational<DividendLhsV_, DivisorLhsV_>, internal::ReducedRational<DividendRhsV_, DivisorRhsV_>> {
23 using type = Rational<DividendLhsV_ * DivisorRhsV_ - DividendRhsV_ * DivisorLhsV_, DivisorLhsV_ * DivisorRhsV_>;
24};
25
26template <int DividendV_, int DivisorV_>
27struct Negation<internal::ReducedRational<DividendV_, DivisorV_>> {
28 using type = Rational<-DividendV_, DivisorV_>;
29};
30
31template <int DividendLhsV_, int DivisorLhsV_, int DividendRhsV_, int DivisorRhsV_>
32struct Product<internal::ReducedRational<DividendLhsV_, DivisorLhsV_>, internal::ReducedRational<DividendRhsV_, DivisorRhsV_>> {
33 using type = Rational<DividendLhsV_ * DividendRhsV_, DivisorLhsV_ * DivisorRhsV_>;
34};
35
36template <int DividendLhsV_, int DivisorLhsV_, int DividendRhsV_, int DivisorRhsV_>
37struct Division<internal::ReducedRational<DividendLhsV_, DivisorLhsV_>, internal::ReducedRational<DividendRhsV_, DivisorRhsV_>> {
38 using type = Rational<DividendLhsV_ * DivisorRhsV_, DivisorLhsV_ * DividendRhsV_>;
39};
40
41// The result of an arbitrary rational powered by another arbitrary rational can be a real number which cannot be expressed as rational.
42// Therefore, only powers of zero are defined, which are zero for every positive exponent.
43template <int DividendExponentV_, int DivisorExponentV_>
44struct Power<internal::ReducedRational<0, 1>, internal::ReducedRational<DividendExponentV_, DivisorExponentV_>> {
45 static_assert(DividendExponentV_ > 0, "Zero raised to a non-positive power is not defined.");
46 using type = Rational<0, 1>;
47};
48
49template <int DividendV_, int DivisorV_>
50struct Inverse<internal::ReducedRational<DividendV_, DivisorV_>> {
52};
53
54} // namespace wuzp
typename internal::ReduceRational< DividendV_, DivisorV_ >::type Rational
Definition Rational.hpp:9
The inverse: the matrix inverse of a matrix, like Eigen's MatrixBase::inverse(), and the reciprocal o...
Definition traits.hpp:188
The negation is performed elementwise.
Definition traits.hpp:101