| 516 | } |
| 517 | |
| 518 | double smmin(double x, const std::string_view& variable, const std::weak_ptr<Payload> payload) { |
| 519 | const auto p = std::dynamic_pointer_cast<PayloadExpressionParser>(payload.lock()); |
| 520 | if (!p) { |
| 521 | assert(p); // Debug build |
| 522 | return NAN; |
| 523 | } |
| 524 | |
| 525 | for (int i = 0; i < p->vars->length(); i++) { |
| 526 | if (p->vars->at(i).compare(QLatin1String(variable)) == 0) { |
| 527 | const int N = x; |
| 528 | DEBUG("N = " << N) |
| 529 | if (N < 1) |
| 530 | break; |
| 531 | // calculate min of last n points |
| 532 | double min = INFINITY; |
| 533 | const int row = p->row; |
| 534 | for (int index = std::max(0, row - N + 1); index <= row; index++) { |
| 535 | const double v = p->xVectors->at(i)->at(index); |
| 536 | if (v < min) |
| 537 | min = v; |
| 538 | } |
| 539 | return min; |
| 540 | } |
| 541 | } |
| 542 | return NAN; |
| 543 | } |
| 544 | |
| 545 | double smmax(double x, const std::string_view& variable, const std::weak_ptr<Payload> payload) { |
| 546 | const auto p = std::dynamic_pointer_cast<PayloadExpressionParser>(payload.lock()); |