Submitter: Fred J. Tydeman (USA)
Submission Date: 2012-1-11
Source: WG 14
Reference Document: N1593
Version: 1.1
Date: October 2012
Subject: f(inf)
is inf
being a
range error
Summary
Several of the functions in <math.h>
that
compute infinity for f(infinity)
have the phrase (or
something similar):
A range error occurs if the magnitude of x is too large.
Since infinity is 'too large', one might conclude that
f(infinity)
is a range error for those
functions.
However, 7.12.1#5 has:
A floating result overflows if the magnitude of the mathematical result is finite but so large that the mathematical result cannot be represented without extraordinary roundoff error ...
The key word being 'finite'. So, one could conclude f(infinity) being infinity is not overflow (and therefore, not a range error).
To me, this appears to be a contradiction. I have encountered both kinds of implementations; some treat this case as a range error, and others that do not.
For both LIA and IEEE-754, f(infinity) being infinity is not considered an error.
Suggested Change
Change to: A range error occurs if the magnitude of finite x is too large.
Change to: A range error occurs if the magnitude of finite x is too large.
Change to: A range error occurs if the magnitude of finite x is too large.
Change to: A range error occurs if the magnitude of finite x is too large.
Change to: A range error occurs if the magnitude of finite x is too large.
Change to: A range error may occur for finite arguments.
Change to: A range error may occur for finite arguments.
Change to: A range error may occur for finite arguments.
Change to: A range error may occur for finite arguments.
Change to: A range error occurs if finite x is too large.
Change to: A range error occurs if finite x is too large.
Change to: A range error occurs if the magnitude of finite x is too large and may occur if the magnitude of x is too small.
Change to: A range error may occur for finite arguments.
Change to: A range error may occur for finite arguments.
Committee Discussion
Oct 2012 meeting
- The committee rejected the Suggested Change in the main body of this defect report.
- The committee considered the following, but rejected it (as just being a restatement of 7.12.1 paragraphs 4 and 5).
If the result overflows, a range error shall occur.- A question arose as to why these range error cases are listed in the individual functions (instead of just being covered by the blanket 7.12.1 paragraphs 4, 5, and 6)
7.12.1 paragraph 1 has the answer:
The behavior of each of the functions in <math.h> is specified for all representable values of its input arguments, except where stated otherwise.- Several other approaches were discussed, without any consensus reached
- Add a footnote to 7.12.1 paragraph 5, first sentence:
In an implementation that supports infinities, a range error may happen for functions that map an infinity argument into an exact infinity or exact zero result.- Add to end of 7.12.1 paragraph 4:
Recommended practiceIn an implementation that supports infinities, a range error should not happen for functions that map an infinity argument into an exact infinity or exact zero result.
- Add to 7.12.1 paragraph 4:
An implementation may define additional range errors, provided that such errors are consistent with the mathematical definition of the function.
Committee Discussion
- Fred wrote a paper N1629 discussing "Fixing a contradiction" and "Taking care of infinity".
- The definition of range error, however, in 7.12.1 paragraph 4 indicates infinity is excluded (since it has a representation), and as such no change is required.
Proposed Committee Response
The definition of range error in 7.12.1 paragraph 4 excludes infinity.
For example, exp(+infinity)
is +infinity
.
Since the input +infinity
is representable,
then the output +infinity
is representable in an object of the
specified type. By, 7.12.1 paragraph 4, a range error has not happened.
Also, by 7.12.1 paragraph 5, since the result is not finite,
a range error has not happened.