Reputation: 2326
I was noticing some wording changes to section 5.6 for C++11. (I'm looking at the draft C++ standard N3242, dated 2011-02-28.) The new (draft) standard includes the sentence:
"For integral operands the / operator yields the algebraic quotient with any fractional part discarded;"
This statement is not in 5.6 of the 03 standard (ISO-IEC-14882-2003), but I don't think this is a change, is it? This is how C and C++ has worked for years unless I've lost my mind (which may have happened anyway).
Upvotes: 7
Views: 2523
Reputation: 16046
Almost. In C++03 the sign of the remainder for %
(in which terms both were specified) was unspecified, as such rounding could go away from zero in certain situations too. Compare with the C++03 footnote:
According to work underway toward the revision of ISO C, the preferred algorithm for integer division follows the rules defined in the ISO Fortran standard, ISO/IEC 1539:1991, in which the quotient is always rounded toward zero.
In practice however, this almost never made any difference.
Upvotes: 2
Reputation: 385144
You're not going mad.
A footnote to 5.6/4
said:
[C++03 footnote 74]:
According to work underway toward the revision of ISO C, the preferred algorithm for integer division follows the rules defined in the ISO Fortran standard, ISO/IEC 1539:1991, in which the quotient is always rounded toward zero.
In C++11 this behaviour is explicitly required rather than being "preferred"; the change is listed in the compatibility section:
[C++11: C.2.2]:
Change: Specify rounding for results of integer/
and%
Rationale: Increase portability, C99 compatibility.
Effect on original feature: Valid C++ 2003 code that uses integer division rounds the result toward 0 or toward negative infinity, whereas this International Standard always rounds the result toward 0.
Upvotes: 10