[PATCH-idea] qsort and bsearch variants for built-in types
Joseph Myers
josmyers@redhat.com
Mon Apr 28 17:50:36 GMT 2025
On Mon, 28 Apr 2025, hypatia.sva@posteo.eu wrote:
> We thought about why bsearch and qsort, although builtin features of libc, are
> almost never used. The main reason for me personally was always that it seemed
> kind of silly to give a new cmp-function for floats or integers, since the
> function call would likely be much slower than the actual comparison
> instruction, so I would usually just roll my own, likely technically less
There are obvious problems with using simple comparisons with
floating-point types for these functions unless you have extra information
about the inputs (NaN compares unequal to itself, while +0 and -0 compare
equal). That is, the appropriate comparison function really does depend
on the desired semantics at the call site; there isn't an obviously
correct default like you seem to be suggesting.
--
Joseph S. Myers
josmyers@redhat.com
More information about the Libc-alpha
mailing list