GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add `math.cbrt()` and `math.exp2()` by jseop-lim · Pull Request #1271 · oracle/graalpython

Conversation

@jseop-lim

@jseop-lim jseop-lim commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #1260

math.cbrt and math.exp2, added in Python 3.11, were missing from the math module. CPython defines both as math_1 wrappers over libm, with overflow checking for exp2 only (mathmodule.c#L1113-L1115, #L1174-L1176).

AS-IS

>>> math.cbrt(8)
AttributeError: module 'math' has no attribute 'cbrt'
>>> math.exp2(3)
AttributeError: module 'math' has no attribute 'exp2'

TO-BE

>>> math.cbrt(8)
2.0
>>> math.exp2(3)
8.0
>>> math.exp2(1024)
OverflowError: math range error

(matching CPython)

Changes

  • Add CbrtNode, returning Math.cbrt(value).
  • Add Exp2Node, returning Math.pow(2.0, value) with the same range check as ExpNode.
  • Enable test.test_math.MathTests.testCbrt and testExp2 in unittest_tags/test_math.txt.

Testing

mx python-jvm on darwin-aarch64, then --tagged test_math (81 passed; master passes 79). Eighteen cbrt and exp2 calls, including infinities, NaN, -0.0 and the overflow case, return the same values as CPython 3.13.14.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jseop-lim
Add math.cbrt() and math.exp2()
8d42af5
Both functions were added to the math module in Python 3.11 and were
missing, so math.cbrt and math.exp2 raised AttributeError. cbrt uses
Math.cbrt; exp2 uses Math.pow(2.0, x) and raises OverflowError on an
infinite result from a finite argument, as exp does. Enable CPython's
testCbrt and testExp2, which now pass.

Signed-off-by: Jeongseop Lim <[email protected]>
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Oct 31, 2026
msimacek
msimacek approved these changes Nov 9, 2026
View reviewed changes

This branch has not been deployed

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

Reviewers

@msimacek msimacek msimacek approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Add math.cbrt and math.exp2

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@jseop-lim @msimacek
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.