diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-11-23 13:25:16 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-11-23 13:25:16 -0500 |
| commit | 295487b62741945bfc7fc0ba71d7a9c2f9be796c (patch) | |
| tree | 4200dd599f7d78ef8eac4ad3ecb67161e7719aee | |
| parent | f868d02b08688c04509d1abda5af89a182033d88 (diff) | |
Fix ordering of Nums that have NaNs
| -rw-r--r-- | stdlib/nums.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/stdlib/nums.c b/stdlib/nums.c index a9cb0a6d..9f69bb1c 100644 --- a/stdlib/nums.c +++ b/stdlib/nums.c @@ -19,9 +19,16 @@ public PUREFUNC Text_t Num$as_text(const double *f, bool colorize, const TypeInf return Text$format(colorize ? "\x1b[35m%.16g\x1b[33;2m\x1b[m" : "%.16g", *f); } -public PUREFUNC int32_t Num$compare(const double *x, const double *y, const TypeInfo_t *type) { - (void)type; - return (*x > *y) - (*x < *y); +public PUREFUNC int32_t Num$compare(const double *x, const double *y, const TypeInfo_t *) { + int64_t rx = *(int64_t*)x, + ry = *(int64_t*)y; + + if (rx == ry) return 0; + + if (rx < 0) rx ^= INT64_MAX; + if (ry < 0) ry ^= INT64_MAX; + + return (rx > ry) - (rx < ry); } public PUREFUNC bool Num$equal(const double *x, const double *y, const TypeInfo_t *type) { |
