You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Negated float comparison is wrong for NaN: !(x < 0.0) compiles to x >= 0.0 #9026
Negating a float comparison flips the operator, which is wrong for NaN:
letk= (x: float) =>!(x < 0.0)
compiles to
functionk(x){returnx>=0.0;}
k(NaN) returns false, but !(NaN < 0.0) is true.
The cause is Js_exp_make.not (compiler/core/js_exp_make.ml), which rewrites < to >=, >= to <, <= to > and > to <=. These are only complements when neither operand is NaN. The same function is used whenever the compiler negates a condition, e.g. when Js_stmt_make.if_ swaps the branches of an if with an empty then-branch, so other float comparisons can be affected too.
The rewrite is safe when the operands can't be NaN, e.g. for int, string and bigint comparisons. For floats, !(a < b) has to stay as it is.
Activity
Keep the operator of a negated float comparison