Visitar URL original
Poor accuracy in true division of integers · Issue #474 · oracle/graalpython · GitHub
Skip to content

Poor accuracy in true division of integers #474

Description

@skirpichev

For example:

>>> x, y = 15649, 2024092432744435552
>>> x/y
7.73136628883186e-15
>>> import mpmath
>>> float(mpmath.mpf(x)/mpmath.mpf(y))  # as in CPython
7.731366288831862e-15

The result expected to be correctly rounded with the round-half-to-even rule.

Activity

  1. self-assigned this
    on Feb 12, 2025
  2. added a commit that references this issue on Mar 18, 2025
    9513ba0
  3. skirpichev commented on Nov 5, 2025

    @skirpichev
    Author

    @msimacek is this included in the 25.0.1 or in 25.0.0?

    In CI I get following failure (building gp312_250-manylinux_x86_64 wheel):

    E           assert (mpz(2305843008955759739) / mpz(784637716923335094969050127462454050937374032249308213819)) == 2.9387358767269886e-39
    

    CPython's result (which is same for mpz):

    Python 3.14.0 (tags/v3.14.0:ebf955df7a8, Oct 15 2025, 06:24:48) [GCC 12.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 2305843008955759739 / 784637716923335094969050127462454050937374032249308213819
    2.9387358767269883e-39

    I don't think this is fixed.

  4. skirpichev commented on Nov 19, 2025

    @skirpichev
    Author

    @msimacek can this be reopened or should I open a new issue?

    I downloaded latest stable and run. It seems the fix was applied, but in my new example it's not enough:

    Python 3.12.8 (Thu Oct 09 17:26:36 UTC 2025)
    [Graal, Oracle GraalVM, Java 25.0.1 (amd64)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> x, y = 15649, 2024092432744435552  # now ok
    >>> x/y
    7.731366288831862e-15
    >>> 2305843008955759739 / 784637716923335094969050127462454050937374032249308213819  # this is wrong
    2.9387358767269886e-39
    >>> _.hex()  # one bit off, correct answer is '0x1.ffffffff0a03cp-129'
    '0x1.ffffffff0a03dp-129'
  5. msimacek commented on Nov 19, 2025

    @msimacek
    Contributor

    Hi, sorry, let's reopen this

  6. skirpichev commented on Dec 12, 2025

    @skirpichev
    Author

    BTW,

    The result expected to be correctly rounded with the round-half-to-even rule.

    it seems, this is not something documented. The Python doesn't specify behavior of true division at all, see discussion in python/cpython#142449. And with the current optimization in the algorithm, above property might be violated on some systems.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions