12 m_approximateOutputText(),
14 m_inputLayout(nullptr),
15 m_exactOutput(nullptr),
16 m_exactOutputLayout(nullptr),
17 m_approximateOutput(nullptr),
18 m_approximateOutputLayout(nullptr)
22 Calculation::~Calculation() {
23 if (m_inputLayout !=
nullptr) {
25 m_inputLayout =
nullptr;
27 if (m_input !=
nullptr) {
31 if (m_exactOutput !=
nullptr) {
33 m_exactOutput =
nullptr;
35 if (m_exactOutputLayout !=
nullptr) {
36 delete m_exactOutputLayout;
37 m_exactOutputLayout =
nullptr;
39 if (m_approximateOutput !=
nullptr) {
40 delete m_approximateOutput;
41 m_approximateOutput =
nullptr;
43 if (m_approximateOutputLayout !=
nullptr) {
44 delete m_approximateOutputLayout;
45 m_approximateOutputLayout =
nullptr;
50 const char * otherInputText = other.m_inputText;
51 const char * otherExactOutputText = other.m_exactOutputText;
52 const char * otherApproximateOutputText = other.m_approximateOutputText;
54 strlcpy(m_inputText, otherInputText,
sizeof(m_inputText));
55 strlcpy(m_exactOutputText, otherExactOutputText,
sizeof(m_exactOutputText));
56 strlcpy(m_approximateOutputText, otherApproximateOutputText,
sizeof(m_approximateOutputText));
60 void Calculation::reset() {
62 m_exactOutputText[0] = 0;
63 m_approximateOutputText[0] = 0;
69 m_input = Expression::parse(
c);
73 m_input->writeTextInBuffer(m_inputText,
sizeof(m_inputText));
74 m_exactOutput = Expression::ParseAndSimplify(m_inputText, *context);
75 m_exactOutput->writeTextInBuffer(m_exactOutputText,
sizeof(m_exactOutputText));
76 m_approximateOutput = m_exactOutput->approximate<
double>(*context);
77 m_approximateOutput->writeTextInBuffer(m_approximateOutputText,
sizeof(m_approximateOutputText));
80 const char * Calculation::inputText() {
84 const char * Calculation::exactOutputText() {
85 return m_exactOutputText;
88 const char * Calculation::approximateOutputText() {
89 return m_approximateOutputText;
93 if (m_input ==
nullptr) {
94 m_input = Expression::parse(m_inputText);
100 if (m_inputLayout ==
nullptr && input() !=
nullptr) {
103 return m_inputLayout;
106 bool Calculation::isEmpty() {
114 if (
strlen(m_approximateOutputText) == 0) {
120 void Calculation::tidy() {
121 if (m_input !=
nullptr) {
125 if (m_inputLayout !=
nullptr) {
126 delete m_inputLayout;
128 m_inputLayout =
nullptr;
129 if (m_exactOutput !=
nullptr) {
130 delete m_exactOutput;
132 m_exactOutput =
nullptr;
133 if (m_exactOutputLayout !=
nullptr) {
134 delete m_exactOutputLayout;
136 m_exactOutputLayout =
nullptr;
137 if (m_approximateOutput !=
nullptr) {
138 delete m_approximateOutput;
140 m_approximateOutput =
nullptr;
141 if (m_approximateOutputLayout !=
nullptr) {
142 delete m_approximateOutputLayout;
144 m_approximateOutputLayout =
nullptr;
148 if (m_exactOutput ==
nullptr) {
151 m_exactOutput = Expression::ParseAndSimplify(m_exactOutputText, *context);
153 return m_exactOutput;
157 if (m_exactOutputLayout ==
nullptr && exactOutput(context) !=
nullptr) {
158 m_exactOutputLayout = exactOutput(context)->createLayout();
160 return m_exactOutputLayout;
164 if (m_approximateOutput ==
nullptr) {
167 Expression *
exp = Expression::parse(m_approximateOutputText);
168 if (
exp !=
nullptr) {
169 m_approximateOutput =
exp->approximate<
double>(*context);
175 return m_approximateOutput;
179 if (m_approximateOutputLayout ==
nullptr && approximateOutput(context) !=
nullptr) {
180 m_approximateOutputLayout = approximateOutput(context)->createLayout();
182 return m_approximateOutputLayout;
185 bool Calculation::shouldDisplayApproximateOutput(
Context * context) {
186 if (
strcmp(m_exactOutputText, m_approximateOutputText) == 0) {
189 if (
strcmp(m_exactOutputText, m_inputText) == 0) {
192 return input()->isApproximate(*context);
196 char buffer[k_printedExpressionSize];
197 approximateOutput(context)->writeTextInBuffer(buffer, k_printedExpressionSize, Preferences::sharedPreferences()->numberOfSignificantDigits());
203 Expression * approximateOutput = Expression::ParseAndSimplify(buffer, *context);
204 bool isEqual = approximateOutput->
isIdenticalTo(exactOutput(context));
205 delete approximateOutput;
size_t strlcpy(char *dst, const char *src, size_t len)
constexpr Expression::ComplexFormat Cartesian
size_t strlen(const char *s)
bool isIdenticalTo(const Expression *e) const
int strcmp(const char *s1, const char *s2)