DGtal  1.5.beta
fraction.cpp File Reference
#include <iostream>
#include "DGtal/arithmetic/LighterSternBrocot.h"
Include dependency graph for fraction.cpp:

Go to the source code of this file.

Functions

void usage (int, char **argv)
 
int main (int argc, char **argv)
 

Detailed Description

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2012/02/06

An example file named fraction.

This file is part of the DGtal library.

Definition in file fraction.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Main.

[fraction-types]

[fraction-types]

[fraction-from-quotients]

[fraction-from-quotients]

Definition at line 49 of file fraction.cpp.

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 }
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
void usage(int, char **argv)
Definition: fraction.cpp:40
boost::int64_t int64_t
signed 94-bit integer.
Definition: BasicTypes.h:74

References usage().

◆ usage()

void usage ( int  ,
char **  argv 
)

Definition at line 40 of file fraction.cpp.

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 }

Referenced by main().