Document: WG14 N1322


Translation-time expression evaluation


Submitter: Fred Tydeman (USA)
Submission Date: 2008-07-12
Reference Documents: N1074, Defect Report 300
Version: 1.1
Subject: Translation-time expression evaluation

The standard does not require translation-time expression evaluation to produce "obvious" values. For example, there is no requirement that static const double d = 1.23/4.56 - 1.23/4.56; be zero.

Currently, if FLT_EVAL_METHOD is negative, there is no requirement that the first 1.23 and the second 1.23 convert to the same internal representation; one could have more precision than the other. While the same range and precision is a requirement when FLT_EVAL_METHOD is 0, 1, or 2, there is no requirement that those two identical constants convert to the same value.

Currently, if FLT_EVAL_METHOD is negative, there is no requirement that the first '/' produce a result with the same precision as the second '/' (for the same operands). This is a requirement when FLT_EVAL_METHOD is 0, 1, or 2.

For translation-time floating-point expression evaluation to produce the "obvious" value, two requirments must be met: the same decimal constants must result in the same value and internal representation, and operators must use the same precision.

Proposed changes to C1x

6.4.4.2 Floating constants: Add to paragraph 5: All floating-constants of the same source form in the same translation unit shall convert to the same internal format with the same value. Footnote: 1.23, 1.230, 123e-2, 123e-02, 1.23L are all different source forms, so need not convert to the same internal format and value.

Add to 6.4.4.2p7, All floating-constants with the same mathematical value and type in the same translation unit should convert to the same internal format and value. Footnote: 1.23, 1.230, 123e-2 and 123e-02 have the same mathematical value, so should convert to the same internal format and value.

6.6: Constant expression: Add a 12th paragraph: All operators with the same type(s) of floating-point operand(s) in the same translation unit shall use the same precision.