On Fri, Apr 19, 2024 at 8:06 AM Bruno Haible <br...@clisp.org> wrote:

> ...
>
> +/* Returns - x, implemented by inverting the sign bit,
> +   so that it works also on 'float' NaN values.  */
> +_GL_UNUSED static float
> +minus_NaNf (float x)
> +{
> +#if defined __mips__
> +  /* The mips instruction neg.s may have no effect on NaNs.
> +     Therefore, invert the sign bit using integer operations.  */
> +  union { unsigned int i; float value; } u;
> +  u.value = x;
> +  u.i ^= 1U << 31;
> +  return u.value;
> +#else
> +  return - x;
> +#endif
> +}
>

Accessing the union first though 'value' and then through 'i' may be
undefined behavior. I don't think you can legally access the union through
the inactive member.

Jeff

Reply via email to