Suppose a
and b
are both of type int
, and b
is nonzero. Consider the result of performing a/b
in the following cases:
a
andb
are both nonnegative.a
andb
are both negative.- Exactly one of them is negative.
In Case 1 the result is rounded down to the nearest integer. But what does the standard say about Cases 2 and 3? An old draft I found floating on the Internet indicates that it is implementation dependent (yes, even case 2) but the committee is leaning toward making it always 'round toward zero.' Does anyone know what the (latest) standard says? Please answer only based on the standard, not what makes sense, or what particular compilers do.