aGrUM  0.16.0
rational.h
Go to the documentation of this file.
1 
29 #ifndef GUM_RATIONAL_H
30 #define GUM_RATIONAL_H
31 
32 #include <iomanip>
33 #include <iostream>
34 #include <sstream>
35 #include <stdlib.h>
36 #include <vector>
37 #include <agrum/core/math/math.h>
38 
39 // 64 bits for windows (long is 32 bits)
40 #ifdef _MSC_VER
41 typedef __int64 int64_t;
42 typedef unsigned __int64 uint64_t;
43 #else
44 # include <stdint.h>
45 #endif
46 
47 namespace gum {
48 
58  template < typename GUM_SCALAR >
59  class Rational {
60  public:
61  // ========================================================================
63  // ========================================================================
65 
83  static void farey(int64_t& numerator,
84  int64_t& denominator,
85  const GUM_SCALAR& number,
86  const int64_t& den_max = 1000000L,
87  const GUM_SCALAR& zero = 1e-6);
88 
110  static void continuedFracFirst(int64_t& numerator,
111  int64_t& denominator,
112  const GUM_SCALAR& number,
113  const double& zero = 1e-6);
114 
131  static void continuedFracBest(int64_t& numerator,
132  int64_t& denominator,
133  const GUM_SCALAR& number,
134  const int64_t& den_max = 1000000);
135 
137  };
138 
139 } // namespace gum
140 
141 
142 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
143 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
144 extern template class gum::Rational< double >;
145 # endif
146 #endif
147 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
148 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
149 extern template class gum::Rational< long double >;
150 # endif
151 #endif
152 
153 
154 // Always include template implementation in header file
156 
157 #endif // GUM_RATIONAL_H
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
static void continuedFracBest(int64_t &numerator, int64_t &denominator, const GUM_SCALAR &number, const int64_t &den_max=1000000)
Find the best rational approximation.
Definition: rational_tpl.h:192
Class template used to approximate decimal numbers by rationals.
Definition: rational.h:59
static void farey(int64_t &numerator, int64_t &denominator, const GUM_SCALAR &number, const int64_t &den_max=1000000L, const GUM_SCALAR &zero=1e-6)
Find the rational close enough to a given ( decimal ) number in [-1,1] and whose denominator is not h...
Definition: rational_tpl.h:36
static void continuedFracFirst(int64_t &numerator, int64_t &denominator, const GUM_SCALAR &number, const double &zero=1e-6)
Find the first best rational approximation.
Definition: rational_tpl.h:95
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.