DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
fraction.cpp
Go to the documentation of this file.
1
13
27
30
#include <iostream>
31
#include "DGtal/arithmetic/LighterSternBrocot.h"
33
35
36
using namespace
DGtal
;
37
39
40
void
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
49
int
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
}
DGtal::LighterSternBrocot
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
Definition
LighterSternBrocot.h:109
Integer
Point::Coordinate Integer
Definition
examplePlaneProbingParallelepipedEstimator.cpp:44
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::int64_t
std::int64_t int64_t
signed 94-bit integer.
Definition
BasicTypes.h:73
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
usage
void usage(int, char **argv)
Definition
testPolynomial.cpp:58
examples
arithmetic
fraction.cpp
Generated on
for DGtal by
1.18.0