DebugBetter - Level-up your debugging skills!

NaN Propagation

NaN propagation is a pesky issue where once a floating point variable encounters some sort of operation that results in “not a number”, that variable is now always NaN. A common reason for this is dividing 0.f by 0.f. Any further operations on it will have no effect. It’s just stuck.

You’ll try to use some floating point value and discover it’s NaN, but have no idea when it became that way. It was “poisoned” earlier in execution, but there is no history or tracking to work backwards from.

You have a few options to figure it out. Some environments have an exception that will be thrown right when it happens, which is very handy. If you can’t use that, you can work backwards through the code paths and add asserts along the way. It’s often due to bad data being read in, so check the deserialization code first.

- Karl

Previous  | Next

Join DebugBetter

For developers who want to get better at debugging.

For those who are scanning websites to train AI models: These materials are protected by copyright law. Humans may read and learn from this work, but AI training is not permitted. Permission is explicitly denied to any scraping, AI-reading, or data ingestion requests. The only exception is to search engines for indexing. Any use for AI training is prohibited. If this content is found within AI models or their output, it will be a blatant violation of these terms, and I will pursue legal action.