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 — [Bug]: `math.log(x, base)` returns `-inf` for zero `x`, ignores `base=None`, and converts `base` before checking `x` · Issue #1253 · oracle/graalpython

[Bug]: math.log(x, base) returns -inf for zero x, ignores base=None, and converts base before checking x #1253

New issue
Copy link
New issue
Copy link
Open
#1264
Open
[Bug]: math.log(x, base) returns -inf for zero x, ignores base=None, and converts base before checking x#1253
#1264
Copy link
Labels
bugSomething isn't workingSomething isn't working

Description

@jseop-lim
jseop-lim
opened on Oct 31, 2026
Issue body actions

Describe the bug

Three argument checks in math.log differ from CPython. With a base, a zero x returns -inf instead of raising ValueError. A None base is treated as a missing base, so the natural logarithm is returned instead of a TypeError. A non-positive x with a base that cannot be converted raises the base's TypeError instead of the ValueError for x.

Operating system

macOS

CPU architecture

ARM64

GraalPy version

master a3009f9 (Python 3.13.14); also reproduced on 25.0.2 (Python 3.12.8) and 25.4.4.1.1 (Python 3.13.14)

JDK version

No response

Context configuration

No response

Steps to reproduce

import math
for args in [(0, 2), (10, None), (-1, object())]:
    try:
        print(math.log(*args))
    except Exception as e:
        print(type(e).__name__, e)

GraalPy master a3009f9:

-inf
2.302585092994046
TypeError must be real number, not object

Expected behavior

CPython 3.13.14 (same on 3.12.13):

ValueError math domain error
TypeError must be real number, not NoneType
ValueError math domain error

Stack trace

Additional context

The zero case also covers math.log(0.0, 2.0), math.log(-0.0, 2), math.log(0, MyInt(2)) and the one-argument math.log(MyInt(0)) for an int subclass; math.log(0, 1) raises ZeroDivisionError instead. The None case depends on call history: once math.log(-1, object()) has run in the process, math.log(10, None) raises TypeError like CPython, while math.log(10.0, None) still returns 2.302585092994046.

Root Cause

The two-argument specializations of LogNode test the value with value < 0 (MathModuleBuiltins.java#L1733-L1742 and four more, plus logPIN at #L1702), so zero reaches Math.log. The one-argument specializations take the base as PNone without an isNoValue guard (#L1678-L1704, #L1806-L1811), so they also match None. logOO, logLO, logDO and logPIO convert the base before the recursive call that checks the value (#L1813-L1839). CPython's math_log computes log(x) first, rejecting any x <= 0, and converts a second argument only after that, whatever it is (mathmodule.c#L2269-L2273, #L2227-L2232).

Fix Suggestion

Use <= 0 for the value in the six specializations, add isNoValue(novalue) to the four PNone specializations, and in logOO, logLO, logDO and logPIO check the value's domain before converting the base and exclude a missing base. The guard change needs the last one, or math.log(-1, None) would start raising TypeError.

Activity

  1. jseop-lim
    added
    bugSomething isn't workingSomething isn't working
    on Oct 31, 2026
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

    bugSomething isn't workingSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.