Bug in number range


In the book it says:

“A signed 64-bit number can hold any integer from -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807”.

I think you are counting the zero twice. It should be:

“A signed 64-bit number can hold any integer from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807”.


from -2^63 to 2^63-1.


I see your point: it seems like the chip should use the whole range of the 64-bit number, but I think you are wrong. I’m pretty sure (and I should double-check) that zero does get counted twice – that there is, essentially and positive and a negative zero.


Knowing that Wikipedia isn’t the one and all truth, allow me to quote it:

“The most common is two’s complement, which allows a signed integral type with n bits to represent numbers from −2(n−1) through 2(n−1)−1.”

From en.wikipedia.org/wiki/Integer_(computer_science

Also the same goes for C++ on Windows, look at the range for __int64:


(I snipped the URL to MSDN since it didn’t copy properly into the forum - the URL is pretty whacked with parenthesis and whatnot :wink: )


OK, I can accept when I am wrong: I am wrong. I’ll fix it in the next printing.


I love an esoteric argument as much as the next person.

The proof is in the pudding, right?

So let’s try it.
In the code snippet:

long test0 = 9223372036854775806; long poslimit = 9223372036854775807; long posoverlimit = 9223372036854775808; long neglimit = -9223372036854775807; long negoverlimit = -9223372036854775808; long negwayoverlimit = -9223372036854775809; printf("test0 is %ld.\n", test0); printf("poslimit is %ld.\n", poslimit); printf("posoverlimit is %ld.\n", posoverlimit); printf("neglimit is %ld.\n", neglimit); printf("negoverlimit is %ld.\n", negoverlimit); printf("negwayoverlimit is %ld.\n", negwayoverlimit);

The variables posoverlimit, negoverlimit, and negwayoverlimit are flagged with the warning:
“Integer constant is so large that it is unsigned”.

However, here are the results:

test0 is 9223372036854775806. poslimit is 9223372036854775807. posoverlimit is -9223372036854775808. neglimit is -9223372036854775807. negoverlimit is -9223372036854775808. negwayoverlimit is 9223372036854775807.

Here’s a screenshot.

I haven’t gotten to the part of the book about warnings, so I don’t really understand the warnings.

But it seems that the limits are -9223372036854775808 through 9223372036854775807.