-
Notifications
You must be signed in to change notification settings - Fork 2
/
parser_operators.h
executable file
·923 lines (682 loc) · 23.6 KB
/
parser_operators.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
/*
* Copyright (C) 2000, 2013 Thierry Crozat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact: criezy01@gmail.com
*/
#ifndef parser_operators_h
#define parser_operators_h
#include <stdlib.h>
#include <math.h>
#include "str.h"
#include "list.h"
#include "strlist.h"
#include "math_utils.h"
#ifdef PARSER_TREE_DEBUG
#include <typeinfo>
#endif
/*! \class ParserOperator
*
* This is an internal class for the EquationParser. It is the base
* class for all the operators (or functions) recognized by the parser.
*/
class ParserOperator {
public:
virtual ~ParserOperator();
virtual double evaluate() const = 0;
// Use by operator =
// Reimplement in classes that can change the argument value.
virtual bool canBeModified() const;
virtual double setValue(double value);
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return typeid(*this).name(); }
virtual int nbChildren() const { return 0; }
virtual ParserOperator* child(int) const { return NULL; }
#endif
protected:
ParserOperator();
};
class ConstantOperator : public ParserOperator {
public:
ConstantOperator(double c, const String& name = String());
virtual ~ConstantOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const {
if (name_.isEmpty())
return String::format("Constant: %f", var_dbl);
return String::format("Constant: %s (%f)", name_.c_str(), var_dbl);
}
#endif
private:
double var_dbl;
String name_;
};
class VariableOperator : public ParserOperator {
public:
VariableOperator(double *vardbl, const String& name);
virtual ~VariableOperator();
virtual double evaluate() const;
virtual bool canBeModified() const;
virtual double setValue(double value);
const String& name() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const {
return String::format("Variable: %s", name_.c_str());
}
#endif
private:
double *var_dbl;
String name_;
};
class PrintOperator : public ParserOperator {
public:
PrintOperator(const List<ParserOperator*>& values, const StringList& strings);
virtual ~PrintOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Print"; }
virtual int nbChildren() const {
int cpt = 0;
for (int i = 0 ; i < values_.size() ; ++i)
if (values_[i] != NULL)
++cpt;
return cpt;
}
virtual ParserOperator* child(int idx) const {
if (idx < 0)
return NULL;
int cpt = 0;
for (int i = 0 ; i < values_.size() ; ++i) {
if (values_[i] != NULL) {
if (idx == cpt)
return values_[i];
else
++cpt;
}
}
return NULL;
}
#endif
private:
List<ParserOperator*> values_;
StringList strings_;
};
class IfOperator : public ParserOperator {
public:
IfOperator(ParserOperator *test, ParserOperator *left, ParserOperator *right);
virtual ~IfOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "If"; }
virtual int nbChildren() const { return 3; }
virtual ParserOperator* child(int i) const { return i == 0 ? test : (i == 1 ? larg : (i == 2 ? rarg : NULL)); }
#endif
private:
ParserOperator *test;
ParserOperator *larg;
ParserOperator *rarg;
};
class ParserOperator1 : public ParserOperator {
public:
virtual ~ParserOperator1();
#ifdef PARSER_TREE_DEBUG
virtual int nbChildren() const { return 1; }
virtual ParserOperator* child(int i) const { return i == 0 ? arg : NULL; }
#endif
protected:
ParserOperator1(ParserOperator *argument);
ParserOperator *arg;
};
class ParserOperator2 : public ParserOperator {
public:
virtual ~ParserOperator2();
#ifdef PARSER_TREE_DEBUG
virtual int nbChildren() const { return 2; }
virtual ParserOperator* child(int i) const { return i == 0 ? larg : (i == 1 ? rarg : NULL); }
#endif
protected:
ParserOperator2(ParserOperator *left, ParserOperator *right);
ParserOperator *larg;
ParserOperator *rarg;
};
class OrOperator : public ParserOperator2 {
public:
OrOperator(ParserOperator *left, ParserOperator *right);
virtual ~OrOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Or"; }
#endif
};
class AndOperator : public ParserOperator2 {
public:
AndOperator(ParserOperator *left, ParserOperator *right);
virtual ~AndOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "And"; }
#endif
};
class EqualOperator : public ParserOperator2 {
public:
EqualOperator(ParserOperator *left, ParserOperator *right);
virtual ~EqualOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Is equal"; }
#endif
};
class GreaterOperator : public ParserOperator2 {
public:
GreaterOperator(ParserOperator *left, ParserOperator *right);
virtual ~GreaterOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Is greater"; }
#endif
};
class SmallerOperator : public ParserOperator2 {
public:
SmallerOperator(ParserOperator *left, ParserOperator *right);
virtual ~SmallerOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Is smaller"; }
#endif
};
class EqualOrGreaterOperator : public ParserOperator2 {
public:
EqualOrGreaterOperator(ParserOperator *left, ParserOperator *right);
virtual ~EqualOrGreaterOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Is equal or greater"; }
#endif
};
class EqualOrSmallerOperator : public ParserOperator2 {
public:
EqualOrSmallerOperator(ParserOperator *left, ParserOperator *right);
virtual ~EqualOrSmallerOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Is equal or smaller"; }
#endif
};
class NotEqualOperator : public ParserOperator2 {
public:
NotEqualOperator(ParserOperator *left, ParserOperator *right);
virtual ~NotEqualOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Is not equal"; }
#endif
};
class AssignmentOperator : public ParserOperator2 {
public:
AssignmentOperator(ParserOperator *left, ParserOperator *right);
virtual ~AssignmentOperator();
virtual double evaluate() const;
virtual bool canBeModified() const;
virtual double setValue(double value);
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Assign"; }
#endif
};
class IncrementOperator : public ParserOperator2 {
public:
IncrementOperator(ParserOperator *left, ParserOperator *right);
virtual ~IncrementOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Increment"; }
#endif
};
class SignOperator : public ParserOperator1 {
public:
SignOperator(ParserOperator* argument);
virtual ~SignOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Sign"; }
#endif
};
class NSignOperator : public ParserOperator1 {
public:
NSignOperator(ParserOperator *argument);
virtual ~NSignOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Change sign"; }
#endif
};
class PlusOperator : public ParserOperator2 {
public:
PlusOperator(ParserOperator *left, ParserOperator *right);
virtual ~PlusOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Add"; }
#endif
};
class MinusOperator : public ParserOperator2 {
public:
MinusOperator(ParserOperator *left, ParserOperator *right);
virtual ~MinusOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Substract"; }
#endif
};
class MultiplyOperator : public ParserOperator2 {
public:
MultiplyOperator(ParserOperator *left, ParserOperator *right);
virtual ~MultiplyOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Multiply"; }
#endif
};
class MultiplyAndAssignOperator : public ParserOperator2 {
public:
MultiplyAndAssignOperator(ParserOperator *left, ParserOperator *right);
virtual ~MultiplyAndAssignOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Multiply and assign"; }
#endif
};
class DivideOperator : public ParserOperator2 {
public:
DivideOperator(ParserOperator *left, ParserOperator *right);
virtual ~DivideOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Divide"; }
#endif
};
class DivideAndAssignOperator : public ParserOperator2 {
public:
DivideAndAssignOperator(ParserOperator *left, ParserOperator *right);
virtual ~DivideAndAssignOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Divide and assign"; }
#endif
};
class ModuloOperator : public ParserOperator2 {
public:
ModuloOperator(ParserOperator *left, ParserOperator *right);
virtual ~ModuloOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Modulo"; }
#endif
};
class SqrtOperator : public ParserOperator1 {
public:
SqrtOperator(ParserOperator *argument);
virtual ~SqrtOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Square root"; }
#endif
};
class CbrtOperator : public ParserOperator1 {
public:
CbrtOperator(ParserOperator *argument);
virtual ~CbrtOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Cubic root"; }
#endif
};
class CosOperator : public ParserOperator1 {
public:
CosOperator(ParserOperator *argument);
virtual ~CosOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Cosine"; }
#endif
};
class SinOperator : public ParserOperator1 {
public:
SinOperator(ParserOperator *argument);
virtual ~SinOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Sine"; }
#endif
};
class TanOperator : public ParserOperator1 {
public:
TanOperator(ParserOperator *argument);
virtual ~TanOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Tangent"; }
#endif
};
class ExpOperator : public ParserOperator1 {
public:
ExpOperator(ParserOperator *argument);
virtual ~ExpOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Exponential"; }
#endif
};
class LogOperator : public ParserOperator1 {
public:
LogOperator(ParserOperator *argument);
virtual ~LogOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Natural logarithm"; }
#endif
};
class Log10Operator : public ParserOperator1 {
public:
Log10Operator(ParserOperator *argument);
virtual ~Log10Operator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Base 10 logarithm"; }
#endif
};
class ASinOperator : public ParserOperator1 {
public:
ASinOperator(ParserOperator *argument);
virtual ~ASinOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Arc sine"; }
#endif
};
class ACosOperator : public ParserOperator1 {
public:
ACosOperator(ParserOperator *argument);
virtual ~ACosOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Arc cosine"; }
#endif
};
class ATanOperator : public ParserOperator1 {
public:
ATanOperator(ParserOperator *argument);
virtual ~ATanOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Arc tangent"; }
#endif
};
class ATan2Operator : public ParserOperator2 {
public:
ATan2Operator(ParserOperator *left, ParserOperator *right);
virtual ~ATan2Operator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Arc tangent of two arguments"; }
#endif
};
class SinHOperator : public ParserOperator1 {
public:
SinHOperator(ParserOperator *argument);
virtual ~SinHOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Hyperbolic sine"; }
#endif
};
class CosHOperator : public ParserOperator1 {
public:
CosHOperator(ParserOperator *argument);
virtual ~CosHOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Hyperbolic cosine"; }
#endif
};
class TanHOperator : public ParserOperator1 {
public:
TanHOperator(ParserOperator *argument);
virtual ~TanHOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Hyperbolic tangent"; }
#endif
};
class ASinHOperator : public ParserOperator1 {
public:
ASinHOperator(ParserOperator *argument);
virtual ~ASinHOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Inverse hyperbolic sine"; }
#endif
};
class ACosHOperator : public ParserOperator1 {
public:
ACosHOperator(ParserOperator *argument);
virtual ~ACosHOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Inverse hyperbolic cosine"; }
#endif
};
class ATanHOperator : public ParserOperator1 {
public:
ATanHOperator(ParserOperator *argument);
virtual ~ATanHOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Inverse hyperbolic tangent"; }
#endif
};
class RoundOperator : public ParserOperator1 {
public:
RoundOperator(ParserOperator *argument);
virtual ~RoundOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Round to nearest"; }
#endif
};
class CeilOperator : public ParserOperator1 {
public:
CeilOperator(ParserOperator *argument);
virtual ~CeilOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Round up"; }
#endif
};
class FloorOperator : public ParserOperator1 {
public:
FloorOperator(ParserOperator *argument);
virtual ~FloorOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Round down"; }
#endif
};
class FAbsOperator : public ParserOperator1 {
public:
FAbsOperator(ParserOperator *argument);
virtual ~FAbsOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Absolute value"; }
#endif
};
class PowOperator : public ParserOperator2 {
public:
PowOperator(ParserOperator *left, ParserOperator *right);
virtual ~PowOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Pow"; }
#endif
};
class Deg2RadOperator : public ParserOperator1 {
public:
Deg2RadOperator(ParserOperator *argument);
virtual ~Deg2RadOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Convert angle from degree to radian"; }
#endif
};
class Rad2DegOperator : public ParserOperator1 {
public:
Rad2DegOperator(ParserOperator *argument);
virtual ~Rad2DegOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Convert angle from radian to degree"; }
#endif
};
class MinimumOperator : public ParserOperator2 {
public:
MinimumOperator(ParserOperator *left, ParserOperator *right);
virtual ~MinimumOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Minimum"; }
#endif
};
class MaximumOperator : public ParserOperator2 {
public:
MaximumOperator(ParserOperator *left, ParserOperator *right);
virtual ~MaximumOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Maximum"; }
#endif
};
class URandOperator : public ParserOperator2 {
public:
URandOperator(ParserOperator *min, ParserOperator *max);
virtual ~URandOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Uniform distribution random number"; }
#endif
};
class NRandOperator : public ParserOperator2 {
public:
NRandOperator(ParserOperator *mean, ParserOperator *sigma);
virtual ~NRandOperator();
virtual double evaluate() const;
static double generateValue();
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Normal distribution random number"; }
#endif
};
class RandSeedOperator : public ParserOperator1 {
public:
RandSeedOperator(ParserOperator *seed);
virtual ~RandSeedOperator();
virtual double evaluate() const;
#ifdef PARSER_TREE_DEBUG
virtual String operatorName() const { return "Set seed for random numbers"; }
#endif
};
/***********************************************************
* Inline Functions implementation
***********************************************************/
inline bool ParserOperator::canBeModified() const { return false;}
inline double ParserOperator::setValue(double value) {return value;}
inline double ConstantOperator::evaluate() const {return var_dbl;}
inline double VariableOperator::evaluate() const {return *var_dbl;}
inline bool VariableOperator::canBeModified() const { return true;}
inline double VariableOperator::setValue(double value) {return (*var_dbl = value);}
inline const String& VariableOperator::name() const {return name_;}
inline double IfOperator::evaluate() const {return (!MathUtils::isEqual(test->evaluate(), 0.) ? larg->evaluate() : rarg->evaluate());}
inline double OrOperator::evaluate() const {return (!MathUtils::isEqual(larg->evaluate(), 0.) || !MathUtils::isEqual(rarg->evaluate(), 0.) ? 1. : 0.);}
inline double AndOperator::evaluate() const {return (!MathUtils::isEqual(larg->evaluate(), 0.) && !MathUtils::isEqual(rarg->evaluate(), 0.) ? 1. : 0.);}
inline double EqualOperator::evaluate() const {return (MathUtils::isEqual(larg->evaluate(), rarg->evaluate()) ? 1. : 0.);}
inline double GreaterOperator::evaluate() const {return (larg->evaluate() > rarg->evaluate() ? 1. : 0.);}
inline double SmallerOperator::evaluate() const {return (larg->evaluate() < rarg->evaluate() ? 1. : 0.);}
inline double EqualOrGreaterOperator::evaluate() const {return (MathUtils::isSupOrEqual(larg->evaluate(), rarg->evaluate()) ? 1. : 0.);}
inline double EqualOrSmallerOperator::evaluate() const {return (MathUtils::isInfOrEqual(larg->evaluate(), rarg->evaluate()) ? 1. : 0.);}
inline double NotEqualOperator::evaluate() const {return (!MathUtils::isEqual(larg->evaluate(), rarg->evaluate()) ? 1. : 0.);}
inline double AssignmentOperator::evaluate() const {return larg->setValue(rarg->evaluate());}
// Assignment operator can be modified if right operand can be modified.
// This allows having a = b = c = 0; for example.
// Assigning to the right argument needs to also do the evaluation, and thus set the left argument afterward.
inline bool AssignmentOperator::canBeModified() const { return rarg->canBeModified();}
inline double AssignmentOperator::setValue(double value) {return larg->setValue(rarg->setValue(value));}
inline double IncrementOperator::evaluate() const {return larg->setValue(larg->evaluate() + rarg->evaluate());}
inline double SignOperator::evaluate() const {return arg->evaluate() < 0. ? -1. : 1.;}
inline double NSignOperator::evaluate() const {return -1.*arg->evaluate();}
inline double PlusOperator::evaluate() const {return larg->evaluate() + rarg->evaluate();}
inline double MinusOperator::evaluate() const {return larg->evaluate() - rarg->evaluate();}
inline double MultiplyOperator::evaluate() const {return larg->evaluate() * rarg->evaluate();}
inline double MultiplyAndAssignOperator::evaluate() const {return larg->setValue(larg->evaluate() * rarg->evaluate());}
inline double DivideOperator::evaluate() const {return larg->evaluate() / rarg->evaluate();}
inline double DivideAndAssignOperator::evaluate() const {return larg->setValue(larg->evaluate() / rarg->evaluate());}
inline double ModuloOperator::evaluate() const {return fmod(larg->evaluate(), rarg->evaluate());}
inline double SqrtOperator::evaluate() const {return sqrt(arg->evaluate());}
inline double CbrtOperator::evaluate() const {return cbrt(arg->evaluate());}
inline double CosOperator::evaluate() const {return cos(arg->evaluate());}
inline double SinOperator::evaluate() const {return sin(arg->evaluate());}
inline double TanOperator::evaluate() const {return tan(arg->evaluate());}
inline double ExpOperator::evaluate() const {return exp(arg->evaluate());}
inline double LogOperator::evaluate() const {return log(arg->evaluate());}
inline double Log10Operator::evaluate() const {return log10(arg->evaluate());}
inline double ASinOperator::evaluate() const {return asin(arg->evaluate());}
inline double ACosOperator::evaluate() const {return acos(arg->evaluate());}
inline double ATanOperator::evaluate() const {return atan(arg->evaluate());}
inline double ATan2Operator::evaluate() const {return atan2(larg->evaluate(), rarg->evaluate());}
inline double SinHOperator::evaluate() const {return sinh(arg->evaluate());}
inline double CosHOperator::evaluate() const {return cosh(arg->evaluate());}
inline double TanHOperator::evaluate() const {return tanh(arg->evaluate());}
inline double ASinHOperator::evaluate() const {return asinh(arg->evaluate());}
inline double ACosHOperator::evaluate() const {return acosh(arg->evaluate());}
inline double ATanHOperator::evaluate() const {return atanh(arg->evaluate());}
inline double RoundOperator::evaluate() const {
double v = arg->evaluate();
return (double)(int)(v < 0. ? (v - 0.5) : (v + 0.5));
}
inline double CeilOperator::evaluate() const {return ceil(arg->evaluate());}
inline double FloorOperator::evaluate() const {return floor(arg->evaluate());}
inline double FAbsOperator::evaluate() const {return fabs(arg->evaluate());}
inline double PowOperator::evaluate() const {return pow(larg->evaluate(),rarg->evaluate());}
inline double Deg2RadOperator::evaluate() const {return arg->evaluate() * M_PI / 180.;}
inline double Rad2DegOperator::evaluate() const {return arg->evaluate() * 180. / M_PI;}
inline double MinimumOperator::evaluate() const {
double v1 = larg->evaluate(), v2 = rarg->evaluate();
return v1 < v2 ? v1 : v2;
}
inline double MaximumOperator::evaluate() const {
double v1 = larg->evaluate(), v2 = rarg->evaluate();
return v1 < v2 ? v2 : v1;
}
inline double URandOperator::evaluate() const {
double minimum = larg->evaluate(), maximum = rarg->evaluate();
return minimum + rand() * (maximum - minimum) / RAND_MAX;
}
inline double NRandOperator::evaluate() const {
return larg->evaluate() + rarg->evaluate() * generateValue();
}
inline double RandSeedOperator::evaluate() const {
unsigned int s = (unsigned int)arg->evaluate();
srand(s);
return (double)s;
}
#endif