https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85077

--- Comment #3 from Matthias Kretz <kretz at kde dot org> ---
Ouch, right I didn't think of non-finite values.

I.e. -0 < 0 is false...

However, this is what I wanted:
abs(-inf) -> inf
abs( inf) -> inf
abs( nan) -> nan
abs(  -0) -> 0
abs(   0) -> 0

The sign bit manipulation works for all of them. The ternary fails only on the
-0 input, no?

I'm working on an implementation of wg21.link/p0214r9 that I'd like to
contribute to libstdc++, which is why I'm currently looking to remove
workarounds and enable the compiler to do const-prop as much as possible.

I'd be happy to go with an implementation that uses my_abs if that's the way to
go (I guess it is).

FWIW, ICC translates `x < 0 ? -x : x` (on float itself) to sign masking. (But
then again ICC doesn't conform with default flags either)

Reply via email to