Skip to content

fix: error on negative ln inputs#22410

Open
puneetdixit200 wants to merge 1 commit into
apache:mainfrom
puneetdixit200:fix/22271-ln-negative-error
Open

fix: error on negative ln inputs#22410
puneetdixit200 wants to merge 1 commit into
apache:mainfrom
puneetdixit200:fix/22271-ln-negative-error

Conversation

@puneetdixit200
Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

ln currently delegates directly to Rust floating-point ln, so negative inputs produce NaN. PostgreSQL-style semantics for this case should return a domain error instead.

What changes are included in this PR?

  • Moves ln from the shared unary math macro to a focused implementation.
  • Returns a compute error for negative Float32/Float64 inputs while preserving the existing ln(0) -> -Infinity behavior.
  • Adds SQL and unit coverage for the negative-input behavior.

Are these changes tested?

Yes:

  • cargo test --profile=ci --test sqllogictests -- scalar.slt
  • cargo test --profile=ci -p datafusion-functions math::ln
  • cargo fmt --all
  • git diff --check
  • cargo clippy --profile=ci --all-targets --all-features -- -D warnings

Are there any user-facing changes?

Yes. ln now returns an error for negative floating-point inputs instead of NaN.

AI assistance: Used OpenAI GPT-5 to help draft and check this focused change; I reviewed the code and tests.

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

There's already a pr for this issue #22276

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: ln(-1.0::float8) should error, not return NaN

2 participants