lrint
, llrint
, lround
, llround
, and ilogb
descriptions are not consistent for unrepresentable resultsThis issue has been automatically converted from the original issue lists and some formatting may not have been preserved.
Authors: Fred Tydeman (US)
Date: 2001-02-25
Reference document: ISO/IEC WG14 N943
Submitted against: C99
Status: Fixed
Fixed in: C99 TC2
Converted from: summary-c99.htm, dr_240.htm
lrint
,llrint
,lround
,llround
, andilogb
need to have consistent and explicit descriptions when results are too big to represent in an integer type. Also, that case should be treated as a domain error.
IEC 60559 requires that when a large floating-point value, an infinity, or a NaN is converted to an integer, and the result cannot be represented as an integer in the result's format, an invalid operation has occurred. This is currently mostly reflected in C99's Annex F. This condition corresponds to C's domain error.
ilogb
does not discuss (in either 7.12.6.5 or annex F) what should happen if the expected result cannot be represented as an int. It should be treated as a domain error (because it is an invalid operation to IEC 60559). The "correct" result ofilogb(0)
is -infinity (which cannot be represented as an int, so should be treated as a domain error).ilogb(NaN)
does not follow the normal convention of NaN in implies NaN out, so this unusual case needs to be discussed.
lrint
andllrint
are inconsistent on how large arguments are treated between 7.12.9.5 (range error) and Annex F (domain error).
lround
andllround
are inconsistent on how large arguments are treated between 7.12.9.7 (range error) and Annex F (domain error).
In 7.12.6.5 ilogb
:
Change:
A range error may occur if
x
is0
.
to
A domain error occurs if
x
is0
, infinite, orNaN
.
Add:
If the correct value is outside the range of the return type, the numeric result is unspecified, and a domain error occurs.
In 7.12.9.5 lrint llrint
:
Change:
If the rounded value is outside the range of the return type, the numeric result is unspecified. A range error may occur if the magnitude of
x
is too large.
to
If the rounded value is outside the range of the return type, the numeric result is unspecified, and a domain error occurs.
In 7.12.9.7 lround llround
:
Change:
If the rounded value is outside the range of the return type, the numeric result is unspecified. A range error may occur if the magnitude of
x
is too large.
to
If the rounded value is outside the range of the return type, the numeric result is unspecified, and a domain error occurs.
Comment from WG14 on 2004-03-16:
In 7.12.6.5 ilogb
:
Change:
A range error may occur if
x
is0
.
to
A domain error or range error may occur if
x
is0
, infinite, orNaN
.
Add:
If the correct value is outside the range of the return type, the numeric result is unspecified.
In F.9.3.5 ilogb
:
Change:
No additional requirements.
to
If the correct result is outside the range of the return type, the numeric result is unspecified and the "invalid" floating-point exception is raised.
In 7.12.9.5 lrint
and llrint
:
Change:
If the rounded value is outside the range of the return type, the numeric result is unspecified. A range error may occur if the magnitude of
x
is too large.
to
If the rounded value is outside the range of the return type, the numeric result is unspecified, and a domain error or range error may occur.
In 7.12.9.7 lround
and llround
:
Change:
If the rounded value is outside the range of the return type, the numeric result is unspecified. A range error may occur if the magnitude of
x
is too large.
to
If the rounded value is outside the range of the return type, the numeric result is unspecified, and a domain error or range error may occur.