Public Comment Number PC-UK0259
ISO/IEC CD2 9899 (SC22N2794) Public Comment
===========================================
Date: 1998-12-07
Author: Stephen Baynes
Author Affiliation: Self
Postal Address:
[Redacted under GDPR 2018-09-07]
E-mail Address:
Telephone Number: [Redacted under GDPR 2018-09-07]
Category: Feature that should be included
Committee Draft subsection: 6.5.5
Title: Rounding of integer division and % operator.
Detailed description:
As the decision has been made to mandate the direction of rounding of
integer division, it should be mandated to be the more useful round
towards minus infinity. This allows a number of useful algorithms
to be implemented on signed numbers using a single / or % operation.
Implementing these using round towards zero would require positive
and negative integers to be separated and processed separately.
Change 6.5.5 paragaph 6 to read (with appropriate amendments to footnotes):
[#6] When integers are divided, the result of the / operator
is the algebraic quotient with any fractional part
rounded to the next smallest integer.76 If the quotient
a/b is representable, the expression (a/b)*b + a%b shall
equal a.76a
__________
76. This is often called ``truncation toward minus infinity''.
76a. If b is positive a%b is in the range 0 to b-1 inclusive.
If b is negative a%b is in the range b-1 to 0 inclusive.
This dictates the following results:
a b a/b a%b
5 3 1 2
-5 3 -2 1
5 -3 -2 -1
-5 -3 1 -2
Also acceptable would be (with appropriate amendments to footnotes):
[#6] When integers are divided, the result of the / operator
is the algebraic quotient with any fractional part
rounded to the next smallest integer if the second operand is positive
and the next largest integer if the second operand is negative.
If the quotient a/b is representable, the expression
(a/b)*b + a%b shall equal a.76
__________
76. If b is positive a%b is in the range 0 to b-1 inclusive.
If b is negative a%b is in the range 0 to -b-1 inclusive.
This dictates the following results:
a b a/b a%b
5 3 1 2
-5 3 -2 1
5 -3 -1 2
-5 -3 2 1