Skip to Content

A stick figure smiling

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!

Image of a comic. To read the full HTML alt text, click "read the transcript".

browse more comics! get the zine!
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” 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

Saturday Morning Comics!

Want another comic like this in your email every Saturday? Sign up here!

I'll send you one of my favourite comics from my archives every Saturday.
© Julia Evans 2024 | All rights reserved (see the FAQ for notes about licensing)