Sort module

compare_floats

procedure · 1 overloadSource

A three-way comparator for quick_sort and intro_sort: -1, 0 or 1 for a < b, a tie and a > b.

The order is total: every NaN goes after all numbers (infinities included) and ties only with other NaNs, so a sort puts NaNs last. -0.0 and 0.0 tie.

ExampleOpen in playground ↗
values := float.[2.5, -1, 9];
quick_sort(values, compare_floats);
assert(values[0] == -1 && values[2] == 9);

#import "Math";
with_nan := float.[FLOAT32_NAN, 3, -2];
quick_sort(with_nan, compare_floats);
assert(with_nan[0] == -2 && with_nan[1] == 3 && with_nan[2] != with_nan[2]);
compare_floats :: (a: float, b: float) -> s64

Parameters

a: float
b: float

Returns

s64

See also