-
Notifications
You must be signed in to change notification settings - Fork 0
/
parallel_series.hpp
102 lines (85 loc) · 1.35 KB
/
parallel_series.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma once
#include <string>
struct Delta {
double a, b, c;
};
struct Star {
double a, b, c;
};
struct METRIC_PREFIX {
const char *symbol;
const char *name;
int8_t exponent; // base 10
};
const METRIC_PREFIX PREFIXES[] = {
{
.symbol = "T",
.name = "tera",
.exponent = 12
},
{
.symbol = "G",
.name = "giga",
.exponent = 9
},
{
.symbol = "M",
.name = "mega",
.exponent = 6
},
{
.symbol = "k",
.name = "kilo",
.exponent = 3
},
{
.symbol = "m",
.name = "milli",
.exponent = -3
},
{
.symbol = "u",
.name = "micro",
.exponent = -6
},
{
.symbol = "n",
.name = "nano",
.exponent = -9
},
{
.symbol = "p",
.name = "pico",
.exponent = -12
},
};
class ParallelSeries {
public:
ParallelSeries();
~ParallelSeries();
double solve();
void reset();
std::string expr; // expression
double (*onParallel)(double, double);
double (*onSeries)(double, double);
Star deltaStarTransform(Delta);
private:
double primary();
void getToken();
void error(std::string);
// lexer token types
enum {
CHARS = 0, NUMBER = 1,
SERIES = '+', PARALLEL = 2,
LP = '(', RP = ')'
};
struct Lexer {
size_t index;
struct Token {
uint8_t type;
std::string value;
} token;
bool fail;
bool busy;
} lexer;
};