oILAB
Loading...
Searching...
No Matches
RationalApproximations.h
Go to the documentation of this file.
1
//
2
// Created by Nikhil Chandra Admal on 4/20/23.
3
//
4
5
#ifndef OILAB_RATIONALAPPROXIMATIONS_H
6
#define OILAB_RATIONALAPPROXIMATIONS_H
7
8
#include "
IntegerMath.h
"
9
#include "
Rational.h
"
10
#include "
Farey.h
"
11
12
namespace
oILAB
{
13
template
<
typename
IntScalarType>
class
RationalApproximations
{
14
public
:
15
double
number
;
16
double
tolerance
;
17
IntScalarType
max_denominator
;
18
std::vector<Rational<IntScalarType>>
approximations
;
19
20
RationalApproximations
(
double
number
,
int
max_denominator
,
double
tolerance
)
21
:
/* init */
number
(
number
),
22
/* init */
max_denominator
(
max_denominator
),
23
/* init */
tolerance
(
tolerance
) {
24
double
n = floor(
number
);
25
auto
seq =
farey
(
max_denominator
,
false
);
26
for
(
auto
p : seq) {
27
double
approx =
28
static_cast<
double
>
(p.first) /
static_cast<
double
>
(p.second);
29
if
(std::abs(
number
- n - approx) <=
tolerance
) {
30
p.first = p.first + n * p.second;
31
approximations
.push_back(
Rational<IntScalarType>
(p.first, p.second));
32
}
33
}
34
}
35
36
37
38
39
};
40
41
}
// namespace oILAB
42
#endif
//OILAB_RATIONALAPPROXIMATIONS_H
Farey.h
IntegerMath.h
Rational.h
oILAB::RationalApproximations
Definition
RationalApproximations.h:13
oILAB::RationalApproximations::approximations
std::vector< Rational< IntScalarType > > approximations
Definition
RationalApproximations.h:18
oILAB::RationalApproximations::max_denominator
IntScalarType max_denominator
Definition
RationalApproximations.h:17
oILAB::RationalApproximations::number
double number
Definition
RationalApproximations.h:15
oILAB::RationalApproximations::tolerance
double tolerance
Definition
RationalApproximations.h:16
oILAB::RationalApproximations::RationalApproximations
RationalApproximations(double number, int max_denominator, double tolerance)
Definition
RationalApproximations.h:20
oILAB
Definition
BiCrystal.cpp:13
oILAB::farey
std::vector< std::pair< int, int > > farey(int limit, const bool firstQuadrant)
Definition
Farey.cpp:5
oILAB::Rational
Definition
Rational.h:14
include
Math
RationalApproximations.h
Generated on Sat Mar 28 2026 00:15:04 for oILAB by
1.9.8