Skip to content

Const-folding does not const-fold NaN values #118

Description

@mqyhlkahu

From src/python_minifier/transforms/constant_folding.py, lines 51-54:

        if isinstance(original_value, float) and math.isnan(original_value):
            # There is no nan literal.
            # we could use float('nan'), but that complicates folding as it's not a Constant
            return node

NaN values do actually have a representation, at least in all the Python versions that I tested (3.9 through 3.12):

>>> ast.unparse(ast.Constant(float("nan")))
'(1e309-1e309)'

This is because inf - inf = nan and 1e309 is inf.

Should be an easy fix, but I don't know if Python 2 supports the same thing so I didn't want to send a PR myself.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions