**Submitter:** Fred J. Tydeman (USA)

**Submission Date:** 2010-06-17

**Subject:** Fix for DR 300 (Translation-time expression
evaluation)

Defect Report 300 was answered as not a defect, but instead a new requirement on implementations that could be addressed in a future revision of the C standard. That time is now.

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

This change is adding requirements and recommendations on floating-point constants and operators.

Many users expect that the same source form of floating-point constants will convert into the same value and internal format. That is, 0.1 in all places in a program produce the same value in the same internal format. I believe that it is no burden for implementations to meet this expectation. So, this is being asked to be a requirement.

Many users expect that the same mathematical value (even when written in different source forms) of floating-point constants will convert into the same value and internal format. I believe that it is a burden for some implementations to meet this expectation (requires perfect decimal to binary conversions). So, this is being asked to be a recommendation. This allows 0.1 and 0.10 to produce different values.

Many users expect that operations with the same types will use the same precision. That is, if constant expression 1.0/3.0 in one place in a program produces one value and in another place in the program produces a different value (because different precisions were used), then the user would be very surprised. This is currently allowed if FLT_EVAL_METHOD is -1. This is asked to be changed.

Add to 6.4.4.2 Floating constants, 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.2, paragraph 7 (Recommended practice):

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.

Add a 12th paragraph to 6.6: Constant expression:

All operators with the same type(s) of floating-point operand(s) in the same translation unit shall use the same precision.

Add to the Rationale on floating-constants:

Converting the same mathematical value (especially if written in different source forms) to the same internal value and representation requires perfect decimal to binary conversion. This is considered too much of a burden to place on all implementations, so it is not required. However, converting the same source form of a floating-point constant into the same internal value and representation is required. Hence, 0.1 and 0.10 need not convert into the same value, but all the 0.1 in a program must convert into the same value.

Update DR 300 to point to this document.