savi-lang / savi

A fast language for programmers who are passionate about their craft.
BSD 3-Clause "New" or "Revised" License
157 stars 12 forks source link

Fix compiler crash on identity comparison of floating-point values. #311

Closed jemc closed 2 years ago

jemc commented 2 years ago

Prior to this change, the compiler was crashing if you tried to compare the identity equality of two floating-point values of the same type. Now, the case is handled.

Values are compared by comparing their integer bits, so that there are no edge cases around things like NaN or various infinite values, failing to compare as they would with value equality. Identity equality is about not being able to distinguish the two operands, and any different floating-point encoded values are distinguishable by calling their bits method, which can reveal different results even when the bits encode a conceptually equivalent value (different bit encodings of the same real number). Similarly, NaN values even if they do not compare with == should have identity equality if they have exactly the same bits.