MCPcopy Create free account
hub / github.com/KDE/labplot / smmax

Function smmax

src/backend/gsl/ExpressionParser.cpp:545–570  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

543}
544
545double 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());
547 if (!p) {
548 assert(p); // Debug build
549 return NAN;
550 }
551
552 for (int i = 0; i < p->vars->length(); i++) {
553 if (p->vars->at(i).compare(QLatin1String(variable)) == 0) {
554 const int N = x;
555 DEBUG("N = " << N)
556 if (N < 1)
557 break;
558 // calculate max of last n points
559 double max = -INFINITY;
560 const int row = p->row;
561 for (int index = std::max(0, row - N + 1); index <= row; index++) {
562 const double v = p->xVectors->at(i)->at(index);
563 if (v > max)
564 max = v;
565 }
566 return max;
567 }
568 }
569 return NAN;
570}
571
572double sma(double x, const std::string_view& variable, const std::weak_ptr<Payload> payload) {
573 const auto p = std::dynamic_pointer_cast<PayloadExpressionParser>(payload.lock());

Callers 1

smrFunction · 0.85

Calls 1

lengthMethod · 0.80

Tested by

no test coverage detected