python-minifier icon indicating copy to clipboard operation
python-minifier copied to clipboard

Const-folding does not const-fold NaN values

Open mqyhlkahu opened this issue 1 year ago • 0 comments

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.

mqyhlkahu avatar Nov 01 '24 16:11 mqyhlkahu