Count to 10 on your fingers. Really :)
The standard way to count to 10 is 1,2,3,..10
(the ordinality of each finger is counted). However, what about "0 fingers"?
Normally that might represent that by putting your hands behind our back, but that adds another piece of information to the system: are your hands in front (present) or behind (missing)?
In this case, putting hands behind your back would equivalent to assigning nil
to an NSNumber
variable. However, NSUInteger
represents a native integer type which does not have this extra state and must still encode 0 to be useful.
The key to encode the value 0 on your fingers is to simply count 0,1,2..9
instead. The same number of fingers (or bits of information) are available, but now the useful 0
can be accounted for .. at the expense of not having a 10
value (there are still 10 fingers, but the 10th finger only represents the value 9
). This is the same reason why unsigned integers have a maximum value of 2^n-1
and not 2^n
: it allows 0
to be encoded with maximum efficiency.
Now, NaN
is not a typical integer value, but rather comes from floating point encodings - think of float
or CGFloat
. One such common encoding is IEEE 754:
In computing, NaN, standing for not a number, is a numeric data type value representing an undefined or unrepresentable value, especially in floating-point calculations ..