Skip to content

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

Open

Description

@jseop-lim

Describe the feature

math.cbrt and math.exp2, both added in Python 3.11, do not exist in GraalPy's math module, so any call raises AttributeError. Seen on master a3009f9 (Python 3.13.14) on macOS ARM64 and on 25.0.2 (Python 3.12.8) on Linux ARM64.

import math
print(hasattr(math, 'cbrt'), hasattr(math, 'exp2'))
print(math.cbrt(8))

GraalPy master a3009f9:

False False
AttributeError: module 'math' has no attribute 'cbrt'

Expected behavior

The same as CPython 3.13.14 (and 3.12.13), with math.exp2(1024) raising OverflowError: math range error:

True True
2.0

Additional context

MathModuleBuiltins registers sqrt, exp and expm1 (MathModuleBuiltins.java#L202-L291) but has no cbrt or exp2 builtin. CPython defines both in mathmodule.c#L1113-L1115 and #L1174-L1176 as math_1 wrappers over libm, with overflow checking enabled for exp2 only.

A CbrtNode returning Math.cbrt(value) and an Exp2Node returning Math.pow(2.0, value) with the same checkMathRangeError as ExpNode (#L258-L274) would cover both. testCbrt and testExp2 are already in the bundled test_math.py and only need enabling in unittest_tags/test_math.txt.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions