floating point: NaN and infinity
@b0rk Though sqrt(-1) = NaN always annoys me, because it is a number, just not a real number
@b0rk this is actually why it's called NaN; it's not just one number, but 253 of them
@b0rk
Those darn NaNs! I have never had the pleasure of meeting the elusive #infinity (probably because the applications I usually use just give me an #error). Thank you for the excellent graphic!

@tanquist @b0rk you can use it to tell apart the 80187 and 80287 (IIRC) coprocessor. One of them didn't have -inf, so creating 1/0, and comparing to its negative lets you know which one it is. You need assembly to do this, though..

FLD 1
FLD0
FDIV
FDUP
FNEG
FCMP

@b0rk
very good.

minor addendum: most programming languages have a specific function like isnan() which returns true if a floating point value is NaN, and related functions like isinf(), isnormal() and so forth.

@llewelly @b0rk I usually compare the number with itself. This works because only NaN is unequal to itself.
For infinity you still need the special functions, yes.
@b0rk R has a special NaN, called NA for "not available", it has different meaning and is propagated consistently
@b0rk And my personal favorite oddity about NaN
@kgjenkins @b0rk what's red and invisible? No tomatoes.
@b0rk one minor addition to the bit pattern section might be to label the sign bit for +/- Infinity.
@b0rk A maybe less important addition would be to mention that some languages that only have double variables use the large number of NaN's to implement typed pointers via "NaN Boxing".
@th @b0rk I never heard of that. Here is a link for others who are wondering: https://piotrduperas.com/posts/nan-boxing
NaN boxing or how to make the world dynamic - Blog by Piotr Duperas

Have you ever wondered how dynamic typing, like in JS, works under the hood? There are some obvious solutions in this matter, however, there is also one which is more than brilliant.

NaN boxing or how to make the world dynamic - Blog by Piotr Duperas
@th @b0rk Yes! Perhaps that was explained on a previous page but I missed that info here. Another little thing is: the right edge of the underline of the exponent is a bit imprecise, looks like 10 bits (it is clear in combination with the text, though, and again, this info is probably on a previous page).
@b0rk have you seen this yet? A fun example of using floats in a really weird way https://www.youtube.com/watch?v=5TFDG-y-EHs
NaN Gates and Flip FLOPS

YouTube
@b0rk pretty cool. might also want to mention somewhere the difference between quiet NaNs and signaling NaNs?
@gray17 where have you run into signaling NaNs?
@b0rk hm, sorry, I don't remember, it's been a while since I did anything nontrivial with float math.
@b0rk I just noticed that you give complete alttext for these images. That's really wonderful!
@davidlowryduda I never know if it actually helps anyone, but maybe it does!

@b0rk things get _really_ interesting when you try to use floating point numbers as hashmap keys:
* NaN is unequal to itself, so a hashmap should allow putting many NaNs in a hashmap.
* Retrieving a value by NaN key should never return anything (because NaN != NaN).
* +0 and -0 have a different bit pattern, but are still equal so only one should be allowed (important for hashing).

Not all languages are so strict with float semantics in hashmaps, though.
https://research.swtch.com/randhash

research!rsc: Random Hash Functions

@b0rk still wondering why IEEE wasted a doubling in range for the large number of ambiguous NaN definitions. For FP64 and FP32 this usually is not a problem, but for FP16 it is.
@b0rk
My favorite:
"NaNs spread"
- as soon as one gets in, it gets everywhere
> reminds me of other "mechanics" e.g. in social life. ๐Ÿ™‚
@b0rk TIL there are many, many NANs

@b0rk Nice. Might be worth specifying this applies to IEEE 754. Some computers (VAX, IBM) have different FP formats.

Maybe also mention all comparisons with NaN are always false.

5.0 < NaN: false
5.0 > NaN: false
5.0 == NaN: false

Many people find it surprising that trichotomy doesnโ€™t hold for NaN.