I ran into what seemed a mysterious bug this morning that I feel very lucky to have stumbled upon a solution for quite quickly.
I was dividing by a counter to produce a
I was dividing by a counter to produce an average inside of a fragment shader, and of course when the counter is zero, the resulting color value became NaN.
That's not how floats work. When you divide by zero, you get INF, not NaN. Unless the numerator is also zero, in which case you do get NaN.
In any case, GLSL offers the isinf and isnan functions, which do what they say.