Skip to content

math.log: handle large integer bases and error order - #9019

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-math-log-base-conversion
Oct 9, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-math-log-base-conversion

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Split the Python 3.14-compatible math.log base handling from #8954.

Use the existing natural-log conversion for both operands, evaluating x before the base. This preserves the large-integer path for integer bases, avoids premature float overflow, and raises ZeroDivisionError when the base logarithm is zero.

Keep log2/log10 and noninteger conversion behavior unchanged. In particular, an exception from __float__ still propagates without retrying __index__.

Extend the existing math snippet with large bases, base one, conversion ordering, integer subclasses, and conversion-error cases. No canonical standard-library assertions change.

Validation

  • The expanded snippet fails on main d0dfcb54 with OverflowError for a large integer base.
  • The same snippet passes with this patch and on CPython 3.14.7.
  • Separate main/patched/reference observations verify the exception type for base one and negative large bases, and the operand conversion order.
  • All 6 selected existing logarithm tests in test_math pass unchanged.
  • Release workspace test targets compile with --no-run, excluding WASM, venvlauncher, and C API; the separate C-API test target also compiles with --no-run.
  • Affected-crate Clippy and repository hooks pass.

Local runtime validation is limited to the focused snippet, observations, and canonical tests above. Broad Rust test targets were compile-checked, not executed.

References: CPython 3.14 log conversion and evaluation order, float division.

AI assistance

OpenAI Codex assisted with auditing the split, implementation, regression coverage, and validation. The runtime does not expose an exact model identifier.

Use the natural logarithm path for both operands, evaluating x first. Preserve large integer bases and raise ZeroDivisionError for base one while retaining noninteger conversion errors.

Split the Python 3.14-compatible behavior from RustPython#8954 without its additional __index__ fallback or changes to log2 and log10.

Assisted-by: OpenAI Codex:model identifier unavailable
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6c1fabbc-2395-4bef-aa33-88918ba1cfcc

📥 Commits

Reviewing files that changed from the base of the PR and between e6cbf36 and 9d17669.


📒 Files selected for processing (2)
  • crates/stdlib/src/math.rs
  • extra_tests/snippets/stdlib_math.py

 ________________________________________________________________________________
< This conditional is a choose-your-own-adventure where every choice is 'panic'. >
 --------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@youknowone
youknowone marked this pull request as ready for review October 9, 2026 11:56
@youknowone
youknowone merged commit bd8fdb7 into RustPython:main Oct 9, 2026
21 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T12:00:59.243865Z 9d17669 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9d17669334

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# assert math.log(1.1111) == math.log(Conversible())

# A logarithm can fit in a float even when its integer base cannot.
assert math.isclose(math.log(2**4000, 2**2000), 2.0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the forbidden test additions

This block adds new assertions, helper classes, and test data to extra_tests/snippets/stdlib_math.py, but the repository's critical test-code rules forbid modifying test assertions, logic, or data and state that the only acceptable test-file changes are adding or removing expected-failure decorators. Remove this new test logic from the patch (or obtain a documented policy exception) before merging.

AGENTS.md reference: AGENTS.md:L273-L279

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants