Right, that’s very well. It is a part if IEEE 754 floating-point arithmetic and conditions where NaN appears are indeed very precisely defined.
Very strictly speaking, you could think of what I’m proposing here is to create new floating point type, with its own rules and own definition of NaN, which is not the IEEE 754 float, but a new thing that just happens to look 99% like it so that it can use the existing IEEE 754 hardware for speed.
I fully acknowledge that there are domains where NaN / Inf is valid, useful and necessary. And f32 / f64 are the types to be used there.
However, there are also other domains (in my case image and video codecs) where all the well-defined proper IEEE 754 operations on NaN and Inf are never needed in practice. The nature of the problem is such that these values have no use, and are never intentionally created. In such context a NaN appearing in the program against author’s intention is an indication of a bug. For example when I have an array of RGB pixels as floats, then the concept of NaN or Inf does not apply to them. I can’t display NaN Red or Inf Blue on screen. If my program happens to produce a non-finite color value, that’s a bug in my program, even though the steps that lead to producing that value are well-defined in IEEE 754 spec, it is an indication of my mistake.
The problem is that programs which don’t intend to make useful use of NaN still have to pay the cost of it. The code is slower because the compiler is required to preserve very specific NaN handling rules, even when the program by design is incapable of doing anything useful with them.