Curious about how fast self addition would grow, I wrote a quick little loop in Java to see:
int count = 1;
while(true){
System.out.println(count);
count += count;
}
The output was unexpected:
0
0
0
0
0
...
Why is this? count
is initialized to 1, so the inner addition should be doing count + count
or 1 + 1
. Why is the result 0?
Additive identity is the value when added to a number, results in the original number. When we add 0 to any real number, we get the same real number. For example, 5 + 0 = 5. Therefore, 0 is the additive identity of any real number.
All positive numbers have their opposite as the same number with a negative value. And, negative numbers like -1, -2, -3, -4 their opposite will be 1, 2, 3, 4 placed left from 0. All negative numbers have their opposite as the same numbers with positive value. Hence, the opposite of zero is itself.
Definition of identity element For example, 0 is the identity element under addition for the real numbers, since for any real number a, a + 0 = a, and 1 is the identity element under multiplication for the real numbers, since a X 1 = a.
The output you've posted is the trailing lines of the output, not the first 30-31 lines. It goes so fast that after the first 31 iterations it goes beyond INT MAX
and the addition results in 0. Remember that a signed integer has a max value of 2^31
, or 4 bytes with a sign bit.
Instead of while(true) {
try while(count>0) {
, you will get to see the first few iterations when it wasn't 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With