From 001ad09cfbd5d79220858d711986fa387c946bea Mon Sep 17 00:00:00 2001 From: Osamaali313 Date: Sat, 18 Jul 2026 23:32:15 +0300 Subject: [PATCH] Fix POWER formula returning the base for a zero exponent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `POWER(base, exponent)` formula function reads its exponent with a truthy fallback: const exponent = params[1]?.value || 1; return Math.pow(value, exponent); `POWER(x, 0)` must return 1 (x^0 = 1), but `0 || 1` evaluates to 1, so the exponent silently becomes 1 and the function returns the base `x` instead. `validateParams` throws when fewer than 2 params are given, so `params[1]` always exists at eval time — the `|| 1` default is never needed for a missing argument and its only reachable effect is corrupting an explicitly passed `0`. The sibling `Ceiling`/`Floor` functions use `params[1]?.value || 0`, which is harmless there because their default equals the falsy value; `Power` is the one case where the default (1) differs from the meaningful falsy input (0). Use `??` so an explicit `0` exponent is honored. --- packages/core/src/formula/functions/numeric.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/formula/functions/numeric.ts b/packages/core/src/formula/functions/numeric.ts index d3eea279e5..e570380963 100644 --- a/packages/core/src/formula/functions/numeric.ts +++ b/packages/core/src/formula/functions/numeric.ts @@ -576,7 +576,7 @@ export class Power extends NumericFunc { eval(params: TypedValue[]): number | null { const value = params[0].value; if (value == null) return null; - const exponent = params[1]?.value || 1; + const exponent = params[1]?.value ?? 1; return Math.pow(value, exponent); } }