Date: Sat, 7 Dec 2024 10:23:46 -0500
`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
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
Received on 2024-12-07 15:23:58