M
Michael Press
Thomas Scrace said:Does not assume it goes negative.
By assuming that adding two positive ints, or multiplying a positive int
by 2, will produce a negative result when the operation overflows
No, it does not.
Well, that's what I see on both my home machine (AMD64 Ubuntu Linux) and
my work machine (SGI IRIX) when I instrument the else clause with a
"printf("%d\n", y)". If something else happens on the machines that
you're familiar with, that's perfectly conforming, too - which is
precisely my point.
Your responses are just a little too laconic. Could you expand a little
on what it is you're trying to communicate?
Not until you prove or retract your claim that I and my code
assume addition or multiplication on int produces negative results.
I wouldn't call it a "claim" as such,
We disagree.
when it was explicitly qualified
by the phrase "seems to", explicitly acknowledging that what seems to be
the case, might not be. A "guess" might be a more appropriate way of
describing it. I can't imagine how I could possibly prove anything about
what your motivations were while writing that code, and I have no
intention of trying.
It was not my intention to suggest any certainty about why you thought
that code should work. I said as much, in words you chose to clip:
However, I suppose that's not the only assumption that would make it work.
Since I never wrote something such as if( x < 0), there are no grounds
for assuming I wrote about negatives or overflow.
My comment that:
If something else happens on the machines that you're familiar with, that's perfectly conforming, too
was also intended to concede that you might have relied upon some other
assumption. Since you seem offended by the idea that you were relying on
that particular assumption, I'll happily retract my guesses as to what
you were thinking when you wrote that code. However, that leaves me with
no idea why you thought it would work. Would you care to explain what
assumptions you were making about the results of signed integer overflow
when you wrote that code?
It did work, on the machines where I tested it, and it worked precisely
because x+step did produce a negative value.
Here is a list of assumptions. They are as complete and consistent
as I could make them in the time spent; but very likely reducible.
Assumptions.
* There is a set called int.
* int is finite.
* There are binary operators {+, *} on int.
* int is closed under {+, *}.
* + is commutative
* * is commutative
* Multiplication is distributive over addition.
* There is an additive identity 0
* There is a multiplicative identity 1.
* There is an order relation < on int.
* The relation < is transitive.
* If a,b in int, then exactly one of a < b, b < a, a = b obtains.
* 0 < 1.
* If a < b, then a < a + 1 and there is no x such that a < x < a + 1.
* Addition is repeated addition of 1.
- That is if 0 < b, then there is a positive integer (not int!), n, such that
b = 1 + 1 + ... + 1 (n times).
- If 0 < a + b, then a + b = a + [1 + 1 + 1 + ... + 1 (n times)].
* Multiplication is repeated addition.
Those axioms seem awfully familiar to me somehow...
Yes, but they are not exactly anything.
For instance, int is not an additive group; but is a semigroup.
I should have included associativity of addition and multiplication.