1 #ifndef PhysicsTools_Utilities_Fraction_h 2 #define PhysicsTools_Utilities_Fraction_h 6 #include <boost/integer/common_factor.hpp> 10 template<
int n,
int m>
12 static_assert(
m != 0);
15 operator double()
const {
return double(
n) / double (
m); }
17 double operator()(
double,
double)
const {
return double(
n) / double (
m); }
21 int num =
n / gcd,
int den =
m / gcd>
26 template<
int n,
int m,
unsigned gcd,
int num>
31 template<
int n,
int m,
bool pn = (n >= 0),
bool pm = (
m >= 0)>
36 template<
int n,
int m>
42 template<
int n,
int m>
50 template<
int n,
int m>
55 template<
int n,
int m>
60 template<
int n,
int m>
65 template<
int a,
int b,
int c>
69 return fract<a * b, c>();
73 template<
int a,
int b,
int c>
77 return fract<a * b, c>();
81 template<
int a,
int b,
int c>
85 return fract<a * c, b>();
89 template<
int a,
int b,
int c>
93 return fract<a * c + b, b>();
97 template<
int a,
int b,
int c>
105 template<
int a,
int b,
int c>
109 return fract<a * c + b, b>();
113 template<
int a,
int b,
int c>
117 return fract<b, a * c>();
121 template<
int a,
int b,
int c,
int d>
125 return fract<a * d + c * b, b * d>();
129 template<
int a,
int b,
int c,
int d>
137 template<
int a,
int b,
int c,
int d>
141 return fract<a * c, b * d>();
145 template<
int a,
int b,
int c,
int d>
149 return fract<a * d, b * c>();
Fraction< a *c, b >::type type
const Numerical< n > & num()
Fraction< a *c-b, b >::type type
static type combine(const Numerical< a > &, const FractionStruct< b, c > &)
static type combine(const Numerical< a > &, const FractionStruct< b, c > &)
static type combine(const FractionStruct< b, c > &, const Numerical< a > &)
Minus< typename PositiveFraction<-n, m >::type >::type type
FractionStruct< num, den > type
static const int denominator
static type combine(const Numerical< n > &, const Numerical< m > &)
static type combine(const Numerical< a > &, const FractionStruct< b, c > &)
static type combine(const Numerical< a > &, const FractionStruct< b, c > &)
static type combine(const FractionStruct< a, b > &, const FractionStruct< c, d > &)
Minus< typename PositiveFraction<-n,-m >::type >::type type
Fraction< a *c, b *d >::type type
Fraction< a *d+c *b, b *d >::type type
PositiveFraction< n, m >::type type
Fraction< a *d, b *c >::type type
Fraction< b, a *c >::type type
const Fraction< n, m >::type & fract()
static const int numerator
Fraction< a *b, c >::type type
static type combine(const FractionStruct< a, b > &, const FractionStruct< c, d > &)
static type combine(const FractionStruct< a, b > &, const FractionStruct< c, d > &)
double operator()(double, double) const
Fraction< a *c+b, b >::type type
Fraction< n, m >::type type
Minus< typename PositiveFraction< n,-m >::type >::type type
static type combine(const FractionStruct< a, b > &, const FractionStruct< c, d > &)
Fraction< a *b, c >::type type
Fraction< a *d-c *b, b *d >::type type
double operator()() const
static type combine(const FractionStruct< b, c > &, const Numerical< a > &)
double operator()(double) const
static type combine(const FractionStruct< b, c > &, const Numerical< a > &)
Fraction< a *c+b, b >::type type