1 #ifndef PhysicsTools_Utilities_Fraction_h
2 #define PhysicsTools_Utilities_Fraction_h
6 #include <boost/math/common_factor.hpp>
7 #include <boost/static_assert.hpp>
11 template<
int n,
int m>
16 operator double()
const {
return double(
n) / double (
m); }
18 double operator()(
double,
double)
const {
return double(
n) / double (
m); }
22 int num =
n / gcd,
int den =
m / gcd>
27 template<
int n,
int m,
unsigned gcd,
int num>
32 template<
int n,
int m,
bool pn = (n >= 0),
bool pm = (
m >= 0)>
37 template<
int n,
int m>
43 template<
int n,
int m>
51 template<
int n,
int m>
56 template<
int n,
int m>
61 template<
int n,
int m>
66 template<
int a,
int b,
int c>
70 return fract<a * b, c>();
74 template<
int a,
int b,
int c>
78 return fract<a * b, c>();
82 template<
int a,
int b,
int c>
86 return fract<a * c, b>();
90 template<
int a,
int b,
int c>
94 return fract<a * c + b, b>();
98 template<
int a,
int b,
int c>
106 template<
int a,
int b,
int c>
110 return fract<a * c + b, b>();
114 template<
int a,
int b,
int c>
118 return fract<b, a * c>();
122 template<
int a,
int b,
int c,
int d>
126 return fract<a * d + c * b, b * d>();
130 template<
int a,
int b,
int c,
int d>
138 template<
int a,
int b,
int c,
int d>
142 return fract<a * c, b * d>();
146 template<
int a,
int b,
int c,
int d>
150 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
BOOST_STATIC_ASSERT(m!=0)
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