-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringtoDouble.h
78 lines (57 loc) · 2 KB
/
StringtoDouble.h
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
#ifndef STRINGTODOUBLE_H
#define STRINGTODOUBLE_H
#include <string>
#include <inttypes.h>
#include "int_96.h"
/*******************************************************************************
prepNumber
helper class storing the x * 10 ^ (y) number
*******************************************************************************/
class prepNumber{
public:
prepNumber();
bool negative; // negative flag for the negative
int32_t exponent; // store the exponent of the numnber v= 10^e * x e (-327:308)
uint64_t mantissa; // x in the above form
};
/*******************************************************************************
Parser
parses the string into prepNumber
*******************************************************************************/
class Parser{
public:
Parser();
prepNumber run(std::string init_string);
int get_machine_state();
int get_parser_state();
static int const PARSER_OK = 0;
static int const PARSER_PZERO = 1;
static int const PARSER_MZERO = 2;
static int const PARSER_PINF = 3;
static int const PARSER_MINF = 4;
private:
/*state machine states*/
static int const FSM_A = 0;
static int const FSM_B = 1;
static int const FSM_C = 2;
static int const FSM_D = 3;
static int const FSM_E = 4;
static int const FSM_F = 5;
static int const FSM_G = 6;
static int const FSM_H = 7;
static int const FSM_I = 8;
static int const FSM_STOP = 9;
int state;
int parser_state;
};
/*******************************************************************************
conveerter
converts the number into the double
*******************************************************************************/
double converter(prepNumber pn);
/*******************************************************************************
stod
wrapping function dealing with parse errors
*******************************************************************************/
double stod(std::string init_string);
#endif // STRINGTODOUBLE_H