DGtal 1.3.0
Loading...
Searching...
No Matches
fraction.cpp
Go to the documentation of this file.
1
30#include <iostream>
31#include "DGtal/arithmetic/LighterSternBrocot.h"
33
35
36using namespace DGtal;
37
39
40void usage( int, char** argv )
41{
42 std::cerr << "Usage: " << argv[ 0 ] << " <u_0> <u_1> ... <u_k>" << std::endl;
43 std::cerr << "\t - computes the fraction [u_0; u_1, ..., u_k] from its partial quotients." << std::endl;
44}
45
49int main( int argc, char** argv )
50{
51 if ( argc < 3 )
52 {
53 usage( argc, argv );
54 return 1;
55 }
56
58 typedef DGtal::int64_t Integer;
59 typedef DGtal::int64_t Quotient;
60 typedef LighterSternBrocot<Integer, Quotient, StdMapRebinder> SB; // the type of the Stern-Brocot tree
61 typedef SB::Fraction Fraction; // the type for fractions
62 typedef std::back_insert_iterator< Fraction > OutputIterator;
64
66 Fraction f;
67 OutputIterator itback = std::back_inserter( f );
68 for ( Quotient i = 1; i < argc; ++i)
69 {
70 Quotient u = atoll( argv[ i ] );
71 *itback++ = std::make_pair( u, i-1 );
72 }
73 std::cout << "z = " << f.p() << " / " << f.q() << std::endl;
75 return 0;
76}
77
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
Definition: BasicTypes.h:74
int main()
Definition: testBits.cpp:56