libqalculate-ruby 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Makefile +157 -0
- data/Rakefile +7 -0
- data/ext/libqalculate/BuiltinFunctions.h +261 -0
- data/ext/libqalculate/Calculator.h +1037 -0
- data/ext/libqalculate/DataSet.h +304 -0
- data/ext/libqalculate/ExpressionItem.h +289 -0
- data/ext/libqalculate/Function.h +766 -0
- data/ext/libqalculate/MathStructure.h +827 -0
- data/ext/libqalculate/Number.h +387 -0
- data/ext/libqalculate/Prefix.h +219 -0
- data/ext/libqalculate/Unit.h +300 -0
- data/ext/libqalculate/Variable.h +380 -0
- data/ext/libqalculate/includes.h +644 -0
- data/ext/libqalculate/qalculate.h +28 -0
- data/ext/libqalculate/util.h +88 -0
- data/ext/qalc_wrap.cxx +198164 -0
- data/extconf.rb +8 -0
- data/test/test_qalc.rb +40 -0
- metadata +71 -0
@@ -0,0 +1,644 @@
|
|
1
|
+
/*
|
2
|
+
Qalculate
|
3
|
+
|
4
|
+
Copyright (C) 2003-2007 Niklas Knutsson (nq@altern.org)
|
5
|
+
|
6
|
+
This program is free software; you can redistribute it and/or modify
|
7
|
+
it under the terms of the GNU General Public License as published by
|
8
|
+
the Free Software Foundation; either version 2 of the License, or
|
9
|
+
(at your option) any later version.
|
10
|
+
*/
|
11
|
+
|
12
|
+
#ifndef INCLUDES_H
|
13
|
+
#define INCLUDES_H
|
14
|
+
|
15
|
+
/** @file */
|
16
|
+
|
17
|
+
/// \cond
|
18
|
+
using namespace std;
|
19
|
+
/// \endcond
|
20
|
+
|
21
|
+
#include <vector>
|
22
|
+
#include <string>
|
23
|
+
#include <stack>
|
24
|
+
#include <list>
|
25
|
+
#include <errno.h>
|
26
|
+
#include <stddef.h>
|
27
|
+
#include <math.h>
|
28
|
+
#include <float.h>
|
29
|
+
#include <stdarg.h>
|
30
|
+
#include <stdlib.h>
|
31
|
+
#include <stdio.h>
|
32
|
+
#include <unistd.h>
|
33
|
+
|
34
|
+
|
35
|
+
#ifdef __GNUC__
|
36
|
+
# if __GNUC__ < 3
|
37
|
+
# include <hash_map.h>
|
38
|
+
namespace Sgi { using ::hash_map; }; // inherit globals
|
39
|
+
# else
|
40
|
+
# include <ext/hash_map>
|
41
|
+
# if __GNUC__ == 3 && __GNUC_MINOR__ == 0
|
42
|
+
namespace Sgi = std; // GCC 3.0
|
43
|
+
# else
|
44
|
+
namespace Sgi = ::__gnu_cxx; // GCC 3.1 and later
|
45
|
+
# endif
|
46
|
+
# endif
|
47
|
+
#else // ... there are other compilers, right?
|
48
|
+
namespace Sgi = std;
|
49
|
+
#endif
|
50
|
+
|
51
|
+
static string empty_string;
|
52
|
+
|
53
|
+
struct ExpressionName;
|
54
|
+
class Calculator;
|
55
|
+
class MathStructure;
|
56
|
+
class Manager;
|
57
|
+
class Unit;
|
58
|
+
class Variable;
|
59
|
+
class KnownVariable;
|
60
|
+
class UnknownVariable;
|
61
|
+
class Assumptions;
|
62
|
+
class DynamicVariable;
|
63
|
+
class ExpressionItem;
|
64
|
+
class Number;
|
65
|
+
class Prefix;
|
66
|
+
class DecimalPrefix;
|
67
|
+
class BinaryPrefix;
|
68
|
+
class NumberPrefix;
|
69
|
+
class CompositeUnit;
|
70
|
+
class AliasUnit;
|
71
|
+
class AliasUnit_Composite;
|
72
|
+
class MathFunction;
|
73
|
+
class Matrix;
|
74
|
+
class Vector;
|
75
|
+
class UserFunction;
|
76
|
+
class EqItem;
|
77
|
+
class EqNumber;
|
78
|
+
class EqContainer;
|
79
|
+
class Argument;
|
80
|
+
class DataSet;
|
81
|
+
class DataProperty;
|
82
|
+
class DataObject;
|
83
|
+
|
84
|
+
/// Type of ExpressionItem
|
85
|
+
typedef enum {
|
86
|
+
/// class Variable
|
87
|
+
TYPE_VARIABLE,
|
88
|
+
/// class MathFunction
|
89
|
+
TYPE_FUNCTION,
|
90
|
+
/// class Unit
|
91
|
+
TYPE_UNIT
|
92
|
+
} ExpressionItemType;
|
93
|
+
|
94
|
+
#define COMPARISON_MIGHT_BE_LESS_OR_GREATER(i) (i == COMPARISON_RESULT_UNKNOWN || i == COMPARISON_RESULT_NOT_EQUAL)
|
95
|
+
#define COMPARISON_NOT_FULLY_KNOWN(i) (i == COMPARISON_RESULT_UNKNOWN || i == COMPARISON_RESULT_NOT_EQUAL || i == COMPARISON_RESULT_EQUAL_OR_LESS || i == COMPARISON_RESULT_EQUAL_OR_GREATER)
|
96
|
+
#define COMPARISON_IS_EQUAL_OR_GREATER(i) (i == COMPARISON_RESULT_EQUAL || i == COMPARISON_RESULT_GREATER || i == COMPARISON_RESULT_EQUAL_OR_GREATER)
|
97
|
+
#define COMPARISON_IS_EQUAL_OR_LESS(i) (i == COMPARISON_RESULT_EQUAL || i == COMPARISON_RESULT_LESS || i == COMPARISON_RESULT_EQUAL_OR_LESS)
|
98
|
+
#define COMPARISON_IS_NOT_EQUAL(i) (i == COMPARISON_RESULT_NOT_EQUAL || i == COMPARISON_RESULT_LESS || i == COMPARISON_RESULT_GREATER)
|
99
|
+
#define COMPARISON_MIGHT_BE_EQUAL(i) (i == COMPARISON_RESULT_UNKNOWN || i == COMPARISON_RESULT_EQUAL_OR_LESS || i == COMPARISON_RESULT_EQUAL_OR_GREATER)
|
100
|
+
#define COMPARISON_MIGHT_BE_NOT_EQUAL(i) (i == COMPARISON_RESULT_UNKNOWN || i == COMPARISON_RESULT_EQUAL_OR_LESS || i == COMPARISON_RESULT_EQUAL_OR_GREATER)
|
101
|
+
|
102
|
+
#define NR_OF_PRIMES 174
|
103
|
+
|
104
|
+
static const int PRIMES[] = {
|
105
|
+
2, 3, 5, 7, 11, 13, 17, 19, 21, 23, 29, 31, 37, 41, 31, 37,
|
106
|
+
41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103,
|
107
|
+
107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167,
|
108
|
+
173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233,
|
109
|
+
239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307,
|
110
|
+
311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379,
|
111
|
+
383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449,
|
112
|
+
457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523,
|
113
|
+
541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607,
|
114
|
+
613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677,
|
115
|
+
683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761,
|
116
|
+
769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853,
|
117
|
+
857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937,
|
118
|
+
941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013
|
119
|
+
};
|
120
|
+
|
121
|
+
#define SQP_LT_1000 11
|
122
|
+
#define SQP_LT_2000 17
|
123
|
+
#define SQP_LT_10000 28
|
124
|
+
#define SQP_LT_25000 40
|
125
|
+
#define SQP_LT_100000 68
|
126
|
+
|
127
|
+
static const int SQUARE_PRIMES[] = {
|
128
|
+
4, 9, 25, 49, 121, 169, 289, 361, 441, 529,
|
129
|
+
841, 961, 1369, 1681, 961, 1369, 1681, 1849, 2209, 2809,
|
130
|
+
3481, 3721, 4489, 5041, 5329, 6241, 6889, 7921, 9409, 10201,
|
131
|
+
10609, 11449, 11881, 12769, 16129, 17161, 18769, 19321, 22201, 22801,
|
132
|
+
24649, 26569, 27889, 29929, 32041, 32761, 36481, 37249, 38809, 39601,
|
133
|
+
44521, 49729, 51529, 52441, 54289, 57121, 58081, 63001, 66049, 69169,
|
134
|
+
72361, 73441, 76729, 78961, 80089, 85849, 94249, 96721, 97969, 100489,
|
135
|
+
109561, 113569, 120409, 121801, 124609, 128881, 134689, 139129, 143641, 146689,
|
136
|
+
151321, 157609, 160801, 167281, 175561, 177241, 185761, 187489, 192721, 196249,
|
137
|
+
201601, 208849, 212521, 214369, 218089, 229441, 237169, 241081, 249001, 253009,
|
138
|
+
259081, 271441, 273529, 292681, 299209, 310249, 316969, 323761, 326041, 332929,
|
139
|
+
344569, 351649, 358801, 361201, 368449, 375769, 380689, 383161, 398161, 410881,
|
140
|
+
413449, 418609, 426409, 434281, 436921, 452929, 458329, 466489, 477481, 491401,
|
141
|
+
502681, 516961, 528529, 537289, 546121, 552049, 564001, 573049, 579121, 591361,
|
142
|
+
597529, 619369, 635209, 654481, 657721, 674041, 677329, 683929, 687241, 703921,
|
143
|
+
727609, 734449, 737881, 744769, 769129, 776161, 779689, 786769, 822649, 829921,
|
144
|
+
844561, 863041, 877969, 885481, 896809, 908209, 935089, 942841, 954529, 966289,
|
145
|
+
982081, 994009, 1018081, 1026169
|
146
|
+
};
|
147
|
+
|
148
|
+
/// The result of a comparison of two values
|
149
|
+
typedef enum {
|
150
|
+
COMPARISON_RESULT_EQUAL,
|
151
|
+
COMPARISON_RESULT_GREATER,
|
152
|
+
COMPARISON_RESULT_LESS,
|
153
|
+
COMPARISON_RESULT_EQUAL_OR_GREATER,
|
154
|
+
COMPARISON_RESULT_EQUAL_OR_LESS,
|
155
|
+
COMPARISON_RESULT_NOT_EQUAL,
|
156
|
+
COMPARISON_RESULT_UNKNOWN
|
157
|
+
} ComparisonResult;
|
158
|
+
|
159
|
+
/// Placement of legend
|
160
|
+
typedef enum {
|
161
|
+
PLOT_LEGEND_NONE,
|
162
|
+
PLOT_LEGEND_TOP_LEFT,
|
163
|
+
PLOT_LEGEND_TOP_RIGHT,
|
164
|
+
PLOT_LEGEND_BOTTOM_LEFT,
|
165
|
+
PLOT_LEGEND_BOTTOM_RIGHT,
|
166
|
+
PLOT_LEGEND_BELOW,
|
167
|
+
PLOT_LEGEND_OUTSIDE
|
168
|
+
} PlotLegendPlacement;
|
169
|
+
|
170
|
+
/// Plot type/style
|
171
|
+
typedef enum {
|
172
|
+
PLOT_STYLE_LINES,
|
173
|
+
PLOT_STYLE_POINTS,
|
174
|
+
PLOT_STYLE_POINTS_LINES,
|
175
|
+
PLOT_STYLE_BOXES,
|
176
|
+
PLOT_STYLE_HISTOGRAM,
|
177
|
+
PLOT_STYLE_STEPS,
|
178
|
+
PLOT_STYLE_CANDLESTICKS,
|
179
|
+
PLOT_STYLE_DOTS
|
180
|
+
} PlotStyle;
|
181
|
+
|
182
|
+
/// Smoothing a plotted lines
|
183
|
+
typedef enum {
|
184
|
+
PLOT_SMOOTHING_NONE,
|
185
|
+
PLOT_SMOOTHING_UNIQUE,
|
186
|
+
PLOT_SMOOTHING_CSPLINES,
|
187
|
+
PLOT_SMOOTHING_BEZIER,
|
188
|
+
PLOT_SMOOTHING_SBEZIER
|
189
|
+
} PlotSmoothing;
|
190
|
+
|
191
|
+
/// File type for saving plot to image
|
192
|
+
typedef enum {
|
193
|
+
PLOT_FILETYPE_AUTO,
|
194
|
+
PLOT_FILETYPE_PNG,
|
195
|
+
PLOT_FILETYPE_PS,
|
196
|
+
PLOT_FILETYPE_EPS,
|
197
|
+
PLOT_FILETYPE_LATEX,
|
198
|
+
PLOT_FILETYPE_SVG,
|
199
|
+
PLOT_FILETYPE_FIG
|
200
|
+
} PlotFileType;
|
201
|
+
|
202
|
+
/// Mathematical operations
|
203
|
+
typedef enum {
|
204
|
+
OPERATION_MULTIPLY,
|
205
|
+
OPERATION_DIVIDE,
|
206
|
+
OPERATION_ADD,
|
207
|
+
OPERATION_SUBTRACT,
|
208
|
+
OPERATION_RAISE,
|
209
|
+
OPERATION_EXP10,
|
210
|
+
OPERATION_LOGICAL_AND,
|
211
|
+
OPERATION_LOGICAL_OR,
|
212
|
+
OPERATION_LOGICAL_XOR,
|
213
|
+
OPERATION_BITWISE_AND,
|
214
|
+
OPERATION_BITWISE_OR,
|
215
|
+
OPERATION_BITWISE_XOR,
|
216
|
+
OPERATION_LESS,
|
217
|
+
OPERATION_GREATER,
|
218
|
+
OPERATION_EQUALS_LESS,
|
219
|
+
OPERATION_EQUALS_GREATER,
|
220
|
+
OPERATION_EQUALS,
|
221
|
+
OPERATION_NOT_EQUALS
|
222
|
+
} MathOperation;
|
223
|
+
|
224
|
+
/// Comparison signs for comparison structures
|
225
|
+
typedef enum {
|
226
|
+
COMPARISON_LESS,
|
227
|
+
COMPARISON_GREATER,
|
228
|
+
COMPARISON_EQUALS_LESS,
|
229
|
+
COMPARISON_EQUALS_GREATER,
|
230
|
+
COMPARISON_EQUALS,
|
231
|
+
COMPARISON_NOT_EQUALS
|
232
|
+
} ComparisonType;
|
233
|
+
|
234
|
+
typedef enum {
|
235
|
+
SORT_DEFAULT = 1 << 0,
|
236
|
+
SORT_SCIENTIFIC = 1 << 1
|
237
|
+
} SortFlags;
|
238
|
+
|
239
|
+
#define BASE_ROMAN_NUMERALS -1
|
240
|
+
#define BASE_TIME -2
|
241
|
+
#define BASE_BINARY 2
|
242
|
+
#define BASE_OCTAL 8
|
243
|
+
#define BASE_DECIMAL 10
|
244
|
+
#define BASE_HEXADECIMAL 16
|
245
|
+
#define BASE_SEXAGESIMAL 60
|
246
|
+
|
247
|
+
#define EXP_BASE_3 -3
|
248
|
+
#define EXP_PRECISION -1
|
249
|
+
#define EXP_NONE 0
|
250
|
+
#define EXP_PURE 1
|
251
|
+
#define EXP_SCIENTIFIC 3
|
252
|
+
|
253
|
+
typedef enum {
|
254
|
+
/// Display numbers in decimal, not fractional, format (ex. 0.333333)
|
255
|
+
FRACTION_DECIMAL,
|
256
|
+
/// Display as fraction if necessary to get an exact display of the result (ex. 1/3, but 0.25)
|
257
|
+
FRACTION_DECIMAL_EXACT,
|
258
|
+
/// Display as fraction (ex. 4/3)
|
259
|
+
FRACTION_FRACTIONAL,
|
260
|
+
/// Display as an integer and a fraction (ex. 3 + 1/2)
|
261
|
+
FRACTION_COMBINED
|
262
|
+
} NumberFractionFormat;
|
263
|
+
//
|
264
|
+
/// Options for ordering the parts of a mathematical expression/result before display
|
265
|
+
static struct SortOptions {
|
266
|
+
/// Put currency units before quantity. Default: true
|
267
|
+
bool prefix_currencies;
|
268
|
+
/// If true, avoid placing negative terms first. Default: true
|
269
|
+
bool minus_last;
|
270
|
+
SortOptions() : prefix_currencies(true), minus_last(true) {}
|
271
|
+
} default_sort_options;
|
272
|
+
|
273
|
+
typedef enum {
|
274
|
+
MULTIPLICATION_SIGN_ASTERISK,
|
275
|
+
MULTIPLICATION_SIGN_DOT,
|
276
|
+
MULTIPLICATION_SIGN_X
|
277
|
+
} MultiplicationSign;
|
278
|
+
|
279
|
+
typedef enum {
|
280
|
+
DIVISION_SIGN_SLASH,
|
281
|
+
DIVISION_SIGN_DIVISION_SLASH,
|
282
|
+
DIVISION_SIGN_DIVISION
|
283
|
+
} DivisionSign;
|
284
|
+
|
285
|
+
typedef enum {
|
286
|
+
BASE_DISPLAY_NONE,
|
287
|
+
BASE_DISPLAY_NORMAL,
|
288
|
+
BASE_DISPLAY_ALTERNATIVE
|
289
|
+
} BaseDisplay;
|
290
|
+
|
291
|
+
/// Options for formatting and display of mathematical structures/results.
|
292
|
+
static struct PrintOptions {
|
293
|
+
int min_exp;
|
294
|
+
/// Number base for displaying numbers. Default: 10
|
295
|
+
int base;
|
296
|
+
/// How prefixes for numbers in non-decimal bases will be displayed
|
297
|
+
BaseDisplay base_display;
|
298
|
+
/// Use lower case for non-numeric characters for bases > 10. Default: false
|
299
|
+
bool lower_case_numbers;
|
300
|
+
/// Use lower case e for base-10 exponent (ex. 1.2e8 instead of 1.2E8). Default: false
|
301
|
+
bool lower_case_e;
|
302
|
+
/// If rational numbers will be displayed with decimals, as a fraction, or something in between. Default: FRACTION_DECIMAL
|
303
|
+
NumberFractionFormat number_fraction_format;
|
304
|
+
/// Show that the digit series of a number continues forever with three dots, instead of rounding (ex. 2/3 displays as 0.666666... instead of 0.666667). Default: false
|
305
|
+
bool indicate_infinite_series;
|
306
|
+
/// Show ending zeroes for approximate numbers to indicate precision (ex.1.2300000 instead of 1.23) . Default: false
|
307
|
+
bool show_ending_zeroes;
|
308
|
+
/// Prefer abbreviated names of variables, units, functions etc. Default: true
|
309
|
+
bool abbreviate_names;
|
310
|
+
/// Prefer reference names of variables, units, functions etc. Default: false
|
311
|
+
bool use_reference_names;
|
312
|
+
/// Isolate units at the end of the displayed expression (ex. x/y m/s instead of (x m)/(y s)). Default: true
|
313
|
+
bool place_units_separately;
|
314
|
+
/// Use prefixes for units when appropriate. Default: true
|
315
|
+
bool use_unit_prefixes;
|
316
|
+
/// Use prefixes for currencies if unit prefixes are om. Default: false
|
317
|
+
bool use_prefixes_for_currencies;
|
318
|
+
/// Use all decimal SI prefixes. If false, prefixes which is not a multiple of thousand (centi, deci, deka, hekto) will not be used automatically. Default: false
|
319
|
+
bool use_all_prefixes;
|
320
|
+
/// If set to true, prefixes will be split between numerator and denominator in a unit expression (millimeter per kilogram instead of micrometer per gram). Default: true
|
321
|
+
bool use_denominator_prefix;
|
322
|
+
/// If true, negative exponents will be used instead of division (ex. 5/x^2 becomes 5*x^-2). Default: false
|
323
|
+
bool negative_exponents;
|
324
|
+
/// Avoid using multiplication sign, when appropriate. Default: true
|
325
|
+
bool short_multiplication;
|
326
|
+
/// Use a format compatible with ParseOptions::limit_implicit_multiplication. Default: false
|
327
|
+
bool limit_implicit_multiplication;
|
328
|
+
/// If it is not necessary that the displayed expression can be parsed correctly. Default: false
|
329
|
+
bool allow_non_usable;
|
330
|
+
/// If unicode signs can be displayed. Default: false
|
331
|
+
bool use_unicode_signs;
|
332
|
+
/// Sign used for display of multiplication. Default: MULTIPLICATION_SIGN_DOT
|
333
|
+
MultiplicationSign multiplication_sign;
|
334
|
+
/// Sign used for display of division. Default: DIVISION_SIGN_DIVISION_SLASH
|
335
|
+
DivisionSign division_sign;
|
336
|
+
/// If space will be used to make the output look nicer. Default: true
|
337
|
+
bool spacious;
|
338
|
+
/// Use parentheses even when not necessary. Default: false
|
339
|
+
bool excessive_parenthesis;
|
340
|
+
/// Transform raised to 1/2 to square root function. Default: true
|
341
|
+
bool halfexp_to_sqrt;
|
342
|
+
/// Minimum number of decimals to display for numbers. Default: 0
|
343
|
+
int min_decimals;
|
344
|
+
/// Maximum number of decimals to display for numbers. A negative value disables the limit. Default: -1
|
345
|
+
int max_decimals;
|
346
|
+
/// Enable use of min_decimals. False is equivalent to a min_decimals value of zero. Default: true
|
347
|
+
bool use_min_decimals;
|
348
|
+
/// Enable use of max_decimals. False is equivalent to a negative max_decimals value. Default: true
|
349
|
+
bool use_max_decimals;
|
350
|
+
/// If true round halfway numbers to nearest even number, otherwise round upwards. Default: false
|
351
|
+
bool round_halfway_to_even;
|
352
|
+
/// Multiply numerator and denominator to get integers (ex. (6x+y)/2z instead of (3x+0.5y)/z). Default: true
|
353
|
+
bool improve_division_multipliers;
|
354
|
+
/// Force use of a specific prefix for units if not NULL. Default: NULL
|
355
|
+
Prefix *prefix;
|
356
|
+
/// If not NULL will be set to true if the output is approximate. Default: NULL
|
357
|
+
bool *is_approximate;
|
358
|
+
/// Options for the order of values in the displayed expression. Default: default_sort_options
|
359
|
+
SortOptions sort_options;
|
360
|
+
/// Comma sign or empty string to use default comma sign. Default: empty string
|
361
|
+
string comma_sign;
|
362
|
+
/// Decimal sign or empty string to use default decimal sign. Default: empty string
|
363
|
+
string decimalpoint_sign;
|
364
|
+
/// Function that returns true if a text string with unicode signs can be properly displayed. Default: NULL
|
365
|
+
bool (*can_display_unicode_string_function) (const char*, void*);
|
366
|
+
/// Argument passed to can_display_unicode_string_function. Default: NULL
|
367
|
+
void *can_display_unicode_string_arg;
|
368
|
+
/// Replace underscores in names with spaces, unless name has suffix. Default: false
|
369
|
+
bool hide_underscore_spaces;
|
370
|
+
/// Preserves the format of the structure (no sorting, no changed prefixes, no improved division multipliers, etc.). Default: false
|
371
|
+
bool preserve_format;
|
372
|
+
/// Allows factorization to occur in the output (should be set to true if the structure has been factorized). Default: false
|
373
|
+
bool allow_factorization;
|
374
|
+
/// If logical operators will be spelled as AND and OR instead of && and ||. Default: false
|
375
|
+
bool spell_out_logical_operators;
|
376
|
+
/// Displays children of the structure with no higher precision than the parent. Default: true
|
377
|
+
bool restrict_to_parent_precision;
|
378
|
+
PrintOptions() : min_exp(EXP_PRECISION), base(BASE_DECIMAL), lower_case_numbers(false), lower_case_e(false), number_fraction_format(FRACTION_DECIMAL), indicate_infinite_series(false), show_ending_zeroes(false), abbreviate_names(true), use_reference_names(false), place_units_separately(true), use_unit_prefixes(true), use_prefixes_for_currencies(false), use_all_prefixes(false), use_denominator_prefix(true), negative_exponents(false), short_multiplication(true), limit_implicit_multiplication(false), allow_non_usable(false), use_unicode_signs(false), multiplication_sign(MULTIPLICATION_SIGN_DOT), division_sign(DIVISION_SIGN_DIVISION_SLASH), spacious(true), excessive_parenthesis(false), halfexp_to_sqrt(true), min_decimals(0), max_decimals(-1), use_min_decimals(true), use_max_decimals(true), round_halfway_to_even(false), improve_division_multipliers(true), prefix(NULL), is_approximate(NULL), can_display_unicode_string_function(NULL), can_display_unicode_string_arg(NULL), hide_underscore_spaces(false), preserve_format(false), allow_factorization(false), spell_out_logical_operators(false), restrict_to_parent_precision(true) {}
|
379
|
+
/// Returns the comma sign used (default sign or comma_sign)
|
380
|
+
const string &comma() const;
|
381
|
+
/// Returns the decimal sign used (default sign or decimalpoint_sign)
|
382
|
+
const string &decimalpoint() const;
|
383
|
+
} default_print_options;
|
384
|
+
|
385
|
+
static struct InternalPrintStruct {
|
386
|
+
int depth, power_depth, division_depth;
|
387
|
+
bool wrap;
|
388
|
+
string *num, *den, *re, *im, *exp;
|
389
|
+
bool *minus, *exp_minus;
|
390
|
+
bool parent_approximate;
|
391
|
+
int parent_precision;
|
392
|
+
InternalPrintStruct() : depth(0), power_depth(0), division_depth(0), wrap(false), num(NULL), den(NULL), re(NULL), im(NULL), exp(NULL), minus(NULL), exp_minus(NULL), parent_approximate(false), parent_precision(-1) {}
|
393
|
+
} top_ips;
|
394
|
+
|
395
|
+
typedef enum {
|
396
|
+
/// Allow only exact results
|
397
|
+
APPROXIMATION_EXACT,
|
398
|
+
/// Try to make the result as exact as possible
|
399
|
+
APPROXIMATION_TRY_EXACT,
|
400
|
+
/// Calculate the result approximately directly
|
401
|
+
APPROXIMATION_APPROXIMATE
|
402
|
+
} ApproximationMode;
|
403
|
+
|
404
|
+
typedef enum {
|
405
|
+
/// Do not do any factorization or additional simplifications
|
406
|
+
STRUCTURING_NONE,
|
407
|
+
/// Simplify the result as much as possible
|
408
|
+
STRUCTURING_SIMPLIFY,
|
409
|
+
/// Factorize the result
|
410
|
+
STRUCTURING_FACTORIZE
|
411
|
+
} StructuringMode;
|
412
|
+
|
413
|
+
typedef enum {
|
414
|
+
/// Do not do any conversion of units in addition to syncing
|
415
|
+
POST_CONVERSION_NONE,
|
416
|
+
/// Convert to the best suited SI units (the least amount of units)
|
417
|
+
POST_CONVERSION_BEST,
|
418
|
+
/// Convert to base units
|
419
|
+
POST_CONVERSION_BASE
|
420
|
+
} AutoPostConversion;
|
421
|
+
|
422
|
+
typedef enum {
|
423
|
+
DONT_READ_PRECISION,
|
424
|
+
ALWAYS_READ_PRECISION,
|
425
|
+
READ_PRECISION_WHEN_DECIMALS
|
426
|
+
} ReadPrecisionMode;
|
427
|
+
|
428
|
+
typedef enum {
|
429
|
+
ANGLE_UNIT_NONE,
|
430
|
+
ANGLE_UNIT_RADIANS,
|
431
|
+
ANGLE_UNIT_DEGREES,
|
432
|
+
ANGLE_UNIT_GRADIANS
|
433
|
+
} AngleUnit;
|
434
|
+
|
435
|
+
/// Options for parsing expressions.
|
436
|
+
static struct ParseOptions {
|
437
|
+
/// If variables will be parsed. Default: true
|
438
|
+
bool variables_enabled;
|
439
|
+
/// If functions will be parsed. Default: true
|
440
|
+
bool functions_enabled;
|
441
|
+
/// If left-over characters will be parsed as symbols. Default: true
|
442
|
+
bool unknowns_enabled;
|
443
|
+
/// If units will be parsed. Default: true
|
444
|
+
bool units_enabled;
|
445
|
+
/// If Reverse Polish Notation syntax will be used. Default: false
|
446
|
+
bool rpn;
|
447
|
+
/// Base of parsed numbers. Default: 10
|
448
|
+
int base;
|
449
|
+
/// When implicit multiplication is limited variables, functions and units must be separated by a space, operator or parenthesis ("xy" does not equal "x * y"). Default: false
|
450
|
+
/**
|
451
|
+
* If the limit implicit multiplication mode is activated, the use of implicite multiplication when parsing expressions and displaying results will be limited to avoid confusion. For example, if this mode is not activated and "integrte(5x)" is accidently typed instead of "integrate(5x)", the expression is interpreted as "int(e * e * (5 * x) * gr * t)". If limit implicit multiplication is turned on to mistyped expression would instead show an error telling that "integrte" is not a valid variable, function or unit (unless unknowns is not enabled in which case the result will be "5 'integrate' * x".
|
452
|
+
*/
|
453
|
+
bool limit_implicit_multiplication;
|
454
|
+
/// If and when precisions will be read from number of digits in a number. Default: DONT_READ_PRECISION
|
455
|
+
ReadPrecisionMode read_precision;
|
456
|
+
/// If true. dots will ignored if another character is the default decimal sign, to allow dots to be used as thousand separator. Default: false
|
457
|
+
bool dot_as_separator;
|
458
|
+
/// Default angle unit for trigonometric functions. Default: ANGLE_UNIT_NONE
|
459
|
+
AngleUnit angle_unit;
|
460
|
+
/// If non-NULL will be set to unfinished function at the end of the expression (if there is one). Default: NULL
|
461
|
+
MathStructure *unended_function;
|
462
|
+
/// Preserve the expression structure as much as possible. Default: false
|
463
|
+
bool preserve_format;
|
464
|
+
ParseOptions() : variables_enabled(true), functions_enabled(true), unknowns_enabled(true), units_enabled(true), rpn(false), base(BASE_DECIMAL), limit_implicit_multiplication(false), read_precision(DONT_READ_PRECISION), dot_as_separator(false), angle_unit(ANGLE_UNIT_NONE), unended_function(NULL), preserve_format(false) {}
|
465
|
+
} default_parse_options;
|
466
|
+
|
467
|
+
/// Options for calculation.
|
468
|
+
static struct EvaluationOptions {
|
469
|
+
/// How exact the result must be. Default: TRY_EXACT
|
470
|
+
ApproximationMode approximation;
|
471
|
+
/// If units will be synced/converted to allow evaluation (ex. 1 min + 1 s=60 s+ 1 s = 61 s). Default: true
|
472
|
+
bool sync_units;
|
473
|
+
/// If units with complex/non-linear relations (ex. degress celsius and fahrenheit) will synced/converted. Default: true
|
474
|
+
bool sync_complex_unit_relations;
|
475
|
+
/// If unit prefixes in original expression will be kept. Default: false
|
476
|
+
bool keep_prefixes;
|
477
|
+
/// If known variables will be replaced by their value. Default: true
|
478
|
+
bool calculate_variables;
|
479
|
+
/// If functions will be calculated. Default: true
|
480
|
+
bool calculate_functions;
|
481
|
+
/// If comparisons will be evaluated (ex. 5>2 => 1). Default: true
|
482
|
+
bool test_comparisons;
|
483
|
+
/// If a varaible will be isolated to the left side in equations/comparisons (ex. x+y=2 => x=2-y). Default: true
|
484
|
+
bool isolate_x;
|
485
|
+
/// If factors (and bases) containing addition will be expanded (ex. z(x+y)=zx+zy). Default: true
|
486
|
+
bool expand;
|
487
|
+
/// If non-numerical parts of a fraction will be reduced (ex. (5x)/(3xy) =5/(3y) . Default: true
|
488
|
+
bool reduce_divisions;
|
489
|
+
/// If complex numbers will be used for evaluation. Default: true
|
490
|
+
bool allow_complex;
|
491
|
+
/// If infinite numbers will be used for evaluation. Default: true
|
492
|
+
bool allow_infinite;
|
493
|
+
/// If simplification will be made easier by assuming that denominators with unknown value not is zero. Default: false
|
494
|
+
bool assume_denominators_nonzero;
|
495
|
+
/// Warn if a denominator with unknown value was assumed non-zero (with assume_denominators_nonzero set to true) to allow simplification. Default: false
|
496
|
+
bool warn_about_denominators_assumed_nonzero;
|
497
|
+
/// If powers with exponent 1/2 that only have an approximate result will be split to the least base (sqrt(8) = 2 * sqrt(2)). Default: true
|
498
|
+
bool split_squares;
|
499
|
+
/// If units with zero quantity will be preserved. Default: true
|
500
|
+
bool keep_zero_units;
|
501
|
+
/// If and how units will be automatically converted. Does not affect syncing of units. Default: POST_CONVERSION_NONE
|
502
|
+
AutoPostConversion auto_post_conversion;
|
503
|
+
/// If the evaluation result will be simplified or factorized
|
504
|
+
StructuringMode structuring;
|
505
|
+
/// Options for parsing of expression. Default: default_parse_options
|
506
|
+
ParseOptions parse_options;
|
507
|
+
/// If set will decide which variable to isolate in an equation. Default: NULL
|
508
|
+
const MathStructure *isolate_var;
|
509
|
+
EvaluationOptions() : approximation(APPROXIMATION_TRY_EXACT), sync_units(true), sync_complex_unit_relations(true), keep_prefixes(false), calculate_variables(true), calculate_functions(true), test_comparisons(true), isolate_x(true), expand(true), reduce_divisions(true), allow_complex(true), allow_infinite(true), assume_denominators_nonzero(false), warn_about_denominators_assumed_nonzero(false), split_squares(true), keep_zero_units(true), auto_post_conversion(POST_CONVERSION_NONE), structuring(STRUCTURING_SIMPLIFY), isolate_var(NULL) {}
|
510
|
+
} default_evaluation_options;
|
511
|
+
|
512
|
+
extern MathStructure m_undefined, m_empty_vector, m_empty_matrix, m_zero, m_one, m_minus_one;
|
513
|
+
extern Number nr_zero, nr_one, nr_minus_one;
|
514
|
+
extern EvaluationOptions no_evaluation;
|
515
|
+
extern ExpressionName empty_expression_name;
|
516
|
+
|
517
|
+
extern Calculator *calculator;
|
518
|
+
|
519
|
+
#define CALCULATOR calculator
|
520
|
+
|
521
|
+
#define DEFAULT_PRECISION 8
|
522
|
+
#define PRECISION CALCULATOR->getPrecision()
|
523
|
+
|
524
|
+
#define SIGN_POWER_0 "°"
|
525
|
+
#define SIGN_POWER_1 "¹"
|
526
|
+
#define SIGN_POWER_2 "²"
|
527
|
+
#define SIGN_POWER_3 "³"
|
528
|
+
#define SIGN_EURO "€"
|
529
|
+
#define SIGN_POUND "£"
|
530
|
+
#define SIGN_CENT "¢"
|
531
|
+
#define SIGN_YEN "¥"
|
532
|
+
#define SIGN_MICRO "µ"
|
533
|
+
#define SIGN_PI "π"
|
534
|
+
#define SIGN_MULTIPLICATION "×"
|
535
|
+
#define SIGN_MULTIDOT "⋅"
|
536
|
+
#define SIGN_MULTIBULLET "∙"
|
537
|
+
#define SIGN_SMALLCIRCLE "•"
|
538
|
+
#define SIGN_DIVISION_SLASH "∕"
|
539
|
+
#define SIGN_DIVISION "÷"
|
540
|
+
#define SIGN_MINUS "−"
|
541
|
+
#define SIGN_PLUS "+"
|
542
|
+
#define SIGN_SQRT "√"
|
543
|
+
#define SIGN_ALMOST_EQUAL "≈"
|
544
|
+
#define SIGN_APPROXIMATELY_EQUAL "≅"
|
545
|
+
#define SIGN_ZETA "ζ"
|
546
|
+
#define SIGN_GAMMA "γ"
|
547
|
+
#define SIGN_PHI "φ"
|
548
|
+
#define SIGN_LESS_OR_EQUAL "≤"
|
549
|
+
#define SIGN_GREATER_OR_EQUAL "≥"
|
550
|
+
#define SIGN_NOT_EQUAL "≠"
|
551
|
+
#define SIGN_CAPITAL_SIGMA "Σ"
|
552
|
+
#define SIGN_CAPITAL_PI "Π"
|
553
|
+
#define SIGN_CAPITAL_OMEGA "Ω"
|
554
|
+
#define SIGN_CAPITAL_GAMMA "Γ"
|
555
|
+
#define SIGN_CAPITAL_BETA "Β"
|
556
|
+
#define SIGN_INFINITY "∞"
|
557
|
+
|
558
|
+
#define ID_WRAP_LEFT_CH '{'
|
559
|
+
#define ID_WRAP_RIGHT_CH '}'
|
560
|
+
|
561
|
+
#define DOT_CH '.'
|
562
|
+
#define ZERO_CH '0'
|
563
|
+
#define ONE_CH '1'
|
564
|
+
#define TWO_CH '2'
|
565
|
+
#define THREE_CH '3'
|
566
|
+
#define FOUR_CH '4'
|
567
|
+
#define FIVE_CH '5'
|
568
|
+
#define SIX_CH '6'
|
569
|
+
#define SEVEN_CH '7'
|
570
|
+
#define EIGHT_CH '8'
|
571
|
+
#define NINE_CH '9'
|
572
|
+
#define PLUS_CH '+'
|
573
|
+
#define MINUS_CH '-'
|
574
|
+
#define MULTIPLICATION_CH '*'
|
575
|
+
#define MULTIPLICATION_2_CH ' '
|
576
|
+
#define DIVISION_CH '/'
|
577
|
+
#define EXP_CH 'E'
|
578
|
+
#define EXP2_CH 'e'
|
579
|
+
#define POWER_CH '^'
|
580
|
+
#define SPACE_CH ' '
|
581
|
+
#define LEFT_PARENTHESIS_CH '('
|
582
|
+
#define RIGHT_PARENTHESIS_CH ')'
|
583
|
+
#define LEFT_VECTOR_WRAP_CH '['
|
584
|
+
#define RIGHT_VECTOR_WRAP_CH ']'
|
585
|
+
#define FUNCTION_VAR_PRE_CH '\\'
|
586
|
+
#define COMMA_CH ','
|
587
|
+
#define NAME_NUMBER_PRE_CH '_'
|
588
|
+
#define UNIT_DIVISION_CH '/'
|
589
|
+
#define AND_CH '&'
|
590
|
+
#define OR_CH '|'
|
591
|
+
#define LESS_CH '<'
|
592
|
+
#define GREATER_CH '>'
|
593
|
+
#define BITWISE_NOT_CH '~'
|
594
|
+
#define LOGICAL_NOT_CH '!'
|
595
|
+
#define NOT_CH '!'
|
596
|
+
#define EQUALS_CH '='
|
597
|
+
|
598
|
+
#define ID_WRAP_LEFT "{"
|
599
|
+
#define ID_WRAP_RIGHT "}"
|
600
|
+
#define ID_WRAPS "{}"
|
601
|
+
#define DOT "."
|
602
|
+
#define SEXADOT ":"
|
603
|
+
#define COMMA ","
|
604
|
+
#define COMMAS ",;"
|
605
|
+
#define NUMBERS "0123456789"
|
606
|
+
#define NUMBER_ELEMENTS "0123456789.:"
|
607
|
+
#define SIGNS "+-*/^"
|
608
|
+
#define OPERATORS "~+-*/^&|!<>="
|
609
|
+
#define PARENTHESISS "()"
|
610
|
+
#define LEFT_PARENTHESIS "("
|
611
|
+
#define RIGHT_PARENTHESIS ")"
|
612
|
+
#define VECTOR_WRAPS "[]"
|
613
|
+
#define LEFT_VECTOR_WRAP "["
|
614
|
+
#define RIGHT_VECTOR_WRAP "]"
|
615
|
+
#define SPACES " \t\n"
|
616
|
+
#define SPACE " "
|
617
|
+
#define RESERVED "\'@?\\{}\""
|
618
|
+
#define PLUS "+"
|
619
|
+
#define MINUS "-"
|
620
|
+
#define MULTIPLICATION "*"
|
621
|
+
#define MULTIPLICATION_2 " "
|
622
|
+
#define DIVISION "/"
|
623
|
+
#define EXP "E"
|
624
|
+
#define EXPS "Ee"
|
625
|
+
#define POWER "^"
|
626
|
+
#define LOGICAL_AND "&&"
|
627
|
+
#define LOGICAL_OR "||"
|
628
|
+
#define LOGICAL_NOT "!"
|
629
|
+
#define BITWISE_AND "&"
|
630
|
+
#define BITWISE_OR "|"
|
631
|
+
#define BITWISE_NOT "~"
|
632
|
+
#define SHIFT_RIGHT ">>"
|
633
|
+
#define SHIFT_LEFT "<<"
|
634
|
+
#define LESS "<"
|
635
|
+
#define GREATER ">"
|
636
|
+
#define NOT "!"
|
637
|
+
#define EQUALS "="
|
638
|
+
#define SINF "INF"
|
639
|
+
#define SNAN "NAN"
|
640
|
+
#define UNDERSCORE "_"
|
641
|
+
|
642
|
+
#define NOT_IN_NAMES RESERVED OPERATORS SPACES SEXADOT DOT VECTOR_WRAPS PARENTHESISS COMMAS
|
643
|
+
|
644
|
+
#endif
|