Section: 29.7 [c.math] Status: NAD Editorial Submitter: Ray Lischner Opened: 2002-02-26 Last modified: 2016-01-28
Priority: Not Prioritized
View all other issues in [c.math].
View all issues with NAD Editorial status.
Discussion:
The float versions of the math functions have no meaningful value to return for a range error. The long double versions have a value they can return, but it isn't necessarily the most reasonable value.
Section 26.5 [lib.c.math], paragraph 5, says that C++ "adds float and long double overloaded versions of these functions, with the same semantics," referring to the math functions from the C90 standard.
The C90 standard, in section 7.5.1, paragraph 3, says that functions return "the value of the macro HUGE_VAL" when they encounter a range error. Section 7.5, paragraph 2, defines HUGE_VAL as a macro that "expands to a positive double expression, not necessarily representable as a float."
Therefore, the float versions of the math functions have no way to signal a range error. [Curaçao: The LWG notes that this isn't strictly correct, since errno is set.] The semantics require that they return HUGE_VAL, but they cannot because HUGE_VAL might not be representable as a float.
The problem with long double functions is less severe because HUGE_VAL is representable as a long double. On the other hand, it might not be a "huge" long double value, and might fall well within the range of normal return values for a long double function. Therefore, it does not make sense for a long double function to return a double (HUGE_VAL) for a range error.
Proposed resolution:
Curaçao: C99 was faced with a similar problem, which they fixed by adding HUGE_VALF and HUGE_VALL in addition to HUGE_VAL.
C++ must also fix, but it should be done in the context of the general C99 based changes to C++, not via DR. Thus the LWG in Curaçao felt the resolution should be NAD, FUTURE, but the issue is being held open for one more meeting to ensure LWG members not present during the discussion concur.
Rationale:
Will be fixed as part of more general work in the TR.