Skip to content

Fix decimal log precision for non-power values#20433

Open
kumarUjjawal wants to merge 3 commits intoapache:mainfrom
kumarUjjawal:fix/decimal_log
Open

Fix decimal log precision for non-power values#20433
kumarUjjawal wants to merge 3 commits intoapache:mainfrom
kumarUjjawal:fix/decimal_log

Conversation

@kumarUjjawal
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

The decimal log implementation used the integer ilog path whenever the base was an integer, which floors results for non‑power values. That produced incorrect outputs such as log(2, 10^35) returning 116 instead of 116.267...

What changes are included in this PR?

  • Fix decimal log to use the integer fast path only for exact powers, preserving fractional results for non-power inputs.
  • Update unit tests and decimal sqllogictest expectations to match the corrected behav

Are these changes tested?

Yes

Are there any user-facing changes?

No

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Feb 19, 2026
@kumarUjjawal
Copy link
Contributor Author

@Jefffrey when you do get the time, can you take a look.

@kumarUjjawal
Copy link
Contributor Author

@martin-g if I could borrow your time here.

Comment on lines +115 to +118
if scale == 0
&& is_valid_integer_base(base)
&& let Ok(unscaled) = u32::try_from(value)
&& unscaled > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel we'll need to reconsider this integer log path now that it's reduced to needing all these requirements:

  • 0 scale
  • integer base
  • can unscale

Just for a more accurate computation 🤔

cc @theirix

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. I would start with more test cases to express our expectations on int/float semantics, like stated in the PR description.

For unscaling, I believe it could be improved in general, there are some edge cases. One attempt is here #19874

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.

Decimal128 implementation of log loses precision

4 participants