floating-point nonsense

Stephen L Moshier moshier@world.std.com
Sun Nov 9 13:29:00 GMT 1997


> double
> foo(int negative)
> {
>   return negative ? -0.0 : 0.0;
> }


The problem seems to be in this use of operand_equal_p, which will say -0.0
equals 0.0.

How should it be fixed?  We might add another argument that means
check for identical bit pattern if the args are constants.

fold-const.c:5539
    case COND_EXPR:
      /* Pedantic ANSI C says that a conditional expression is never an lvalue,
	 so all simple results must be passed through pedantic_non_lvalue.  */
      if (TREE_CODE (arg0) == INTEGER_CST)
	return pedantic_non_lvalue
	  (TREE_OPERAND (t, (integer_zerop (arg0) ? 2 : 1)));
      else if (operand_equal_p (arg1, TREE_OPERAND (expr, 2), 0))
	return pedantic_omit_one_operand (type, arg1, arg0);




More information about the Gcc-bugs mailing list