Question

I'm migrating some code from a compiler with 32-bit integers to 64-bit. I found some old code that assumes the highest possible integer is 2147483647 and the lowest possible is -947483647.

I understand the highest (maximum signed 32-bit integer), but does anyone know what makes the lowest special? There is nothing in the business logic that suggests that this integer (used for an ID) can't be below that number.

Searching google turns up very little except some other code where someone used 947483646 in a variable called INF (infinity/highest possible number? In signed, two's-complement representation that would make "negative infinity" -947483647).

It may be just a meaningless number, but there are also a few other hits using that exact number for other integers like monster HP in a video game (while searching for other close-by numbers turn up no results) that makes me think there's something behind it.

Was it helpful?

Solution

Int32 datatype doesn't have a value for infinity, so one can randomly chose magic number to denote INF.
It's naturally to select maximal integer value (2^31-1) for +INF.
But why (-2^31) was not chosen for -INF?
Probably, because both +INF and -INF must have equal length when printed (10 chars each).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top