54 #include "DGtal/arithmetic/LighterSternBrocot.h"
55 #include "DGtal/base/StdRebinders.h"
60 using namespace DGtal;
66 std::cerr <<
"Usage: " << argv[ 0 ] <<
" <floating point number>" << std::endl;
67 std::cerr <<
"\t - computes the successive rational approximation of this number, up to a precision of 1e-14." << std::endl;
73 int main(
int argc,
char** argv )
85 typedef SB::Fraction Fraction;
86 typedef std::back_insert_iterator< Fraction > OutputIterator;
90 long double epsilon = 1e-14;
91 long double number0 = strtold( argv[ 1 ], 0 );
92 long double number = number0;
93 ASSERT( number >= 0.0 );
95 OutputIterator itback = std::back_inserter( f );
99 long double int_part = floorl( number );
101 *itback++ = std::make_pair( u, i++ );
105 std::cout <<
"z = " << f.p() <<
" / " << f.q()
106 <<
" =~ " << std::setprecision( 16 ) << approx << std::endl;
108 if ( ( (number0 - epsilon ) < approx )
109 && ( approx < (number0 + epsilon ) ) )
break;
110 number = 1.0 / number;
112 std::cout <<
"z = " << f.p() <<
" / " << f.q() << std::endl;
void usage(int, char **argv)
int main(int argc, char **argv)
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
Point::Coordinate Integer
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
static DGtal::int64_t castToInt64_t(const std::decay< T >::type &aT)
Cast method to DGtal::int64_t (for I/O or board export uses only).
Aim: The traits class for all models of Cinteger.