Re: C2124 is most disrespectful of IEEE floating point arithmetic



Alexander Grigoriev wrote:

In the standard:

"If during the evaluation of an expression, the result is not
mathematically defined or not in the range of representable values
for its type, the behavior is undefined, unless such an expression is
a constant expression (5.19), in which case the program is illformed.
[Note: most existing implementations of C++ ignore integer overflows.
Treatment of division by zero, forming a remainder using a zero
divisor, and all floating point exceptions vary among machines, and
is usually adjustable by a library function. ]"

Clause 5.119.3:
An arithmetic constant expression shall have arithmetic or
enumeration type and shall only have operands that are integer
literals (2.13.1), floating literals (2.13.3), enumerators, character
literals (2.13.2) and sizeof expressions (5.3.3). Cast operators in
an arithmetic constant expression shall only convert arithmetic or
enumeration types to arithmetic or enumeration types, except as part
of an operand to the sizeof operator.

This means: 1.f/0.f is a constant expression and the compiler is
evaluating it on compile time. Since it's not mathematically defined
(don't mind it's defined by IEC559), the program is illformed.

What are you talking about? According to the mathematical rules for
floating point numbers (which are NOT the rules for real numbers) the
result is both defined and representable.


--

.



Relevant Pages

  • Re: C2124 is most disrespectful of IEEE floating point arithmetic
    ... An arithmetic constant expression shall have arithmetic or ... or enumeration types to arithmetic or enumeration types, ... in handling mathematically undefined expressions provided they are not ... "An arithmetic constant expression shall satisfy the requirements for an ...
    (microsoft.public.vc.language)
  • Re: Reason for ISO ; warning
    ... "An arithmetic constant expression shall have arithmetic type and shall only have operands that are integer constants, floating constants, enumeration constants, character constants, and sizeof expressions. ... Cast operators in an arithmetic constant expression shall only convert arithmetic types to arithmetic types, except as part of an operand to a sizeof operator whose ...
    (comp.lang.c)
  • Re: C2124 is most disrespectful of IEEE floating point arithmetic
    ... "An arithmetic constant expression shall satisfy the requirements for ... Thus 1.0f/0.0f is an "arithmetic constant expression". ... Undefined behaviour is just that, ... deduce about code correctness by looking how compilers behave. ...
    (microsoft.public.vc.language)
  • Re: (int)"text" as initializer
    ... And it is verly likely for the committee to reject a DR to request ... defined form of the arithmetic constant expression. ... Jun, Woong ...
    (comp.std.c)