Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mqyhlkahu opened this issue Nov 1, 2024 · 0 comments
Open

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

mqyhlkahu opened this issue Nov 1, 2024 · 0 comments

Comments

@mqyhlkahu
Copy link

mqyhlkahu commented Nov 1, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant