Skip to content

Commit

Permalink
trees.nim: compare floating points by their bitpatterns because NaN c…
Browse files Browse the repository at this point in the history
…omparisions are always false (WORST design in the history of computing!)
  • Loading branch information
Araq committed Mar 23, 2020
1 parent ee440df commit bcccb74
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/trees.nim
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ proc sameTree*(a, b: PNode): bool =
result = a.sym.name.id == b.sym.name.id
of nkIdent: result = a.ident.id == b.ident.id
of nkCharLit..nkUInt64Lit: result = a.intVal == b.intVal
of nkFloatLit..nkFloat64Lit: result = a.floatVal == b.floatVal
of nkFloatLit..nkFloat64Lit: result = cast[uint64](a.floatVal) == cast[uint64](b.floatVal)
of nkStrLit..nkTripleStrLit: result = a.strVal == b.strVal
of nkEmpty, nkNilLit, nkType: result = true
else:
Expand Down

3 comments on commit bcccb74

@timotheecour
Copy link
Member

@timotheecour timotheecour commented on bcccb74 Mar 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that correct wrt denormalization?
0.0 == -0.0 but cast[uint64](0.0) != cast[uint64](-0.0)
(curious also what nim code has been fixed by that commit)

@Clyybber
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we want to differentiate between 0.0 and -0.0 here probably, but it shouldn't matter (I think) since this is in sameTree, and - is an unary template.

@timotheecour
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> #13730

Please sign in to comment.