Skip to content

Should PyFloat_Pack8/PyFloat_Unpack8 be infallible? #107

Description

@encukou

Since 3.11, building CPython requires support for “IEEE” floating-point format and NaN. The discussion's consensus seems to be “CPython requires IEEE 754 floats, but the Python language does not.” The requirement was added to simplify internals and avoid untested code paths, but, as Greg says on the thread:

Should a meaningful large-os platform come along that promotes the use of a
different format available from C we could make use of that and loosen the
policy as needed.


A 3.15 change made PyFloat_Pack8 and PyFloat_Unpack8 always succeed on CPython. I think that goes against the decision: error-less conversion means a 1:1 mapping, i.e. it effectively requires that double is IEEE binary64. Or at least that NaNs and infinities are available. Changing this (“loosening the policy”) would be painful: we'd probably need to remove the now-fallible functions, with a suitable deprecation period.

So, it would make sense to me to keep PyFloat_Pack* and PyFloat_Unpack8 fallible; infallibility should be an internal implementation detail, which we can drop in the next version.

What's your opinion?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions