Date: Fri, 27 Jun 2025 09:21:15 +0200
That seems equivalent, but the compiler would optimize the last line
to a single arithmetic right-shift basically, and I don't find it any
easier to write with this test and conditional operator:
> (x >> 31)
vs.
> (x & (1u << 31) ? -1u : 0u)
Anyhow, no matter how you do it, it seems like some ugly setup is
required to make it work, and the code doesn't end up being very
expressive, so that seems like perfect motivation for a function
template to me.
to a single arithmetic right-shift basically, and I don't find it any
easier to write with this test and conditional operator:
> (x >> 31)
vs.
> (x & (1u << 31) ? -1u : 0u)
Anyhow, no matter how you do it, it seems like some ugly setup is
required to make it work, and the code doesn't end up being very
expressive, so that seems like perfect motivation for a function
template to me.
Received on 2025-06-27 07:21:27