Skip to content

fixing negative power to zero#22277

Open
raushanprabhakar1 wants to merge 1 commit into
apache:mainfrom
raushanprabhakar1:feat/22272-fix-negative-power-zero
Open

fixing negative power to zero#22277
raushanprabhakar1 wants to merge 1 commit into
apache:mainfrom
raushanprabhakar1:feat/22272-fix-negative-power-zero

Conversation

@raushanprabhakar1
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

PostgreSQL rejects power(0::float8, negative::float8) because zero raised to a negative power is undefined. DataFusion used f64::powf, which returns infinity for that case. This aligns float (and related decimal float paths) with PostgreSQL’s domain semantics.

What changes are included in this PR?

  • Added float64_power_checked to error when base == 0.0 and exp < 0.0 with message zero raised to a negative power is undefined.
  • Wired it into Float64/Float64 power, decimal array-exponent float fallback, and compute_pow_f64_result.
  • Updated math.slt expectations for pow(0, -0.5) and added coverage for power(0.0::float8, -1.0::float8).
  • Added unit tests in power.rs.

Are these changes tested?

Yes. Unit tests in datafusion/functions/src/math/power.rs, and SQL logic tests in datafusion/sqllogictest/test_files/math.slt (including the regression for #22272).

Are there any user-facing changes?

Yes. Queries that previously returned positive infinity for power / pow with a zero base and negative exponent now return a runtime error (compute error) with that message, matching PostgreSQL for this case.

No public Rust API signature changes; treat as SQL/runtime behavior only unless your process labels SQL semantics as API.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels May 16, 2026
@raushanprabhakar1
Copy link
Copy Markdown
Contributor Author

Hi @Dandandan , requesting you to review. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL compatibility: power(0.0::float8, -1.0::float8) should error, not return infinity

1 participant