Skip to content

Math.log(0)/log2(0)/log10(0) return NaN instead of −∞ (Python/JS parity) #790

Description

@aallan

Surfaced by CodeRabbit's review of the #421 decomposition (#789). Pre-existing — the wrapper moved verbatim from codegen/api.py.

vera/runtime/math.py's _math_unary_host converts every ValueError from Python's math module into NaN, to mirror IEEE 754 / JS for genuine domain errors (e.g. log(-1) → NaN). But Python's math.log(0.0) raises ValueError (math domain error) at the pole, where IEEE 754 and JS Math.log(0) both give −∞. So Vera's Math.log(0) / log2(0) / log10(0) return NaN under the Python/wasmtime runtime while the browser/JS runtime returns −∞ — a parity violation.

Fix: special-case x == 0-inf in _math_unary_host for log/log2/log10, keeping the ValueError → NaN path for true domain errors. Add a tests/test_browser.py parity case for log(0).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions