MinitScript  0.9.31 PRE-BETA
MathMethods.cpp
Go to the documentation of this file.
1 #include <span>
2 
8 
9 using std::span;
10 
12 
14 
17 
18 void MathMethods::registerDataType(MinitScript::DataType* dataType) {
19  dataTypes.push_back(dataType);
20 }
21 
22 void MathMethods::registerConstants() {
23  minitScript->setConstant("$math::DEG2RAD", MinitScript::Variable(_Math::DEG2RAD));
24  minitScript->setConstant("$math::EPSILON", MinitScript::Variable(_Math::EPSILON));
25  minitScript->setConstant("$math::PI", MinitScript::Variable(_Math::PI));
26 }
27 
28 void MathMethods::registerMethods() {
29  // operator methods
30  {
31  //
32  class MethodAdd: public MinitScript::Method {
33  private:
34  MinitScript* minitScript { nullptr };
35  public:
36  MethodAdd(MinitScript* minitScript):
38  {
39  { .type = MinitScript::TYPE_PSEUDO_MIXED, .name = "a", .optional = false, .reference = false, .nullable = false },
40  { .type = MinitScript::TYPE_PSEUDO_MIXED, .name = "b", .optional = false, .reference = false, .nullable = false },
41  { .type = MinitScript::TYPE_INTEGER, .name = "operator", .optional = true, .reference = false, .nullable = false }
42  },
43  MinitScript::TYPE_PSEUDO_MIXED
44  ),
45  minitScript(minitScript) {}
46  const string getMethodName() override {
47  return "add";
48  }
49  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
50  minitScript->getMathMethods()->add(arguments, returnValue, subStatement);
51  }
52  MinitScript::Operator getOperator() const override {
53  return MinitScript::OPERATOR_ADDITION;
54  }
55  };
56  minitScript->registerMethod(new MethodAdd(minitScript));
57  }
58  {
59  //
60  class MethodSub: public MinitScript::Method {
61  private:
62  MinitScript* minitScript { nullptr };
63  public:
64  MethodSub(MinitScript* minitScript):
66  {
67  { .type = MinitScript::TYPE_PSEUDO_MIXED, .name = "a", .optional = false, .reference = false, .nullable = false },
68  { .type = MinitScript::TYPE_PSEUDO_MIXED, .name = "b", .optional = false, .reference = false, .nullable = false },
69  { .type = MinitScript::TYPE_INTEGER, .name = "operator", .optional = true, .reference = false, .nullable = false }
70  },
71  MinitScript::TYPE_PSEUDO_MIXED
72  ),
73  minitScript(minitScript) {}
74  const string getMethodName() override {
75  return "sub";
76  }
77  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
78  minitScript->getMathMethods()->sub(arguments, returnValue, subStatement);
79  }
80  MinitScript::Operator getOperator() const override {
81  return MinitScript::OPERATOR_SUBTRACTION;
82  }
83  };
84  minitScript->registerMethod(new MethodSub(minitScript));
85  }
86  {
87  //
88  class MethodMul: public MinitScript::Method {
89  private:
90  MinitScript* minitScript { nullptr };
91  public:
92  MethodMul(MinitScript* minitScript):
94  {
95  { .type = MinitScript::TYPE_PSEUDO_MIXED, .name = "a", .optional = false, .reference = false, .nullable = false },
96  { .type = MinitScript::TYPE_PSEUDO_MIXED, .name = "b", .optional = false, .reference = false, .nullable = false },
97  { .type = MinitScript::TYPE_INTEGER, .name = "operator", .optional = true, .reference = false, .nullable = false }
98  },
99  MinitScript::TYPE_PSEUDO_MIXED
100  ),
101  minitScript(minitScript) {}
102  const string getMethodName() override {
103  return "mul";
104  }
105  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
106  minitScript->getMathMethods()->mul(arguments, returnValue, subStatement);
107  }
108  MinitScript::Operator getOperator() const override {
109  return MinitScript::OPERATOR_MULTIPLICATION;
110  }
111  };
112  minitScript->registerMethod(new MethodMul(minitScript));
113  }
114  {
115  //
116  class MethodDiv: public MinitScript::Method {
117  private:
118  MinitScript* minitScript { nullptr };
119  public:
120  MethodDiv(MinitScript* minitScript):
122  {
123  { .type = MinitScript::TYPE_PSEUDO_MIXED, .name = "a", .optional = false, .reference = false, .nullable = false },
124  { .type = MinitScript::TYPE_PSEUDO_MIXED, .name = "b", .optional = false, .reference = false, .nullable = false },
125  { .type = MinitScript::TYPE_INTEGER, .name = "operator", .optional = true, .reference = false, .nullable = false }
126  },
127  MinitScript::TYPE_PSEUDO_MIXED
128  ),
129  minitScript(minitScript) {}
130  const string getMethodName() override {
131  return "div";
132  }
133  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
134  minitScript->getMathMethods()->div(arguments, returnValue, subStatement);
135  }
136  MinitScript::Operator getOperator() const override {
137  return MinitScript::OPERATOR_DIVISION;
138  }
139  };
140  minitScript->registerMethod(new MethodDiv(minitScript));
141  }
142  {
143  //
144  class MethodMod: public MinitScript::Method {
145  private:
146  MinitScript* minitScript { nullptr };
147  public:
148  MethodMod(MinitScript* minitScript): MinitScript::Method(
149  {
150  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "value", .optional = false, .reference = false, .nullable = false },
151  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "range", .optional = false, .reference = false, .nullable = false },
152  { .type = MinitScript::TYPE_INTEGER, .name = "operator", .optional = true, .reference = false, .nullable = false }
153  },
154  MinitScript::TYPE_PSEUDO_NUMBER
155  ), minitScript(minitScript) {}
156  const string getMethodName() override {
157  return "mod";
158  }
159  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
160  if (arguments.size() == 2 || arguments.size() == 3) {
161  if (MinitScript::hasType(arguments, MinitScript::TYPE_INTEGER) == true) {
162  int64_t value;
163  int64_t range;
164  // TODO: correct complains
165  if (MinitScript::getIntegerValue(arguments, 0, value, false) == true &&
166  MinitScript::getIntegerValue(arguments, 1, range, false) == true) {
167  returnValue.setValue(_Math::mod(value, range));
168  } else {
169  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
170  }
171  } else {
172  float value;
173  float range;
174  // TODO: correct complains
175  if (MinitScript::getFloatValue(arguments, 0, value, false) == true &&
176  MinitScript::getFloatValue(arguments, 1, range, false) == true) {
177  returnValue.setValue(_Math::mod(value, range));
178  } else {
179  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
180  }
181  }
182  } else {
183  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
184  }
185  }
186  MinitScript::Operator getOperator() const override {
187  return MinitScript::OPERATOR_MODULO;
188  }
189  };
190  minitScript->registerMethod(new MethodMod(minitScript));
191  }
192  {
193  //
194  class MethodAcos: public MinitScript::Method {
195  private:
196  MinitScript* minitScript { nullptr };
197  public:
198  MethodAcos(MinitScript* minitScript): MinitScript::Method(
199  {
200  { .type = MinitScript::TYPE_FLOAT, .name = "x", .optional = false, .reference = false, .nullable = false },
201  },
202  MinitScript::TYPE_FLOAT), minitScript(minitScript) {}
203  const string getMethodName() override {
204  return "math.acos";
205  }
206  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
207  float x;
208  if (arguments.size() == 1 &&
209  MinitScript::getFloatValue(arguments, 0, x) == true) {
210  returnValue.setValue(_Math::acos(x));
211  } else {
212  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
213  }
214  }
215  };
216  minitScript->registerMethod(new MethodAcos(minitScript));
217  }
218  {
219  //
220  class MethodAsin: public MinitScript::Method {
221  private:
222  MinitScript* minitScript { nullptr };
223  public:
224  MethodAsin(MinitScript* minitScript): MinitScript::Method(
225  {
226  { .type = MinitScript::TYPE_FLOAT, .name = "x", .optional = false, .reference = false, .nullable = false },
227  },
228  MinitScript::TYPE_FLOAT), minitScript(minitScript) {}
229  const string getMethodName() override {
230  return "math.asin";
231  }
232  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
233  float x;
234  if (arguments.size() == 1 &&
235  MinitScript::getFloatValue(arguments, 0, x) == true) {
236  returnValue.setValue(_Math::asin(x));
237  } else {
238  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
239  }
240  }
241  };
242  minitScript->registerMethod(new MethodAsin(minitScript));
243  }
244  {
245  //
246  class MethodAtan: public MinitScript::Method {
247  private:
248  MinitScript* minitScript { nullptr };
249  public:
250  MethodAtan(MinitScript* minitScript): MinitScript::Method(
251  {
252  { .type = MinitScript::TYPE_FLOAT, .name = "x", .optional = false, .reference = false, .nullable = false },
253  },
254  MinitScript::TYPE_FLOAT), minitScript(minitScript) {}
255  const string getMethodName() override {
256  return "math.atan";
257  }
258  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
259  float x;
260  if (arguments.size() == 1 &&
261  MinitScript::getFloatValue(arguments, 0, x) == true) {
262  returnValue.setValue(_Math::atan(x));
263  } else {
264  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
265  }
266  }
267  };
268  minitScript->registerMethod(new MethodAtan(minitScript));
269  }
270  {
271  //
272  class MethodAtan2: public MinitScript::Method {
273  private:
274  MinitScript* minitScript { nullptr };
275  public:
276  MethodAtan2(MinitScript* minitScript): MinitScript::Method(
277  {
278  { .type = MinitScript::TYPE_FLOAT, .name = "y", .optional = false, .reference = false, .nullable = false },
279  { .type = MinitScript::TYPE_FLOAT, .name = "x", .optional = false, .reference = false, .nullable = false },
280  },
281  MinitScript::TYPE_FLOAT), minitScript(minitScript) {}
282  const string getMethodName() override {
283  return "math.atan2";
284  }
285  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
286  float y;
287  float x;
288  if (arguments.size() == 2 &&
289  MinitScript::getFloatValue(arguments, 0, y) == true &&
290  MinitScript::getFloatValue(arguments, 1, x) == true) {
291  returnValue.setValue(_Math::atan2(y, x));
292  } else {
293  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
294  }
295  }
296  };
297  minitScript->registerMethod(new MethodAtan2(minitScript));
298  }
299  {
300  //
301  class MethodTan: public MinitScript::Method {
302  private:
303  MinitScript* minitScript { nullptr };
304  public:
305  MethodTan(MinitScript* minitScript): MinitScript::Method(
306  {
307  { .type = MinitScript::TYPE_FLOAT, .name = "x", .optional = false, .reference = false, .nullable = false },
308  },
309  MinitScript::TYPE_FLOAT), minitScript(minitScript) {}
310  const string getMethodName() override {
311  return "math.tan";
312  }
313  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
314  float x;
315  if (arguments.size() == 1 &&
316  MinitScript::getFloatValue(arguments, 0, x) == true) {
317  returnValue.setValue(_Math::tan(x));
318  } else {
319  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
320  }
321  }
322  };
323  minitScript->registerMethod(new MethodTan(minitScript));
324  }
325  {
326  //
327  class MethodCos: public MinitScript::Method {
328  private:
329  MinitScript* minitScript { nullptr };
330  public:
331  MethodCos(MinitScript* minitScript): MinitScript::Method(
332  {
333  { .type = MinitScript::TYPE_FLOAT, .name = "x", .optional = false, .reference = false, .nullable = false },
334  },
335  MinitScript::TYPE_FLOAT), minitScript(minitScript) {}
336  const string getMethodName() override {
337  return "math.cos";
338  }
339  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
340  float x;
341  if (arguments.size() == 1 &&
342  MinitScript::getFloatValue(arguments, 0, x) == true) {
343  returnValue.setValue(_Math::cos(x));
344  } else {
345  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
346  }
347  }
348  };
349  minitScript->registerMethod(new MethodCos(minitScript));
350  }
351  {
352  //
353  class MethodSin: public MinitScript::Method {
354  private:
355  MinitScript* minitScript { nullptr };
356  public:
357  MethodSin(MinitScript* minitScript): MinitScript::Method(
358  {
359  { .type = MinitScript::TYPE_FLOAT, .name = "x", .optional = false, .reference = false, .nullable = false },
360  },
361  MinitScript::TYPE_FLOAT), minitScript(minitScript) {}
362  const string getMethodName() override {
363  return "math.sin";
364  }
365  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
366  float x;
367  if (arguments.size() == 1 &&
368  MinitScript::getFloatValue(arguments, 0, x) == true) {
369  returnValue.setValue(_Math::sin(x));
370  } else {
371  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
372  }
373  }
374  };
375  minitScript->registerMethod(new MethodSin(minitScript));
376  }
377  {
378  //
379  class MethodFloor: public MinitScript::Method {
380  private:
381  MinitScript* minitScript { nullptr };
382  public:
383  MethodFloor(MinitScript* minitScript): MinitScript::Method(
384  {
385  { .type = MinitScript::TYPE_FLOAT, .name = "value", .optional = false, .reference = false, .nullable = false },
386  },
387  MinitScript::TYPE_FLOAT), minitScript(minitScript) {}
388  const string getMethodName() override {
389  return "math.floor";
390  }
391  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
392  float value;
393  if (arguments.size() == 1 &&
394  MinitScript::getFloatValue(arguments, 0, value) == true) {
395  returnValue.setValue(_Math::floor(value));
396  } else {
397  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
398  }
399  }
400  };
401  minitScript->registerMethod(new MethodFloor(minitScript));
402  }
403  {
404  //
405  class MethodCeil: public MinitScript::Method {
406  private:
407  MinitScript* minitScript { nullptr };
408  public:
409  MethodCeil(MinitScript* minitScript): MinitScript::Method(
410  {
411  { .type = MinitScript::TYPE_FLOAT, .name = "value", .optional = false, .reference = false, .nullable = false },
412  },
413  MinitScript::TYPE_FLOAT), minitScript(minitScript) {}
414  const string getMethodName() override {
415  return "math.ceil";
416  }
417  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
418  float value;
419  if (arguments.size() == 1 &&
420  MinitScript::getFloatValue(arguments, 0, value) == true) {
421  returnValue.setValue(_Math::ceil(value));
422  } else {
423  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
424  }
425  }
426  };
427  minitScript->registerMethod(new MethodCeil(minitScript));
428  }
429  {
430  //
431  class MethodRound: public MinitScript::Method {
432  private:
433  MinitScript* minitScript { nullptr };
434  public:
435  MethodRound(MinitScript* minitScript): MinitScript::Method(
436  {
437  { .type = MinitScript::TYPE_FLOAT, .name = "value", .optional = false, .reference = false, .nullable = false },
438  },
439  MinitScript::TYPE_FLOAT), minitScript(minitScript) {}
440  const string getMethodName() override {
441  return "math.round";
442  }
443  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
444  float value;
445  if (arguments.size() == 1 &&
446  MinitScript::getFloatValue(arguments, 0, value) == true) {
447  returnValue.setValue(_Math::round(value));
448  } else {
449  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
450  }
451  }
452  };
453  minitScript->registerMethod(new MethodRound(minitScript));
454  }
455  {
456  //
457  class MethodSqrt: public MinitScript::Method {
458  private:
459  MinitScript* minitScript { nullptr };
460  public:
461  MethodSqrt(MinitScript* minitScript): MinitScript::Method(
462  {
463  { .type = MinitScript::TYPE_FLOAT, .name = "value", .optional = false, .reference = false, .nullable = false },
464  },
465  MinitScript::TYPE_FLOAT), minitScript(minitScript) {}
466  const string getMethodName() override {
467  return "math.sqrt";
468  }
469  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
470  float value;
471  if (arguments.size() == 1 &&
472  MinitScript::getFloatValue(arguments, 0, value) == true) {
473  returnValue.setValue(_Math::sqrt(value));
474  } else {
475  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
476  }
477  }
478  };
479  minitScript->registerMethod(new MethodSqrt(minitScript));
480  }
481  {
482  //
483  class MethodRandom: public MinitScript::Method {
484  private:
485  MinitScript* minitScript { nullptr };
486  public:
487  MethodRandom(MinitScript* minitScript): MinitScript::Method({}, MinitScript::TYPE_FLOAT), minitScript(minitScript) {}
488  const string getMethodName() override {
489  return "math.random";
490  }
491  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
492  if (arguments.size() == 0) {
493  returnValue.setValue(_Math::random());
494  } else {
495  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
496  }
497  }
498  };
499  minitScript->registerMethod(new MethodRandom(minitScript));
500  }
501  {
502  //
503  class MethodExp: public MinitScript::Method {
504  private:
505  MinitScript* minitScript { nullptr };
506  public:
507  MethodExp(MinitScript* minitScript): MinitScript::Method(
508  {
509  { .type = MinitScript::TYPE_FLOAT, .name = "power", .optional = false, .reference = false, .nullable = false },
510  },
511  MinitScript::TYPE_FLOAT), minitScript(minitScript) {}
512  const string getMethodName() override {
513  return "math.exp";
514  }
515  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
516  float power;
517  if (arguments.size() == 1 &&
518  MinitScript::getFloatValue(arguments, 0, power) == true) {
519  returnValue.setValue(_Math::exp(power));
520  } else {
521  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
522  }
523  }
524  };
525  minitScript->registerMethod(new MethodExp(minitScript));
526  }
527  {
528  //
529  class MethodLog: public MinitScript::Method {
530  private:
531  MinitScript* minitScript { nullptr };
532  public:
533  MethodLog(MinitScript* minitScript): MinitScript::Method(
534  {
535  { .type = MinitScript::TYPE_FLOAT, .name = "value", .optional = false, .reference = false, .nullable = false },
536  },
537  MinitScript::TYPE_FLOAT), minitScript(minitScript) {}
538  const string getMethodName() override {
539  return "math.log";
540  }
541  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
542  float value;
543  if (arguments.size() == 1 &&
544  MinitScript::getFloatValue(arguments, 0, value) == true) {
545  returnValue.setValue(_Math::log(value));
546  } else {
547  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
548  }
549  }
550  };
551  minitScript->registerMethod(new MethodLog(minitScript));
552  }
553  {
554  //
555  class MethodSign: public MinitScript::Method {
556  private:
557  MinitScript* minitScript { nullptr };
558  public:
559  MethodSign(MinitScript* minitScript): MinitScript::Method(
560  {
561  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "value", .optional = false, .reference = false, .nullable = false },
562  },
563  MinitScript::TYPE_PSEUDO_NUMBER),
564  minitScript(minitScript) {}
565  const string getMethodName() override {
566  return "math.sign";
567  }
568  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
569  if (arguments.size() == 1) {
570  int64_t intValue;
571  float floatValue;
572  if (MinitScript::hasType(arguments, MinitScript::TYPE_FLOAT) == true && MinitScript::getFloatValue(arguments, 0, floatValue) == true) {
573  returnValue.setValue(_Math::sign(floatValue));
574  } else
575  if (MinitScript::getIntegerValue(arguments, 0, intValue) == true) {
576  returnValue.setValue(_Math::sign(intValue));
577  } else {
578  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
579  }
580  } else {
581  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
582  }
583  }
584  };
585  minitScript->registerMethod(new MethodSign(minitScript));
586  }
587  {
588  //
589  class MethodSquare: public MinitScript::Method {
590  private:
591  MinitScript* minitScript { nullptr };
592  public:
593  MethodSquare(MinitScript* minitScript): MinitScript::Method(
594  {
595  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "value", .optional = false, .reference = false, .nullable = false },
596  },
597  MinitScript::TYPE_PSEUDO_NUMBER),
598  minitScript(minitScript) {}
599  const string getMethodName() override {
600  return "math.square";
601  }
602  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
603  if (arguments.size() == 1) {
604  int64_t intValue;
605  float floatValue;
606  if (MinitScript::hasType(arguments, MinitScript::TYPE_FLOAT) == true && MinitScript::getFloatValue(arguments, 0, floatValue) == true) {
607  returnValue.setValue(_Math::square(floatValue));
608  } else
609  if (MinitScript::getIntegerValue(arguments, 0, intValue) == true) {
610  returnValue.setValue(_Math::square(intValue));
611  } else {
612  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
613  }
614  } else {
615  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
616  }
617  }
618  };
619  minitScript->registerMethod(new MethodSquare(minitScript));
620  }
621  {
622  //
623  class MethodMin: public MinitScript::Method {
624  private:
625  MinitScript* minitScript { nullptr };
626  public:
627  MethodMin(MinitScript* minitScript): MinitScript::Method(
628  {
629  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "value1", .optional = false, .reference = false, .nullable = false },
630  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "value2", .optional = false, .reference = false, .nullable = false },
631  },
632  MinitScript::TYPE_PSEUDO_NUMBER),
633  minitScript(minitScript) {}
634  const string getMethodName() override {
635  return "math.min";
636  }
637  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
638  if (arguments.size() == 2) {
639  int64_t intValue1;
640  int64_t intValue2;
641  float floatValue1;
642  float floatValue2;
643  if (MinitScript::hasType(arguments, MinitScript::TYPE_FLOAT) == true &&
644  MinitScript::getFloatValue(arguments, 0, floatValue1) == true &&
645  MinitScript::getFloatValue(arguments, 1, floatValue2) == true) {
646  returnValue.setValue(_Math::min(floatValue1, floatValue2));
647  } else
648  if (MinitScript::getIntegerValue(arguments, 0, intValue1) == true &&
649  MinitScript::getIntegerValue(arguments, 1, intValue2) == true) {
650  returnValue.setValue(_Math::min(intValue1, intValue2));
651  } else {
652  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
653  }
654  } else {
655  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
656  }
657  }
658  };
659  minitScript->registerMethod(new MethodMin(minitScript));
660  }
661  {
662  //
663  class MethodMax: public MinitScript::Method {
664  private:
665  MinitScript* minitScript { nullptr };
666  public:
667  MethodMax(MinitScript* minitScript): MinitScript::Method(
668  {
669  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "value1", .optional = false, .reference = false, .nullable = false },
670  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "value2", .optional = false, .reference = false, .nullable = false },
671  },
672  MinitScript::TYPE_PSEUDO_NUMBER),
673  minitScript(minitScript) {}
674  const string getMethodName() override {
675  return "math.max";
676  }
677  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
678  if (arguments.size() == 2) {
679  int64_t intValue1;
680  int64_t intValue2;
681  float floatValue1;
682  float floatValue2;
683  if (MinitScript::hasType(arguments, MinitScript::TYPE_FLOAT) == true &&
684  MinitScript::getFloatValue(arguments, 0, floatValue1) == true &&
685  MinitScript::getFloatValue(arguments, 1, floatValue2) == true) {
686  returnValue.setValue(_Math::max(floatValue1, floatValue2));
687  } else
688  if (MinitScript::getIntegerValue(arguments, 0, intValue1) == true &&
689  MinitScript::getIntegerValue(arguments, 1, intValue2) == true) {
690  returnValue.setValue(_Math::max(intValue1, intValue2));
691  } else {
692  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
693  }
694  } else {
695  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
696  }
697  }
698  };
699  minitScript->registerMethod(new MethodMax(minitScript));
700  }
701  {
702  //
703  class MethodAbs: public MinitScript::Method {
704  private:
705  MinitScript* minitScript { nullptr };
706  public:
707  MethodAbs(MinitScript* minitScript): MinitScript::Method(
708  {
709  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "value", .optional = false, .reference = false, .nullable = false },
710  },
711  MinitScript::TYPE_PSEUDO_NUMBER),
712  minitScript(minitScript) {}
713  const string getMethodName() override {
714  return "math.abs";
715  }
716  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
717  if (arguments.size() == 1) {
718  int64_t intValue;
719  float floatValue;
720  if (MinitScript::hasType(arguments, MinitScript::TYPE_FLOAT) == true && MinitScript::getFloatValue(arguments, 0, floatValue) == true) {
721  returnValue.setValue(_Math::abs(floatValue));
722  } else
723  if (MinitScript::getIntegerValue(arguments, 0, intValue) == true) {
724  returnValue.setValue(_Math::abs(intValue));
725  } else {
726  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
727  }
728  } else {
729  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
730  }
731  }
732  };
733  minitScript->registerMethod(new MethodAbs(minitScript));
734  }
735  {
736  //
737  class MethodClamp: public MinitScript::Method {
738  private:
739  MinitScript* minitScript { nullptr };
740  public:
741  MethodClamp(MinitScript* minitScript): MinitScript::Method(
742  {
743  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "value", .optional = false, .reference = false, .nullable = false },
744  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "min", .optional = false, .reference = false, .nullable = false },
745  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "max", .optional = false, .reference = false, .nullable = false },
746  },
747  MinitScript::TYPE_PSEUDO_NUMBER),
748  minitScript(minitScript) {}
749  const string getMethodName() override {
750  return "math.clamp";
751  }
752  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
753  if (arguments.size() == 3) {
754  int64_t intValueA;
755  int64_t intValueB;
756  int64_t intValueC;
757  float floatValueA;
758  float floatValueB;
759  float floatValueC;
760  if (MinitScript::hasType(arguments, MinitScript::TYPE_FLOAT) == true &&
761  MinitScript::getFloatValue(arguments, 0, floatValueA) == true &&
762  MinitScript::getFloatValue(arguments, 1, floatValueB) == true &&
763  MinitScript::getFloatValue(arguments, 2, floatValueC) == true) {
764  returnValue.setValue(_Math::clamp(floatValueA, floatValueB, floatValueC));
765  } else
766  if (MinitScript::getIntegerValue(arguments, 0, intValueA) == true &&
767  MinitScript::getIntegerValue(arguments, 1, intValueB) == true &&
768  MinitScript::getIntegerValue(arguments, 2, intValueC) == true) {
769  returnValue.setValue(_Math::clamp(intValueA, intValueB, intValueC));
770  } else {
771  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
772  }
773  } else {
774  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
775  }
776  }
777  };
778  minitScript->registerMethod(new MethodClamp(minitScript));
779  }
780  {
781  //
782  class MethodPow: public MinitScript::Method {
783  private:
784  MinitScript* minitScript { nullptr };
785  public:
786  MethodPow(MinitScript* minitScript): MinitScript::Method(
787  {
788  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "base", .optional = false, .reference = false, .nullable = false },
789  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "power", .optional = false, .reference = false, .nullable = false },
790  },
791  MinitScript::TYPE_PSEUDO_NUMBER),
792  minitScript(minitScript) {}
793  const string getMethodName() override {
794  return "math.pow";
795  }
796  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
797  if (arguments.size() == 2) {
798  int64_t intValueBase;
799  int64_t intValuePower;
800  float floatValueBase;
801  float floatValuePower;
802  if (MinitScript::hasType(arguments, MinitScript::TYPE_FLOAT) == true &&
803  MinitScript::getFloatValue(arguments, 0, floatValueBase) == true &&
804  MinitScript::getFloatValue(arguments, 1, floatValuePower) == true) {
805  returnValue.setValue(_Math::pow(floatValueBase, floatValuePower));
806  } else
807  if (MinitScript::getIntegerValue(arguments, 0, intValueBase) == true &&
808  MinitScript::getIntegerValue(arguments, 1, intValuePower) == true) {
809  returnValue.setValue(static_cast<int64_t>(_Math::pow(intValueBase, intValuePower)));
810  } else {
811  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
812  }
813  } else {
814  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
815  }
816  }
817  };
818  minitScript->registerMethod(new MethodPow(minitScript));
819  }
820  {
821  //
822  class MethodMod: public MinitScript::Method {
823  private:
824  MinitScript* minitScript { nullptr };
825  public:
826  MethodMod(MinitScript* minitScript): MinitScript::Method(
827  {
828  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "value", .optional = false, .reference = false, .nullable = false },
829  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "range", .optional = false, .reference = false, .nullable = false },
830  },
831  MinitScript::TYPE_PSEUDO_NUMBER
832  ), minitScript(minitScript) {}
833  const string getMethodName() override {
834  return "math.mod";
835  }
836  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
837  if (arguments.size() == 2) {
838  if (MinitScript::hasType(arguments, MinitScript::TYPE_INTEGER) == true) {
839  int64_t value;
840  int64_t range;
841  if (MinitScript::getIntegerValue(arguments, 0, value) == true &&
842  MinitScript::getIntegerValue(arguments, 1, range) == true) {
843  returnValue.setValue(_Math::mod(value, range));
844  } else {
845  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
846  }
847  } else {
848  float value;
849  float range;
850  if (MinitScript::getFloatValue(arguments, 0, value) == true &&
851  MinitScript::getFloatValue(arguments, 1, range) == true) {
852  returnValue.setValue(_Math::mod(value, range));
853  } else {
854  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
855  }
856  }
857  } else {
858  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
859  }
860  }
861  };
862  minitScript->registerMethod(new MethodMod(minitScript));
863  }
864  {
865  //
866  class MethodAbsMod: public MinitScript::Method {
867  private:
868  MinitScript* minitScript { nullptr };
869  public:
870  MethodAbsMod(MinitScript* minitScript): MinitScript::Method(
871  {
872  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "value", .optional = false, .reference = false, .nullable = false },
873  { .type = MinitScript::TYPE_PSEUDO_NUMBER, .name = "range", .optional = false, .reference = false, .nullable = false },
874  },
875  MinitScript::TYPE_PSEUDO_NUMBER
876  ), minitScript(minitScript) {}
877  const string getMethodName() override {
878  return "math.absmod";
879  }
880  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
881  if (arguments.size() == 2) {
882  if (MinitScript::hasType(arguments, MinitScript::TYPE_INTEGER) == true) {
883  int64_t value;
884  int64_t range;
885  if (MinitScript::getIntegerValue(arguments, 0, value) == true &&
886  MinitScript::getIntegerValue(arguments, 1, range) == true) {
887  returnValue.setValue(_Math::absmod(value, range));
888  } else {
889  minitScript->complain(getMethodName(), subStatement);
890  minitScript->startErrorScript();
891  }
892  } else {
893  float value;
894  float range;
895  if (MinitScript::getFloatValue(arguments, 0, value) == true &&
896  MinitScript::getFloatValue(arguments, 1, range) == true) {
897  returnValue.setValue(_Math::absmod(value, range));
898  } else {
899  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
900  }
901  }
902  } else {
903  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
904  }
905  }
906  };
907  minitScript->registerMethod(new MethodAbsMod(minitScript));
908  }
909 }
910 
911 void MathMethods::mul(const span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) {
912  if (arguments.size() != 2 && arguments.size() != 3) {
913  minitScript->complain(MinitScript::decodeOperator(arguments, 2, "mul"), subStatement); minitScript->startErrorScript();
914  return;
915  }
916  // custom data types
917  for (const auto dataType: dataTypes) {
918  if (dataType->mul(minitScript, arguments, returnValue, subStatement) == true) return;
919  }
920  // float
921  if (MinitScript::hasTypeForOperatorArguments(arguments, MinitScript::TYPE_FLOAT) == true) {
922  float a;
923  float b;
924  auto isAFloat = MinitScript::getFloatValue(arguments, 0, a, false);
925  auto isBFloat = MinitScript::getFloatValue(arguments, 1, b, false);
926  if (isAFloat == true &&
927  isBFloat == true) {
928  returnValue.setValue(a * b);
929  return;
930  } else {
931  minitScript->complainOperator(
932  "mul",
933  MinitScript::decodeOperator(arguments, 2, "mul"),
934  subStatement,
935  string(isAFloat == false?"Left argument '" + arguments[0].getValueAsString() + "' is not a float value":"") +
936  string(isBFloat == false?string(isAFloat == false?" and right argument":"Right argument") + " '" + arguments[1].getValueAsString() + "' is not a float value":"")
937  );
938  minitScript->startErrorScript();
939  return;
940  }
941  } else {
942  // int
943  int64_t a;
944  int64_t b;
945  auto isAInteger = MinitScript::getIntegerValue(arguments, 0, a, false) == true;
946  auto isBInteger = MinitScript::getIntegerValue(arguments, 1, b, false) == true;
947  if (isAInteger == true &&
948  isBInteger == true) {
949  returnValue.setValue(a * b);
950  return;
951  } else {
952  minitScript->complainOperator(
953  "mul",
954  MinitScript::decodeOperator(arguments, 2, "mul"),
955  subStatement,
956  string(isAInteger == false?"Left argument '" + arguments[0].getValueAsString() + "' is not a integer value":"") +
957  string(isBInteger == false?string(isAInteger == false?" and right argument":"Right argument") + " '" + arguments[1].getValueAsString() + "' is not a integer value":"")
958  );
959  minitScript->startErrorScript();
960  return;
961  }
962  }
963 }
964 
965 void MathMethods::div(const span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) {
966  if (arguments.size() != 2 && arguments.size() != 3) {
967  minitScript->complain(MinitScript::decodeOperator(arguments, 2, "div"), subStatement); minitScript->startErrorScript();
968  return;
969  }
970  // custom data types
971  for (const auto dataType: dataTypes) {
972  if (dataType->div(minitScript, arguments, returnValue, subStatement) == true) return;
973  }
974  // float
975  if (MinitScript::hasTypeForOperatorArguments(arguments, MinitScript::TYPE_FLOAT) == true) {
976  float a;
977  float b;
978  auto isAFloat = MinitScript::getFloatValue(arguments, 0, a, false);
979  auto isBFloat = MinitScript::getFloatValue(arguments, 1, b, false);
980  if (isAFloat == true &&
981  isBFloat == true) {
982  returnValue.setValue(a / b);
983  return;
984  } else {
985  minitScript->complainOperator(
986  "div",
987  MinitScript::decodeOperator(arguments, 2, "div"),
988  subStatement,
989  string(isAFloat == false?"Left argument '" + arguments[0].getValueAsString() + "' is not a float value":"") +
990  string(isBFloat == false?string(isAFloat == false?" and right argument":"Right argument") + " '" + arguments[1].getValueAsString() + "' is not a float value":"")
991  );
992  minitScript->startErrorScript();
993  return;
994  }
995  } else {
996  // int
997  int64_t a;
998  int64_t b;
999  auto isAInteger = MinitScript::getIntegerValue(arguments, 0, a, false) == true;
1000  auto isBInteger = MinitScript::getIntegerValue(arguments, 1, b, false) == true;
1001  if (isAInteger == true &&
1002  isBInteger == true) {
1003  returnValue.setValue(a / b);
1004  return;
1005  } else {
1006  minitScript->complainOperator(
1007  "div",
1008  MinitScript::decodeOperator(arguments, 2, "div"),
1009  subStatement,
1010  string(isAInteger == false?"Left argument '" + arguments[0].getValueAsString() + "' is not a integer value":"") +
1011  string(isBInteger == false?string(isAInteger == false?" and right argument":"Right argument") + " '" + arguments[1].getValueAsString() + "' is not a integer value":"")
1012  );
1013  minitScript->startErrorScript();
1014  return;
1015  }
1016  }
1017 }
1018 
1019 void MathMethods::add(const span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) {
1020  if (arguments.size() != 2 && arguments.size() != 3) {
1021  minitScript->complain(MinitScript::decodeOperator(arguments, 2, "add"), subStatement); minitScript->startErrorScript();
1022  return;
1023  }
1024  // string concatenation
1025  if (MinitScript::hasTypeForOperatorArguments(arguments, MinitScript::TYPE_STRING) == true) {
1026  string result;
1027  for (auto i = 0; i < arguments.size() - 1; i++) {
1028  result+= arguments[i].getValueAsString();
1029  }
1030  returnValue.setValue(result);
1031  return;
1032  }
1033  // custom data types
1034  for (const auto dataType: dataTypes) {
1035  if (dataType->add(minitScript, arguments, returnValue, subStatement) == true) return;
1036  }
1037  // float
1038  if (MinitScript::hasTypeForOperatorArguments(arguments, MinitScript::TYPE_FLOAT) == true) {
1039  float a;
1040  float b;
1041  auto isAFloat = MinitScript::getFloatValue(arguments, 0, a, false);
1042  auto isBFloat = MinitScript::getFloatValue(arguments, 1, b, false);
1043  if (isAFloat == true &&
1044  isBFloat == true) {
1045  returnValue.setValue(a + b);
1046  return;
1047  } else {
1048  minitScript->complainOperator(
1049  "add",
1050  MinitScript::decodeOperator(arguments, 2, "add"),
1051  subStatement,
1052  string(isAFloat == false?"Left argument '" + arguments[0].getValueAsString() + "' is not a float value":"") +
1053  string(isBFloat == false?string(isAFloat == false?" and right argument":"Right argument") + " '" + arguments[1].getValueAsString() + "' is not a float value":"")
1054  );
1055  minitScript->startErrorScript();
1056  return;
1057  }
1058  } else {
1059  // int
1060  int64_t a;
1061  int64_t b;
1062  auto isAInteger = MinitScript::getIntegerValue(arguments, 0, a, false) == true;
1063  auto isBInteger = MinitScript::getIntegerValue(arguments, 1, b, false) == true;
1064  if (isAInteger == true &&
1065  isBInteger == true) {
1066  returnValue.setValue(a + b);
1067  return;
1068  } else {
1069  minitScript->complainOperator(
1070  "add",
1071  MinitScript::decodeOperator(arguments, 2, "add"),
1072  subStatement,
1073  string(isAInteger == false?"Left argument '" + arguments[0].getValueAsString() + "' is not a integer value":"") +
1074  string(isBInteger == false?string(isAInteger == false?" and right argument":"Right argument") + " '" + arguments[1].getValueAsString() + "' is not a integer value":"")
1075  );
1076  minitScript->startErrorScript();
1077  return;
1078  }
1079  }
1080 }
1081 
1082 void MathMethods::sub(const span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) {
1083  if (arguments.size() != 2 && arguments.size() != 3) {
1084  minitScript->complain(MinitScript::decodeOperator(arguments, 2, "sub"), subStatement); minitScript->startErrorScript();
1085  return;
1086  }
1087  // custom data types
1088  for (const auto dataType: dataTypes) {
1089  if (dataType->sub(minitScript, arguments, returnValue, subStatement) == true) return;
1090  }
1091  // float
1092  if (MinitScript::hasTypeForOperatorArguments(arguments, MinitScript::TYPE_FLOAT) == true) {
1093  float a;
1094  float b;
1095  auto isAFloat = MinitScript::getFloatValue(arguments, 0, a, false);
1096  auto isBFloat = MinitScript::getFloatValue(arguments, 1, b, false);
1097  if (isAFloat == true &&
1098  isBFloat == true) {
1099  returnValue.setValue(a - b);
1100  return;
1101  } else {
1102  minitScript->complainOperator(
1103  "sub",
1104  MinitScript::decodeOperator(arguments, 2, "sub"),
1105  subStatement,
1106  string(isAFloat == false?"Left argument '" + arguments[0].getValueAsString() + "' is not a float value":"") +
1107  string(isBFloat == false?string(isAFloat == false?" and right argument":"Right argument") + " '" + arguments[1].getValueAsString() + "' is not a float value":"")
1108  );
1109  minitScript->startErrorScript();
1110  return;
1111  }
1112  } else {
1113  // int
1114  int64_t a;
1115  int64_t b;
1116  auto isAInteger = MinitScript::getIntegerValue(arguments, 0, a, false) == true;
1117  auto isBInteger = MinitScript::getIntegerValue(arguments, 1, b, false) == true;
1118  if (isAInteger == true &&
1119  isBInteger == true) {
1120  returnValue.setValue(a - b);
1121  return;
1122  } else {
1123  minitScript->complainOperator(
1124  "sub",
1125  MinitScript::decodeOperator(arguments, 2, "sub"),
1126  subStatement,
1127  string(isAInteger == false?"Left argument '" + arguments[0].getValueAsString() + "' is not a integer value":"") +
1128  string(isBInteger == false?string(isAInteger == false?" and right argument":"Right argument") + " '" + arguments[1].getValueAsString() + "' is not a integer value":"")
1129  );
1130  minitScript->startErrorScript();
1131  return;
1132  }
1133  }
1134 }
#define MINITSCRIPT_METHODUSAGE_COMPLAIN(methodName)
Definition: MinitScript.h:59
Standard math functions.
Definition: Math.h:19
static float sqrt(float value)
Returns the square root of given value.
Definition: Math.h:192
static float log(float value)
Returns the natural (base e) logarithm of value.
Definition: Math.h:219
static float round(float value)
Returns the rounded value of given float value.
Definition: Math.h:156
static float sin(float x)
Returns the sine of x.
Definition: Math.h:183
static float tan(float x)
Returns the tangent of x.
Definition: Math.h:201
static float atan(float x)
Returns the arc tangent of x.
Definition: Math.h:90
static auto mod(auto value, auto range)
Returns modulo of value, so that return value is -range < value < range.
Definition: Math.h:229
static auto square(auto value)
Do the square product.
Definition: Math.h:54
static float floor(float value)
Returns the lower integer value of given value.
Definition: Math.h:127
static float cos(float x)
Returns the cosine of x.
Definition: Math.h:118
static constexpr float EPSILON
Definition: Math.h:22
static auto abs(auto value)
Returns absolute value.
Definition: Math.h:63
static float asin(float x)
Returns the arc sine of x.
Definition: Math.h:81
static float random()
Returns a random value between 0.0 .
Definition: Math.h:174
static auto absmod(auto value, auto range)
Returns absolute modulo of value, so that return value is 0 <= value < range.
Definition: Math.h:249
static auto min(auto value1, auto value2)
Returns the lesser value of given values.
Definition: Math.h:147
static float acos(float x)
Returns the arc cosine of x.
Definition: Math.h:72
static auto max(auto value1, auto value2)
Returns the higher value of given values.
Definition: Math.h:137
static float atan2(float y, float x)
Returns the angle from the conversion of rectangular coordinates to polar coordinates.
Definition: Math.h:100
static float exp(float power)
Returns e raised to the given power.
Definition: Math.h:210
static auto pow(auto base, auto power)
Returns the value of base raised to the power.
Definition: Math.h:166
static constexpr float PI
Definition: Math.h:21
static auto sign(auto value)
Returns sign of value.
Definition: Math.h:44
static float ceil(float value)
Returns the higher integer value of given value.
Definition: Math.h:109
static constexpr float DEG2RAD
Definition: Math.h:23
static auto clamp(auto value, auto min, auto max)
Clamps a value to min or max value.
Definition: Math.h:33
MinitScript math methods.
Definition: MathMethods.h:16
void div(const span< MinitScript::Variable > &arguments, MinitScript::Variable &returnValue, const MinitScript::SubStatement &subStatement)
Division.
void sub(const span< MinitScript::Variable > &arguments, MinitScript::Variable &returnValue, const MinitScript::SubStatement &subStatement)
Subtraction.
void mul(const span< MinitScript::Variable > &arguments, MinitScript::Variable &returnValue, const MinitScript::SubStatement &subStatement)
Multiply.
void add(const span< MinitScript::Variable > &arguments, MinitScript::Variable &returnValue, const MinitScript::SubStatement &subStatement)
Addition.
void setValue(const Variable &variable)
Set value from given variable into variable.
Definition: MinitScript.h:1618
void complain(const string &methodName, const SubStatement &subStatement)
Complain about method usage.
void startErrorScript()
Start error script.
Definition: MinitScript.h:4499