I
Ian Pilcher
As I was setting out from base camp to climb the "itoa mountain", full
of trepidation about crossing the "INT_MIN chasm", my wise old Sherpa
told me meditate on the meaning of section 6.5.5(6) of the C99 standard:
When integers are divided, the result of the / operator is the
algebraic quotient with any fractional part discarded.(87) If the
quotient a/b is representable, the expression (a/b)*b + a%b shall
equal a.
(87) This is often called "truncation toward zero".
To my shallow occidental eye, this seems to provide a solid definition
of both the / and % operators (division and modulisation?) for negative
integers, eliminating the traditional need to convert the integer being
formatted to its absolute value.
Question #1: Am I right about this?
Question #2: In what circumstances can "the quotient a/b" not be
representable? I can think of two:
* division by zero
* negative zero - only possible if a or b is negative
zero
Actually, I'm not sure that the second really qualifies as
not representable.
So, as usual, the real question is did I miss something?
Thanks!
of trepidation about crossing the "INT_MIN chasm", my wise old Sherpa
told me meditate on the meaning of section 6.5.5(6) of the C99 standard:
When integers are divided, the result of the / operator is the
algebraic quotient with any fractional part discarded.(87) If the
quotient a/b is representable, the expression (a/b)*b + a%b shall
equal a.
(87) This is often called "truncation toward zero".
To my shallow occidental eye, this seems to provide a solid definition
of both the / and % operators (division and modulisation?) for negative
integers, eliminating the traditional need to convert the integer being
formatted to its absolute value.
Question #1: Am I right about this?
Question #2: In what circumstances can "the quotient a/b" not be
representable? I can think of two:
* division by zero
* negative zero - only possible if a or b is negative
zero
Actually, I'm not sure that the second really qualifies as
not representable.
So, as usual, the real question is did I miss something?
Thanks!