#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include "DGtal/arithmetic/LighterSternBrocot.h"
#include "DGtal/base/StdRebinders.h"
Go to the source code of this file.
|
void | usage (int, char **argv) |
|
int | main (int argc, char **argv) |
|
- 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 approximation.
This file is part of the DGtal library.
Definition in file approximation.cpp.
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Main.
[approximation-types]
[approximation-types]
[approximation-process]
[approximation-process]
Definition at line 73 of file approximation.cpp.
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)
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
Point::Coordinate Integer
boost::int64_t int64_t
signed 94-bit integer.
Aim: The traits class for all models of Cinteger.
References DGtal::NumberTraitsImpl< std::decay< T >::type >::castToInt64_t(), and usage().
◆ usage()
void usage |
( |
int |
, |
|
|
char ** |
argv |
|
) |
| |
- Examples
- arithmetic/approximation.cpp, arithmetic/convergents-biginteger.cpp, arithmetic/convergents.cpp, arithmetic/extended-euclid.cpp, arithmetic/fraction.cpp, arithmetic/lower-integer-convex-hull.cpp, arithmetic/pattern.cpp, graph/volDistanceTraversal.cpp, math/polynomial-derivative.cpp, math/polynomial2-derivative.cpp, shapes/viewMarchingCubes.cpp, shapes/viewPolygonalMarchingCubes.cpp, topology/trackImplicitPolynomialSurfaceToOFF.cpp, topology/volBreadthFirstTraversal.cpp, topology/volMarchingCubes.cpp, topology/volScanBoundary.cpp, topology/volToOFF.cpp, and topology/volTrackBoundary.cpp.
Definition at line 64 of file approximation.cpp.
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;
Referenced by main().