Skip to content

Commit

Permalink
Fully order NaN
Browse files Browse the repository at this point in the history
NaN is unordered in IEEE754, but we need all values to be ordered.
Make NaN larger than any other float (including inf) so that
dicts with NaN keys work correctly.

Signed-off-by: Keith Packard <keithp@keithp.com>
  • Loading branch information
keith-packard committed Sep 27, 2021
1 parent 845f4fb commit 774e0d0
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions snek-poly.c
Expand Up @@ -87,6 +87,9 @@ snek_poly_cmp(snek_poly_t a, snek_poly_t b, bool is)
int sdiff;
switch (atype) {
case snek_float:
tdiff = snek_is_nan(a) - snek_is_nan(b);
if (tdiff)
return tdiff;
return (b.f < a.f) - (a.f < b.f);
case snek_string:
sdiff = strcmp(snek_poly_to_string(a), snek_poly_to_string(b));
Expand Down

0 comments on commit 774e0d0

Please sign in to comment.