Here's a preview from my zine, How Integers and Floats Work! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!
read the transcript!
NaN and infinity
NaN stands for “not a number”
It means the result of the calculation is undefined.
0/0 = NaN
sqrt(-1) = NaN
log(-1) = NaN
infinity
“Infinity” just means “this number is too big for floating point to handle.” There are two infinities: one positive, one negative.
2.0**1024 = inf
(2.0**1024
means 2^1024
)
-1/0 = -inf
inf 10 = inf
inf - inf = NaN
NaNs spread
As soon as one NaN gets in, it gets everywhere
NaN * 5 = NaN
NaN + 2 = NaN
NaN != NaN
NaN isn’t equal to anything (including itself)
NaN and infinity: the bits
A floating point value is NaN
or infinity
if the bits in the exponent are all 1. For example, this is a NaN
:
01111111 11110001 00000000 00000000 00000000 00000000 00000000 00000000
It’s infinity
if the offset bits are all 0, otherwise it’s NaN
.
There are 2^52 values like this: 2 of them are ±infinity
and the other 2^52-2 are NaN
.
We usually treat NaN
like a single value though.
a note on byte order
All of the floating point examples in this zine use a big endian byte order, because it’s easier to read. But most computers use a little endian byte order.
You can see this in action at https://memory-spy.wizardzines.com
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!