C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::next_higher, std::next_lower

From: Halalaluyafail3 <luigighiron_at_[hidden]>
Date: Sat, 7 Dec 2024 13:50:29 -0500
C23 standardized the functions nextup and nextdown which take a single
argument, are these what you're looking for?

On Sat, Dec 7, 2024 at 10:24 AM Charles R Hogg via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> `std::nextafter` and friends provide the next representable value after the first argument, in the direction of the second argument.
>
> Often, I find myself wanting specifically the next-higher or next-lower representable value. In these cases, it feels awkward to cook up a number that I know will be higher or lower. Yes, I can use `std::numeric_limits`. I think `max` and `lowest` are the right tools for the job. `infinity` is tempting, but I don't see a "negative infinity", I don't want to raise questions in the reader's mind about negating singular values like this, and `infinity` would be a disastrous choice for integral types, where it returns `0`. (Not that we typically intentionally use `nextafter` for integral types, but it may happen in a generic template by accident.)
>
> Sometimes I wonder: wouldn't it be more intent-based to provide something like `std::next_higher()` and `std::next_lower()`, with a single argument? Has this ever been proposed?
>
> Thanks,
> Chip
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2024-12-07 18:54:01