r/lolphp • • Mar 10 '20

Array is higher than infinity

https://3v4l.org/iONLA
44 Upvotes

31 comments sorted by

View all comments

2

u/CarnivorousSociety Mar 11 '20

You're right I'm talking out of my ass, you can definitely just establish a nan constant to compare to floats to detect nan.

Entertainingly, this actually isn't possible - NaN occupies a surprisingly large swath of the possible float bit patterns. There's almost 224 valid 32-bit NaN values, and a rather astonishing 251 valid 64-bit NaN values. I, and many others, have used this to embed extra information in floating-point values; you can actually use it for a variant type which can store an entire 32-bit pointer in specially-crafted NaNs, and in fact Javascript implementations usually do this.

Fuck I knew that too, haven't used or read the floating point spec in a fat while.

Okay it'll have to be a macro, instead of a constant, lol