Computes the quotients and the convergents of a given fraction.
- See also
- Instantiating fractions
# Approximations of pi
$ ./examples/arithmetic/convergents 103993 33102
z = [3,7,15,1,292]
z_0 = 3 / 1
z_1 = 22 / 7
z_2 = 333 / 106
z_3 = 355 / 113
z_4 = 103993 / 33102
#include <iostream>
#include "DGtal/arithmetic/LighterSternBrocot.h"
void usage(
int,
char** argv )
{
std::cerr << "Usage: " << argv[ 0 ] << " <p> <q>" << std::endl;
std::cerr << "\t - computes the successive convergent of the fraction p / q." << std::endl;
}
int main(
int argc,
char** argv )
{
if ( argc < 3 )
{
return 1;
}
typedef LighterSternBrocot<DGtal::int64_t, DGtal::int64_t, StdMapRebinder> SB;
typedef SB::Fraction Fraction;
Fraction f( p, q );
std::cout << "z = ";
{
std::cout << ( ( it == itbegin ) ? "[" : "," )
<< u.first;
}
std::cout << "]" << std::endl;
Fraction g;
{
std::cout << "z_" << u.second << " = ";
g.push_back( u );
std::cout << g.p() << " / " << g.q() << std::endl;
}
return 0;
}
void usage(int, char **argv)
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
int main(int argc, char **argv)