1 /* 2 Qalculate (library) 3 4 Copyright (C) 2003-2007, 2008, 2016-2021 Hanna Knutsson (hanna.knutsson@protonmail.com) 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 #include <vector> 18 #include <string> 19 #include <stack> 20 #include <list> 21 #include <errno.h> 22 #include <stddef.h> 23 #include <math.h> 24 #include <float.h> 25 #include <stdarg.h> 26 #include <stdlib.h> 27 #include <stdio.h> 28 #include <string.h> 29 #include <iostream> 30 #include <unistd.h> 31 #include <stdint.h> 32 33 #define QALCULATE_MAJOR_VERSION (3) 34 #define QALCULATE_MINOR_VERSION (17) 35 #define QALCULATE_MICRO_VERSION (0) 36 37 static std::string empty_string; 38 39 struct ExpressionName; 40 class Calculator; 41 class MathStructure; 42 class Manager; 43 class Unit; 44 class Variable; 45 class KnownVariable; 46 class UnknownVariable; 47 class Assumptions; 48 class DynamicVariable; 49 class ExpressionItem; 50 class Number; 51 class Prefix; 52 class DecimalPrefix; 53 class BinaryPrefix; 54 class NumberPrefix; 55 class CompositeUnit; 56 class AliasUnit; 57 class AliasUnit_Composite; 58 class MathFunction; 59 class Matrix; 60 class Vector; 61 class UserFunction; 62 class EqItem; 63 class EqNumber; 64 class EqContainer; 65 class Argument; 66 class DataSet; 67 class DataProperty; 68 class DataObject; 69 70 /// Type of ExpressionItem 71 typedef enum { 72 /// class Variable 73 TYPE_VARIABLE, 74 /// class MathFunction 75 TYPE_FUNCTION, 76 /// class Unit 77 TYPE_UNIT 78 } ExpressionItemType; 79 80 #define COMPARISON_MIGHT_BE_LESS_OR_GREATER(i) (i >= COMPARISON_RESULT_UNKNOWN || i == COMPARISON_RESULT_NOT_EQUAL) 81 #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) 82 #define COMPARISON_IS_EQUAL_OR_GREATER(i) (i == COMPARISON_RESULT_EQUAL || i == COMPARISON_RESULT_GREATER || i == COMPARISON_RESULT_EQUAL_OR_GREATER) 83 #define COMPARISON_IS_EQUAL_OR_LESS(i) (i == COMPARISON_RESULT_EQUAL || i == COMPARISON_RESULT_LESS || i == COMPARISON_RESULT_EQUAL_OR_LESS) 84 #define COMPARISON_IS_NOT_EQUAL(i) (i == COMPARISON_RESULT_NOT_EQUAL || i == COMPARISON_RESULT_LESS || i == COMPARISON_RESULT_GREATER) 85 #define COMPARISON_MIGHT_BE_EQUAL(i) (i >= COMPARISON_RESULT_UNKNOWN || i == COMPARISON_RESULT_EQUAL_OR_LESS || i == COMPARISON_RESULT_EQUAL_OR_GREATER) 86 #define COMPARISON_MIGHT_BE_NOT_EQUAL(i) (i >= COMPARISON_RESULT_UNKNOWN || i == COMPARISON_RESULT_EQUAL_OR_LESS || i == COMPARISON_RESULT_EQUAL_OR_GREATER) 87 88 #define NR_OF_PRIMES 600 89 90 static const long int PRIMES[] = { 91 2L, 3L, 5L, 7L, 11L, 13L, 17L, 19L, 23L, 29L, 92 31L, 37L, 41L, 43L, 47L, 53L, 59L, 61L, 67L, 71L, 93 73L, 79L, 83L, 89L, 97L, 101L, 103L, 107L, 109L, 113L, 94 127L, 131L, 137L, 139L, 149L, 151L, 157L, 163L, 167L, 173L, 95 179L, 181L, 191L, 193L, 197L, 199L, 211L, 223L, 227L, 229L, 96 233L, 239L, 241L, 251L, 257L, 263L, 269L, 271L, 277L, 281L, 97 283L, 293L, 307L, 311L, 313L, 317L, 331L, 337L, 347L, 349L, 98 353L, 359L, 367L, 373L, 379L, 383L, 389L, 397L, 401L, 409L, 99 419L, 421L, 431L, 433L, 439L, 443L, 449L, 457L, 461L, 463L, 100 467L, 479L, 487L, 491L, 499L, 503L, 509L, 521L, 523L, 541L, 101 547L, 557L, 563L, 569L, 571L, 577L, 587L, 593L, 599L, 601L, 102 607L, 613L, 617L, 619L, 631L, 641L, 643L, 647L, 653L, 659L, 103 661L, 673L, 677L, 683L, 691L, 701L, 709L, 719L, 727L, 733L, 104 739L, 743L, 751L, 757L, 761L, 769L, 773L, 787L, 797L, 809L, 105 811L, 821L, 823L, 827L, 829L, 839L, 853L, 857L, 859L, 863L, 106 877L, 881L, 883L, 887L, 907L, 911L, 919L, 929L, 937L, 941L, 107 947L, 953L, 967L, 971L, 977L, 983L, 991L, 997L, 1009L, 1013L, 108 1019L, 1021L, 1031L, 1033L, 1039L, 1049L, 1051L, 1061L, 1063L, 1069L, 109 1087L, 1091L, 1093L, 1097L, 1103L, 1109L, 1117L, 1123L, 1129L, 1151L, 110 1153L, 1163L, 1171L, 1181L, 1187L, 1193L, 1201L, 1213L, 1217L, 1223L, 111 1229L, 1231L, 1237L, 1249L, 1259L, 1277L, 1279L, 1283L, 1289L, 1291L, 112 1297L, 1301L, 1303L, 1307L, 1319L, 1321L, 1327L, 1361L, 1367L, 1373L, 113 1381L, 1399L, 1409L, 1423L, 1427L, 1429L, 1433L, 1439L, 1447L, 1451L, 114 1453L, 1459L, 1471L, 1481L, 1483L, 1487L, 1489L, 1493L, 1499L, 1511L, 115 1523L, 1531L, 1543L, 1549L, 1553L, 1559L, 1567L, 1571L, 1579L, 1583L, 116 1597L, 1601L, 1607L, 1609L, 1613L, 1619L, 1621L, 1627L, 1637L, 1657L, 117 1663L, 1667L, 1669L, 1693L, 1697L, 1699L, 1709L, 1721L, 1723L, 1733L, 118 1741L, 1747L, 1753L, 1759L, 1777L, 1783L, 1787L, 1789L, 1801L, 1811L, 119 1823L, 1831L, 1847L, 1861L, 1867L, 1871L, 1873L, 1877L, 1879L, 1889L, 120 1901L, 1907L, 1913L, 1931L, 1933L, 1949L, 1951L, 1973L, 1979L, 1987L, 121 1993L, 1997L, 1999L, 2003L, 2011L, 2017L, 2027L, 2029L, 2039L, 2053L, 122 2063L, 2069L, 2081L, 2083L, 2087L, 2089L, 2099L, 2111L, 2113L, 2129L, 123 2131L, 2137L, 2141L, 2143L, 2153L, 2161L, 2179L, 2203L, 2207L, 2213L, 124 2221L, 2237L, 2239L, 2243L, 2251L, 2267L, 2269L, 2273L, 2281L, 2287L, 125 2293L, 2297L, 2309L, 2311L, 2333L, 2339L, 2341L, 2347L, 2351L, 2357L, 126 2371L, 2377L, 2381L, 2383L, 2389L, 2393L, 2399L, 2411L, 2417L, 2423L, 127 2437L, 2441L, 2447L, 2459L, 2467L, 2473L, 2477L, 2503L, 2521L, 2531L, 128 2539L, 2543L, 2549L, 2551L, 2557L, 2579L, 2591L, 2593L, 2609L, 2617L, 129 2621L, 2633L, 2647L, 2657L, 2659L, 2663L, 2671L, 2677L, 2683L, 2687L, 130 2689L, 2693L, 2699L, 2707L, 2711L, 2713L, 2719L, 2729L, 2731L, 2741L, 131 2749L, 2753L, 2767L, 2777L, 2789L, 2791L, 2797L, 2801L, 2803L, 2819L, 132 2833L, 2837L, 2843L, 2851L, 2857L, 2861L, 2879L, 2887L, 2897L, 2903L, 133 2909L, 2917L, 2927L, 2939L, 2953L, 2957L, 2963L, 2969L, 2971L, 2999L, 134 3001L, 3011L, 3019L, 3023L, 3037L, 3041L, 3049L, 3061L, 3067L, 3079L, 135 3083L, 3089L, 3109L, 3119L, 3121L, 3137L, 3163L, 3167L, 3169L, 3181L, 136 3187L, 3191L, 3203L, 3209L, 3217L, 3221L, 3229L, 3251L, 3253L, 3257L, 137 3259L, 3271L, 3299L, 3301L, 3307L, 3313L, 3319L, 3323L, 3329L, 3331L, 138 3343L, 3347L, 3359L, 3361L, 3371L, 3373L, 3389L, 3391L, 3407L, 3413L, 139 3433L, 3449L, 3457L, 3461L, 3463L, 3467L, 3469L, 3491L, 3499L, 3511L, 140 3517L, 3527L, 3529L, 3533L, 3539L, 3541L, 3547L, 3557L, 3559L, 3571L, 141 3581L, 3583L, 3593L, 3607L, 3613L, 3617L, 3623L, 3631L, 3637L, 3643L, 142 3659L, 3671L, 3673L, 3677L, 3691L, 3697L, 3701L, 3709L, 3719L, 3727L, 143 3733L, 3739L, 3761L, 3767L, 3769L, 3779L, 3793L, 3797L, 3803L, 3821L, 144 3823L, 3833L, 3847L, 3851L, 3853L, 3863L, 3877L, 3881L, 3889L, 3907L, 145 3911L, 3917L, 3919L, 3923L, 3929L, 3931L, 3943L, 3947L, 3967L, 3989L, 146 4001L, 4003L, 4007L, 4013L, 4019L, 4021L, 4027L, 4049L, 4051L, 4057L, 147 4073L, 4079L, 4091L, 4093L, 4099L, 4111L, 4127L, 4129L, 4133L, 4139L, 148 4153L, 4157L, 4159L, 4177L, 4201L, 4211L, 4217L, 4219L, 4229L, 4231L, 149 4241L, 4243L, 4253L, 4259L, 4261L, 4271L, 4273L, 4283L, 4289L, 4297L, 150 4327L, 4337L, 4339L, 4349L, 4357L, 4363L, 4373L, 4391L, 4397L, 4409L 151 }; 152 153 #define SQP_LT_1000 11 154 #define SQP_LT_2000 17 155 #define SQP_LT_10000 28 156 #define SQP_LT_25000 40 157 #define SQP_LT_100000 68 158 159 #define NR_OF_SQUARE_PRIMES 170 160 161 static const long int SQUARE_PRIMES[] = { 162 4L, 9L, 25L, 49L, 121L, 169L, 289L, 361L, 529L, 841L, 163 961L, 1369L, 1681L, 1849L, 2209L, 2809L, 3481L, 3721L, 4489L, 5041L, 164 5329L, 6241L, 6889L, 7921L, 9409L, 10201L, 10609L, 11449L, 11881L, 12769L, 165 16129L, 17161L, 18769L, 19321L, 22201L, 22801L, 24649L, 26569L, 27889L, 29929L, 166 32041L, 32761L, 36481L, 37249L, 38809L, 39601L, 44521L, 49729L, 51529L, 52441L, 167 54289L, 57121L, 58081L, 63001L, 66049L, 69169L, 72361L, 73441L, 76729L, 78961L, 168 80089L, 85849L, 94249L, 96721L, 97969L, 100489L, 109561L, 113569L, 120409L, 121801L, 169 124609L, 128881L, 134689L, 139129L, 143641L, 146689L, 151321L, 157609L, 160801L, 167281L, 170 175561L, 177241L, 185761L, 187489L, 192721L, 196249L, 201601L, 208849L, 212521L, 214369L, 171 218089L, 229441L, 237169L, 241081L, 249001L, 253009L, 259081L, 271441L, 273529L, 292681L, 172 299209L, 310249L, 316969L, 323761L, 326041L, 332929L, 344569L, 351649L, 358801L, 361201L, 173 368449L, 375769L, 380689L, 383161L, 398161L, 410881L, 413449L, 418609L, 426409L, 434281L, 174 436921L, 452929L, 458329L, 466489L, 477481L, 491401L, 502681L, 516961L, 528529L, 537289L, 175 546121L, 552049L, 564001L, 573049L, 579121L, 591361L, 597529L, 619369L, 635209L, 654481L, 176 657721L, 674041L, 677329L, 683929L, 687241L, 703921L, 727609L, 734449L, 737881L, 744769L, 177 769129L, 776161L, 779689L, 786769L, 822649L, 829921L, 844561L, 863041L, 877969L, 885481L, 178 896809L, 908209L, 935089L, 942841L, 954529L, 966289L, 982081L, 994009L, 1018081L, 1026169L 179 }; 180 181 #define LARGEST_RAISED_PRIME_EXPONENT 10 182 183 static const long int RAISED_PRIMES[][49] = { 184 {8L, 27L, 125L, 343L, 1331L, 2197, 4913, 6859, 12167L, 24389L, 185 29791L, 50653L, 68921L, 79507L, 103823L, 148877L, 205379L, 226981L, 300763L, 357911L, 186 389017L, 493039L, 571787L, 704969L, 912673L, 1030301L, 1092727L, 1225043L, 1295029, 1442897, 187 2048383L, 2248091L, 2571353L, 2685619L, 3307949L, 3442951L, 3869893L, 4330747L, 4657463L, 5177717L, 188 5735339L, 5929741L, 6967871L, 7189057L, 7645373L, 7880599L, 9393931L, 11089567L, 0}, 189 {16L, 81L, 625L, 2401L, 14641L, 28561L, 83521L, 130321L, 279841L, 707281L, 190 923521L, 1874161L, 2825761L, 3418801L, 4879681L, 7890481L, 12117361L, 191 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 192 {32L, 243L, 3125L, 16807L, 161051L, 371293L, 1419857L, 2476099L, 6436343L, 20511149L, 193 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 194 {64L, 729L, 15625L, 117649L, 1771561L, 4826809L, 24137569L, 47045881L, 148035889L, 195 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 196 {128L, 2187L, 78125L, 823543L, 19487171L, 62748517L, 410338673L, 197 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 198 {256L, 6561L, 390625L, 5764801L, 214358881L, 815730721L, 199 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 200 {512L, 19683L, 1953125L, 40353607L, 201 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 202 {1024L, 59049L, 9765625L, 282475249L, 203 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 204 }; 205 206 /// The result of a comparison of two values 207 typedef enum { 208 COMPARISON_RESULT_EQUAL, 209 COMPARISON_RESULT_GREATER, 210 COMPARISON_RESULT_LESS, 211 COMPARISON_RESULT_EQUAL_OR_GREATER, 212 COMPARISON_RESULT_EQUAL_OR_LESS, 213 COMPARISON_RESULT_NOT_EQUAL, 214 COMPARISON_RESULT_UNKNOWN, 215 COMPARISON_RESULT_EQUAL_LIMITS, 216 COMPARISON_RESULT_CONTAINS, 217 COMPARISON_RESULT_CONTAINED, 218 COMPARISON_RESULT_OVERLAPPING_LESS, 219 COMPARISON_RESULT_OVERLAPPING_GREATER 220 } ComparisonResult; 221 222 /// Placement of legend 223 typedef enum { 224 PLOT_LEGEND_NONE, 225 PLOT_LEGEND_TOP_LEFT, 226 PLOT_LEGEND_TOP_RIGHT, 227 PLOT_LEGEND_BOTTOM_LEFT, 228 PLOT_LEGEND_BOTTOM_RIGHT, 229 PLOT_LEGEND_BELOW, 230 PLOT_LEGEND_OUTSIDE 231 } PlotLegendPlacement; 232 233 /// Plot type/style 234 typedef enum { 235 PLOT_STYLE_LINES, 236 PLOT_STYLE_POINTS, 237 PLOT_STYLE_POINTS_LINES, 238 PLOT_STYLE_BOXES, 239 PLOT_STYLE_HISTOGRAM, 240 PLOT_STYLE_STEPS, 241 PLOT_STYLE_CANDLESTICKS, 242 PLOT_STYLE_DOTS 243 } PlotStyle; 244 245 /// Smoothing a plotted lines 246 typedef enum { 247 PLOT_SMOOTHING_NONE, 248 PLOT_SMOOTHING_UNIQUE, 249 PLOT_SMOOTHING_CSPLINES, 250 PLOT_SMOOTHING_BEZIER, 251 PLOT_SMOOTHING_SBEZIER 252 } PlotSmoothing; 253 254 /// File type for saving plot to image 255 typedef enum { 256 PLOT_FILETYPE_AUTO, 257 PLOT_FILETYPE_PNG, 258 PLOT_FILETYPE_PS, 259 PLOT_FILETYPE_EPS, 260 PLOT_FILETYPE_LATEX, 261 PLOT_FILETYPE_SVG, 262 PLOT_FILETYPE_FIG, 263 PLOT_FILETYPE_PDF 264 } PlotFileType; 265 266 /// Mathematical operations 267 typedef enum { 268 OPERATION_MULTIPLY, 269 OPERATION_DIVIDE, 270 OPERATION_ADD, 271 OPERATION_SUBTRACT, 272 OPERATION_RAISE, 273 OPERATION_EXP10, 274 OPERATION_LOGICAL_AND, 275 OPERATION_LOGICAL_OR, 276 OPERATION_LOGICAL_XOR, 277 OPERATION_BITWISE_AND, 278 OPERATION_BITWISE_OR, 279 OPERATION_BITWISE_XOR, 280 OPERATION_LESS, 281 OPERATION_GREATER, 282 OPERATION_EQUALS_LESS, 283 OPERATION_EQUALS_GREATER, 284 OPERATION_EQUALS, 285 OPERATION_NOT_EQUALS 286 } MathOperation; 287 288 /// Comparison signs for comparison structures 289 typedef enum { 290 COMPARISON_LESS, 291 COMPARISON_GREATER, 292 COMPARISON_EQUALS_LESS, 293 COMPARISON_EQUALS_GREATER, 294 COMPARISON_EQUALS, 295 COMPARISON_NOT_EQUALS 296 } ComparisonType; 297 298 typedef enum { 299 SORT_DEFAULT = 1 << 0, 300 SORT_SCIENTIFIC = 1 << 1 301 } SortFlags; 302 303 #define BASE_ROMAN_NUMERALS -1 304 #define BASE_TIME -2 305 #define BASE_BINARY 2 306 #define BASE_OCTAL 8 307 #define BASE_DECIMAL 10 308 #define BASE_DUODECIMAL 12 309 #define BASE_HEXADECIMAL 16 310 #define BASE_SEXAGESIMAL 60 311 #define BASE_CUSTOM -3 312 #define BASE_UNICODE -4 313 #define BASE_GOLDEN_RATIO -5 314 #define BASE_SUPER_GOLDEN_RATIO -6 315 #define BASE_PI -7 316 #define BASE_E -8 317 #define BASE_SQRT2 -9 318 #define BASE_BIJECTIVE_26 -26 319 #define BASE_FP16 -30 320 #define BASE_FP32 -31 321 #define BASE_FP64 -32 322 #define BASE_FP128 -33 323 #define BASE_FP80 -34 324 325 #define EXP_BASE_3 -3 326 #define EXP_PRECISION -1 327 #define EXP_NONE 0 328 #define EXP_PURE 1 329 #define EXP_SCIENTIFIC 3 330 331 typedef enum { 332 /// Display numbers in decimal, not fractional, format (ex. 0.333333) 333 FRACTION_DECIMAL, 334 /// Display as fraction if necessary to get an exact display of the result (ex. 1/3, but 0.25) 335 FRACTION_DECIMAL_EXACT, 336 /// Display as fraction (ex. 4/3) 337 FRACTION_FRACTIONAL, 338 /// Display as an integer and a fraction (ex. 3 + 1/2) 339 FRACTION_COMBINED 340 } NumberFractionFormat; 341 342 /// Options for ordering the parts of a mathematical expression/result before display 343 static const struct SortOptions { 344 /// Put currency units before quantity. Default: true 345 bool prefix_currencies; 346 /// If true, avoid placing negative terms first. Default: true 347 bool minus_last; SortOptionsSortOptions348 SortOptions() : prefix_currencies(true), minus_last(true) {} 349 } default_sort_options; 350 351 typedef enum { 352 MULTIPLICATION_SIGN_ASTERISK, 353 MULTIPLICATION_SIGN_DOT, 354 MULTIPLICATION_SIGN_X, 355 MULTIPLICATION_SIGN_ALTDOT 356 } MultiplicationSign; 357 358 typedef enum { 359 DIVISION_SIGN_SLASH, 360 DIVISION_SIGN_DIVISION_SLASH, 361 DIVISION_SIGN_DIVISION 362 } DivisionSign; 363 364 typedef enum { 365 BASE_DISPLAY_NONE, 366 BASE_DISPLAY_NORMAL, 367 BASE_DISPLAY_ALTERNATIVE 368 } BaseDisplay; 369 370 typedef enum { 371 INTERVAL_DISPLAY_SIGNIFICANT_DIGITS, 372 INTERVAL_DISPLAY_INTERVAL, 373 INTERVAL_DISPLAY_PLUSMINUS, 374 INTERVAL_DISPLAY_MIDPOINT, 375 INTERVAL_DISPLAY_LOWER, 376 INTERVAL_DISPLAY_UPPER 377 } IntervalDisplay; 378 379 typedef enum { 380 DIGIT_GROUPING_NONE, 381 DIGIT_GROUPING_STANDARD, 382 DIGIT_GROUPING_LOCALE 383 } DigitGrouping; 384 385 typedef enum { 386 DATE_TIME_FORMAT_ISO, 387 DATE_TIME_FORMAT_LOCALE 388 } DateTimeFormat; 389 390 typedef enum { 391 TIME_ZONE_UTC, 392 TIME_ZONE_LOCAL, 393 TIME_ZONE_CUSTOM 394 } TimeZone; 395 396 /// Options for formatting and display of mathematical structures/results. 397 static const struct PrintOptions { 398 int min_exp; 399 /// Number base for displaying numbers. Default: 10 400 int base; 401 /// How prefixes for numbers in non-decimal bases will be displayed. Default: BASE_DISPLAY_NONE 402 BaseDisplay base_display; 403 /// Use lower case for non-numeric characters for bases > 10. Default: false 404 bool lower_case_numbers; 405 /// Use lower case e for base-10 exponent (ex. 1.2e8 instead of 1.2E8). Default: false 406 bool lower_case_e; 407 /// If rational numbers will be displayed with decimals, as a fraction, or something in between. Default: FRACTION_DECIMAL 408 NumberFractionFormat number_fraction_format; 409 /// 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 410 bool indicate_infinite_series; 411 /// Show ending zeroes for approximate numbers to indicate precision (ex.1.2300000 instead of 1.23) . Default: false 412 bool show_ending_zeroes; 413 /// Prefer abbreviated names of variables, units, functions etc. Default: true 414 bool abbreviate_names; 415 /// Prefer reference names of variables, units, functions etc. Default: false 416 bool use_reference_names; 417 /// Isolate units at the end of the displayed expression (ex. x/y m/s instead of (x m)/(y s)). Default: true 418 bool place_units_separately; 419 /// Use prefixes for units when appropriate. Default: true 420 bool use_unit_prefixes; 421 /// Use prefixes for currencies if unit prefixes are om. Default: false 422 bool use_prefixes_for_all_units; 423 /// 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 424 bool use_prefixes_for_currencies; 425 /// Use prefixes for all units (even imperial and similar ones). Default: false 426 bool use_all_prefixes; 427 /// 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 428 bool use_denominator_prefix; 429 /// If true, negative exponents will be used instead of division (ex. 5/x^2 becomes 5*x^-2). Default: false 430 bool negative_exponents; 431 /// Avoid using multiplication sign, when appropriate. Default: true 432 bool short_multiplication; 433 /// Use a format compatible with ParseOptions::limit_implicit_multiplication. Default: false 434 bool limit_implicit_multiplication; 435 /// If it is not necessary that the displayed expression can be parsed correctly. Default: false 436 bool allow_non_usable; 437 /// If unicode signs can be displayed. Default: false 438 bool use_unicode_signs; 439 /// Sign used for display of multiplication. Default: MULTIPLICATION_SIGN_DOT 440 MultiplicationSign multiplication_sign; 441 /// Sign used for display of division. Default: DIVISION_SIGN_DIVISION_SLASH 442 DivisionSign division_sign; 443 /// If space will be used to make the output look nicer. Default: true 444 bool spacious; 445 /// Use parentheses even when not necessary. Default: false 446 bool excessive_parenthesis; 447 /// Transform raised to 1/2 to square root and raised to 1/3 to cbrt function. Default: true 448 bool halfexp_to_sqrt; 449 /// Minimum number of decimals to display for numbers. Default: 0 450 int min_decimals; 451 /// Maximum number of decimals to display for numbers. A negative value disables the limit. Default: -1 452 int max_decimals; 453 /// Enable use of min_decimals. False is equivalent to a min_decimals value of zero. Default: true 454 bool use_min_decimals; 455 /// Enable use of max_decimals. False is equivalent to a negative max_decimals value. Default: true 456 bool use_max_decimals; 457 /// If true round halfway numbers to nearest even number, otherwise round upwards. Default: false 458 bool round_halfway_to_even; 459 /// Multiply numerator and denominator to get integers (ex. (6x+y)/2z instead of (3x+0.5y)/z). Default: true 460 bool improve_division_multipliers; 461 /// Force use of a specific prefix for units if not NULL. Default: NULL 462 Prefix *prefix; 463 /// If not NULL will be set to true if the output is approximate. Default: NULL 464 bool *is_approximate; 465 /// Options for the order of values in the displayed expression. Default: default_sort_options 466 SortOptions sort_options; 467 /// Comma sign or empty string to use default comma sign. Default: empty string 468 std::string comma_sign; 469 /// Decimal sign or empty string to use default decimal sign. Default: empty string 470 std::string decimalpoint_sign; 471 /// Function that returns true if a text string with unicode signs can be properly displayed. Default: NULL 472 bool (*can_display_unicode_string_function) (const char*, void*); 473 /// Argument passed to can_display_unicode_string_function. Default: NULL 474 void *can_display_unicode_string_arg; 475 /// Replace underscores in names with spaces, unless name has suffix. Default: false 476 bool hide_underscore_spaces; 477 /// Preserves the format of the structure (no sorting, no changed prefixes, no improved division multipliers, etc.). Default: false 478 bool preserve_format; 479 /// Allows factorization to occur in the output (should be set to true if the structure has been factorized). Default: false 480 bool allow_factorization; 481 /// If logical operators will be spelled as AND and OR instead of && and ||. Default: false 482 bool spell_out_logical_operators; 483 /// Displays children of the structure with no higher precision than the parent. Default: true 484 bool restrict_to_parent_precision; 485 /// Restrict the length of numerators and demonitor as integers in decimal mode for fractional display of numbers. Default: false 486 bool restrict_fraction_length; 487 /// Transform exponentiation positive base and unit fraction exponent (if denominator < 10) to root function. Default: false 488 bool exp_to_root; 489 /// Use the internal precision of each number instead of global precision. Default: false 490 bool preserve_precision; 491 /// How number intervals will be displayed. Default: INTERVAL_DISPLAY_INTERVAL 492 IntervalDisplay interval_display; 493 /// Digit grouping separator. Default: DIGIT_GROUPING_NONE 494 DigitGrouping digit_grouping; 495 /// Format for time and date. Default: DATE_TIME_FORMAT_ISO 496 DateTimeFormat date_time_format; 497 /// Time zone for time and date. Default: TIME_ZONE_LOCAL 498 TimeZone time_zone; 499 /// Offset in minute for custom time zone. Default: 0 500 int custom_time_zone; 501 /// Negative binary numbers uses two's complement representation. All binary numbers starting with 1 are negative. Default: true 502 bool twos_complement; 503 /// Negative hexadecimal numbers uses two's complement representation. All hexadecimal numbers starting with 8 or higher are negative. Default: false 504 bool hexadecimal_twos_complement; 505 /// Number of bits used for binary numbers. Set to 0 for automatic. Default: 0 506 unsigned int binary_bits; 507 PrintOptions(); 508 /// Returns the comma sign used (default sign or comma_sign) 509 const std::string &comma() const; 510 /// Returns the decimal sign used (default sign or decimalpoint_sign) 511 const std::string &decimalpoint() const; 512 /// Returns the digit grouping separator used 513 } default_print_options; 514 515 static const struct InternalPrintStruct { 516 int depth, power_depth, division_depth; 517 bool wrap; 518 std::string *num, *den, *re, *im, *exp; 519 bool *minus, *exp_minus; 520 bool parent_approximate; 521 int parent_precision; 522 long int *iexp; 523 InternalPrintStruct(); 524 } top_ips; 525 526 typedef enum { 527 /// Allow only exact results 528 APPROXIMATION_EXACT, 529 /// Try to make the result as exact as possible 530 APPROXIMATION_TRY_EXACT, 531 /// Calculate the result approximately directly 532 APPROXIMATION_APPROXIMATE, 533 /// Used internally 534 APPROXIMATION_EXACT_VARIABLES 535 } ApproximationMode; 536 537 #define STRUCTURING_SIMPLIFY STRUCTURING_EXPAND 538 539 typedef enum { 540 /// Do not do any factorization or additional simplifications 541 STRUCTURING_NONE, 542 /// Simplify the result as much as possible and expand (minimal factorization, normally the same as STRUCTURING_NONE) 543 STRUCTURING_EXPAND, 544 /// Factorize the result 545 STRUCTURING_FACTORIZE, 546 /// Deprecated: use STRUCTURING_SIMPLIFY instead 547 STRUCTURING_HYBRID 548 } StructuringMode; 549 550 typedef enum { 551 /// Do not do any conversion of units in addition to syncing 552 POST_CONVERSION_NONE, 553 /// Convert to the least amount of units. Non-SI units are converted to SI units. 554 POST_CONVERSION_OPTIMAL_SI, 555 /// Convert to base units 556 POST_CONVERSION_BASE, 557 /// Convert to the the least amount of units. Non-SI units is kept (if optimal), but for conversion only SI units are used. 558 POST_CONVERSION_OPTIMAL 559 } AutoPostConversion; 560 561 #define POST_CONVERSION_BEST POST_CONVERSION_OPTIMAL_SI 562 563 typedef enum { 564 MIXED_UNITS_CONVERSION_NONE, 565 MIXED_UNITS_CONVERSION_DOWNWARDS_KEEP, 566 MIXED_UNITS_CONVERSION_DOWNWARDS, 567 MIXED_UNITS_CONVERSION_DEFAULT, 568 MIXED_UNITS_CONVERSION_FORCE_INTEGER, 569 MIXED_UNITS_CONVERSION_FORCE_ALL 570 } MixedUnitsConversion; 571 572 typedef enum { 573 DONT_READ_PRECISION, 574 ALWAYS_READ_PRECISION, 575 READ_PRECISION_WHEN_DECIMALS 576 } ReadPrecisionMode; 577 578 typedef enum { 579 ANGLE_UNIT_NONE, 580 ANGLE_UNIT_RADIANS, 581 ANGLE_UNIT_DEGREES, 582 ANGLE_UNIT_GRADIANS 583 } AngleUnit; 584 585 typedef enum { 586 COMPLEX_NUMBER_FORM_RECTANGULAR, 587 COMPLEX_NUMBER_FORM_EXPONENTIAL, 588 COMPLEX_NUMBER_FORM_POLAR, 589 COMPLEX_NUMBER_FORM_CIS 590 } ComplexNumberForm; 591 592 typedef enum { 593 /// The default adaptive mode works as the "parse implicit multiplication first" mode, unless spaces are found (<quote>1/5x = 1/(5*x)</quote>, but <quote>1/5 x = (1/5)*x</quote>). In the adaptive mode unit expressions are parsed separately (<quote>5 m/5 m/s = (5*m)/(5*(m/s)) = 1 s</quote>). 594 PARSING_MODE_ADAPTIVE, 595 /// In the "parse implicit multiplication first" mode, implicit multiplication is parsed before explicit multiplication (<quote>12/2(1+2) = 12/(2*3) = 2</quote>, <quote>5x/5y = (5*x)/(5*y) = x/y</quote>). 596 PARSING_MODE_IMPLICIT_MULTIPLICATION_FIRST, 597 /// In the conventional mode implicit multiplication does not differ from explicit multiplication (<quote>12/2(1+2) = 12/2*3 = 18</quote>, <quote>5x/5y = 5*x/5*y = xy</quote>). 598 PARSING_MODE_CONVENTIONAL, 599 // as immediate execution mode in simple traditional calculators (e.g. 5+2*3=(5+2)*3=21) 600 PARSING_MODE_CHAIN, 601 PARSING_MODE_RPN 602 } ParsingMode; 603 604 typedef enum { 605 /// Ignores uncertainties and uses the middle value of intervals 606 INTERVAL_CALCULATION_NONE, 607 INTERVAL_CALCULATION_VARIANCE_FORMULA, 608 INTERVAL_CALCULATION_INTERVAL_ARITHMETIC, 609 /// Treats all intervals as uncorrelated 610 INTERVAL_CALCULATION_SIMPLE_INTERVAL_ARITHMETIC 611 } IntervalCalculation; 612 613 /// Options for parsing expressions. 614 static const struct ParseOptions { 615 /// If variables will be parsed. Default: true 616 bool variables_enabled; 617 /// If functions will be parsed. Default: true 618 bool functions_enabled; 619 /// If left-over characters will be parsed as symbols. Default: true 620 bool unknowns_enabled; 621 /// If units will be parsed. Default: true 622 bool units_enabled; 623 /// If Reverse Polish Notation syntax will be used. Default: false (deprecated, use parsing_mode = PARSING_MODE_RPN instead) 624 bool rpn; 625 /// Base of parsed numbers. Default: 10 626 int base; 627 /// 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 628 /** 629 * 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". 630 */ 631 bool limit_implicit_multiplication; 632 /// If and when precisions will be read from number of digits in a number. Default: DONT_READ_PRECISION 633 ReadPrecisionMode read_precision; 634 /// If true dots will ignored if another character is the default decimal sign, to allow dots to be used as thousand separator. Default: false 635 bool dot_as_separator; 636 /// If true commas will ignored if another character is the default decimal sign, to allow commas to be used as thousand separator. You should also call CALCULATOR->useDecimalPoint(true). Default: false 637 bool comma_as_separator; 638 ///Interpret square brackets equally to parentheses (not only for vectors/matrices). Default; false 639 bool brackets_as_parentheses; 640 /// Default angle unit for trigonometric functions. Default: ANGLE_UNIT_NONE 641 AngleUnit angle_unit; 642 /// If non-NULL will be set to unfinished function at the end of the expression (if there is one). Default: NULL 643 MathStructure *unended_function; 644 /// Preserve the expression structure as much as possible. Default: false 645 bool preserve_format; 646 /// Default dataset. Used for object.property syntax without a preceeding data set. Default: NULL 647 DataSet *default_dataset; 648 /// Parsing mode. Default: PARSING_MODE_ADAPTIVE 649 ParsingMode parsing_mode; 650 /// Negative binary numbers uses two's complement representation. All binary numbers starting with 1 are assumed to be negative. Default: false 651 bool twos_complement; 652 /// Negative hexadecimal numbers uses two's complement representation. All hexadecimal numbers starting with 8 or higher are assumed to be negative. Default: false 653 bool hexadecimal_twos_complement; 654 655 ParseOptions(); 656 657 } default_parse_options; 658 659 /// Options for calculation. 660 static const struct EvaluationOptions { 661 /// How exact the result must be. Default: TRY_EXACT 662 ApproximationMode approximation; 663 /// If units will be synced/converted to allow evaluation (ex. 1 min + 1 s=60 s+ 1 s = 61 s). Default: true 664 bool sync_units; 665 /// If units with complex/non-linear relations (ex. degress celsius and fahrenheit) will synced/converted. Default: true 666 bool sync_nonlinear_unit_relations; 667 /// If unit prefixes in original expression will be kept. Default: false 668 bool keep_prefixes; 669 /// If known variables will be replaced by their value. Default: true 670 bool calculate_variables; 671 /// If functions will be calculated. Default: true 672 bool calculate_functions; 673 /// If comparisons will be evaluated (ex. 5>2 => 1). Default: true 674 int test_comparisons; 675 /// If a varaible will be isolated to the left side in equations/comparisons (ex. x+y=2 => x=2-y). Default: true 676 bool isolate_x; 677 /// If factors (and bases) containing addition will be expanded (ex. z(x+y)=zx+zy). Default: true 678 int expand; 679 /// Use behaviour from version <= 0.9.12 which returns (x+y)/z instead of x/y+y/z if expand = true 680 bool combine_divisions; 681 /// If non-numerical parts of a fraction will be reduced (ex. (5x)/(3xy) =5/(3y) . Default: true 682 bool reduce_divisions; 683 /// If complex numbers will be used for evaluation. Default: true 684 bool allow_complex; 685 /// If infinite numbers will be used for evaluation. Default: true 686 bool allow_infinite; 687 /// If simplification will be made easier by assuming that denominators with unknown value not is zero. Default: false 688 int assume_denominators_nonzero; 689 /// Warn if a denominator with unknown value was assumed non-zero (with assume_denominators_nonzero set to true) to allow simplification. Default: true 690 bool warn_about_denominators_assumed_nonzero; 691 /// 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 692 bool split_squares; 693 /// If units with zero quantity will be preserved. Default: true 694 bool keep_zero_units; 695 /// If and how units will be automatically converted. Does not affect syncing of units. Default: POST_CONVERSION_OPTIMAL 696 AutoPostConversion auto_post_conversion; 697 /// Shows time as h + min + s, imperial length as ft + in, etc. Default: MIXED_UNITS_CONVERSION_DEFAULT 698 MixedUnitsConversion mixed_units_conversion; 699 /// If the evaluation result will be expanded or factorized Default: STRUCTURING_NONE 700 StructuringMode structuring; 701 /// Options for parsing of expression. Default: default_parse_options 702 ParseOptions parse_options; 703 /// If set will decide which variable to isolate in an equation. Default: NULL 704 const MathStructure *isolate_var; 705 /// Use polynomial division to simplify the result. Default: true 706 bool do_polynomial_division; 707 /// Do not calculate the specified function. Default: NULL 708 MathFunction *protected_function; 709 /// Complex number form. Default: COMPLEX_NUMBER_FORM_RECTANGULAR 710 ComplexNumberForm complex_number_form; 711 /// Convert to local currency when optimal conversion is enabled 712 bool local_currency_conversion; 713 /// Mainly for internal use. Default: true 714 bool transform_trigonometric_functions; 715 /// Algorithm used for calculation of uncertainty propagation / intervals. This does not affect calculation of the high precision intervals produced by approximate functions or irrational numbers. Default: INTERVAL_CALCULATION_VARIANCE_FORMULA 716 IntervalCalculation interval_calculation; 717 718 EvaluationOptions(); 719 720 } default_evaluation_options; 721 722 static EvaluationOptions default_user_evaluation_options; 723 724 extern MathStructure m_undefined, m_empty_vector, m_empty_matrix, m_zero, m_one, m_minus_one, m_one_i; 725 extern Number nr_zero, nr_one, nr_two, nr_three, nr_minus_one, nr_one_i, nr_minus_i, nr_half, nr_minus_half, nr_plus_inf, nr_minus_inf; 726 extern EvaluationOptions no_evaluation; 727 extern ExpressionName empty_expression_name; 728 729 extern Calculator *calculator; 730 731 #define CALCULATOR calculator 732 733 #define DEFAULT_PRECISION 8 734 #define PRECISION (CALCULATOR ? CALCULATOR->getPrecision() : DEFAULT_PRECISION) 735 736 #define SIGN_DEGREE "°" 737 #define SIGN_POWER_0 "⁰" 738 #define SIGN_POWER_1 "¹" 739 #define SIGN_POWER_2 "²" 740 #define SIGN_POWER_3 "³" 741 #define SIGN_POWER_4 "⁴" 742 #define SIGN_POWER_5 "⁵" 743 #define SIGN_POWER_6 "⁶" 744 #define SIGN_POWER_7 "⁷" 745 #define SIGN_POWER_8 "⁸" 746 #define SIGN_POWER_9 "⁹" 747 #define SIGN_EURO "€" 748 #define SIGN_POUND "£" 749 #define SIGN_CENT "¢" 750 #define SIGN_YEN "¥" 751 #define SIGN_MICRO "µ" 752 #define SIGN_PI "π" 753 #define SIGN_MULTIPLICATION "×" 754 #define SIGN_MULTIDOT "⋅" 755 #define SIGN_MIDDLEDOT "·" 756 #define SIGN_MULTIBULLET "∙" 757 #define SIGN_SMALLCIRCLE "•" 758 #define SIGN_DIVISION_SLASH "∕" 759 #define SIGN_DIVISION "÷" 760 #define SIGN_MINUS "−" 761 #define SIGN_PLUS "+" 762 #define SIGN_SQRT "√" 763 #define SIGN_ALMOST_EQUAL "≈" 764 #define SIGN_APPROXIMATELY_EQUAL "≅" 765 #define SIGN_ZETA "ζ" 766 #define SIGN_GAMMA "γ" 767 #define SIGN_PHI "φ" 768 #define SIGN_LESS_OR_EQUAL "≤" 769 #define SIGN_GREATER_OR_EQUAL "≥" 770 #define SIGN_NOT_EQUAL "≠" 771 #define SIGN_CAPITAL_SIGMA "Σ" 772 #define SIGN_CAPITAL_PI "Π" 773 #define SIGN_CAPITAL_OMEGA "Ω" 774 #define SIGN_CAPITAL_GAMMA "Γ" 775 #define SIGN_CAPITAL_BETA "Β" 776 #define SIGN_INFINITY "∞" 777 #define SIGN_PLUSMINUS "±" 778 779 #define ID_WRAP_LEFT_CH '{' 780 #define ID_WRAP_RIGHT_CH '}' 781 782 #define DOT_CH '.' 783 #define ZERO_CH '0' 784 #define ONE_CH '1' 785 #define TWO_CH '2' 786 #define THREE_CH '3' 787 #define FOUR_CH '4' 788 #define FIVE_CH '5' 789 #define SIX_CH '6' 790 #define SEVEN_CH '7' 791 #define EIGHT_CH '8' 792 #define NINE_CH '9' 793 #define PLUS_CH '+' 794 #define MINUS_CH '-' 795 #define MULTIPLICATION_CH '*' 796 #define MULTIPLICATION_2_CH ' ' 797 #define DIVISION_CH '/' 798 #define EXP_CH 'E' 799 #define EXP2_CH 'e' 800 #define POWER_CH '^' 801 #define SPACE_CH ' ' 802 #define LEFT_PARENTHESIS_CH '(' 803 #define RIGHT_PARENTHESIS_CH ')' 804 #define LEFT_VECTOR_WRAP_CH '[' 805 #define RIGHT_VECTOR_WRAP_CH ']' 806 #define FUNCTION_VAR_PRE_CH '\\' 807 #define COMMA_CH ',' 808 #define NAME_NUMBER_PRE_CH '_' 809 #define UNIT_DIVISION_CH '/' 810 #define AND_CH '&' 811 #define OR_CH '|' 812 #define LESS_CH '<' 813 #define GREATER_CH '>' 814 #define BITWISE_NOT_CH '~' 815 #define LOGICAL_NOT_CH '!' 816 #define NOT_CH '!' 817 #define EQUALS_CH '=' 818 819 #define ID_WRAP_LEFT "{" 820 #define ID_WRAP_RIGHT "}" 821 #define ID_WRAPS "{}" 822 #define DOT "." 823 #define SEXADOT ":" 824 #define COMMA "," 825 #define COMMAS ",;" 826 #define NUMBERS "0123456789" 827 #define NUMBER_ELEMENTS "0123456789.:" 828 #define SIGNS "+-*/^" 829 #define OPERATORS "~+-*/^&|!<>=" 830 #define PARENTHESISS "()" 831 #define LEFT_PARENTHESIS "(" 832 #define RIGHT_PARENTHESIS ")" 833 #define VECTOR_WRAPS "[]" 834 #define LEFT_VECTOR_WRAP "[" 835 #define RIGHT_VECTOR_WRAP "]" 836 #define SPACES " \t\n" 837 #define SPACE " " 838 #define RESERVED "\'@\\{}?\"" 839 #define PLUS "+" 840 #define MINUS "-" 841 #define MULTIPLICATION "*" 842 #define MULTIPLICATION_2 " " 843 #define DIVISION "/" 844 #define EXP "E" 845 #define EXPS "Ee" 846 #define POWER "^" 847 #define LOGICAL_AND "&&" 848 #define LOGICAL_OR "||" 849 #define LOGICAL_NOT "!" 850 #define BITWISE_AND "&" 851 #define BITWISE_OR "|" 852 #define BITWISE_NOT "~" 853 #define SHIFT_RIGHT ">>" 854 #define SHIFT_LEFT "<<" 855 #define LESS "<" 856 #define GREATER ">" 857 #define NOT "!" 858 #define EQUALS "=" 859 #define SINF "INF" 860 //#define SNAN "NAN" 861 #define UNDERSCORE "_" 862 863 #define NOT_IN_NAMES RESERVED OPERATORS SPACES SEXADOT DOT VECTOR_WRAPS PARENTHESISS COMMAS 864 865 #endif 866