Skip to content

Commit 20ae423

Browse files
authored
Merge pull request #1177 from m-muecke/perf/etscalc-damped-phistar
perf(ets): replace pow() with running power in damped forecast loop
2 parents 682618b + 6c64e08 commit 20ae423

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/etscalc.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ SEXP etsforecast(SEXP x, SEXP m, SEXP trend, SEXP season, SEXP phi, SEXP h) {
260260

261261
static void forecast(double l, double b, const double *s, int m, int trend,
262262
int season, double phi, double *f, int h) {
263-
double phistar = phi;
263+
double phistar = phi, phipow = phi;
264264

265265
// FORECASTS
266266
for (int i = 0; i < h; i++) {
@@ -280,10 +280,12 @@ static void forecast(double l, double b, const double *s, int m, int trend,
280280
else if (season == MULT)
281281
f[i] = f[i] * s[j];
282282
if (i < (h - 1)) {
283-
if (fabs(phi - 1.0) < TOL)
283+
if (fabs(phi - 1.0) < TOL) {
284284
phistar = phistar + 1.0;
285-
else
286-
phistar = phistar + pow(phi, (double)(i + 2));
285+
} else {
286+
phipow *= phi;
287+
phistar += phipow;
288+
}
287289
}
288290
}
289291
}

0 commit comments

Comments
 (0)