Julia: Literal NaNs in ASTs

Created on 31 Mar 2016  路  3Comments  路  Source: JuliaLang/julia

Perhaps comparing ASTs isn't a very common operation, but I came across the following which I found surprising. I think it is even arguable that == should ignore the facts that NaNs are not numerically equal to themselves since it's not really numerical comparison.

julia> :(f($NaN)) == :(f($NaN))
false

julia> isequal(:(f($NaN)), :(f($NaN)))
false

Most helpful comment

it is even arguable that == should ignore the facts that NaNs are not numerically equal to themselves since it's not really numerical comparison.

NaN literal is not NaN value, yep

All 3 comments

It looks like we need an isequal method for Expr that calls isequal recursively.

it is even arguable that == should ignore the facts that NaNs are not numerically equal to themselves since it's not really numerical comparison.

NaN literal is not NaN value, yep

Very good point. The real solution is probably for == on Exprs to use isequal to compare elements.

Was this page helpful?
0 / 5 - 0 ratings