Is there a way to set Unity to write message log when the calculation has Infinity or NaN?

I've written a simple soccer simulation. It works without any error log from Unity. But I saw that the AI didn't have good decision behavior. So, I decided to check some variables with Debug.Log I found that some of them are infinity or NaN due to variable error or math error in my math method. What surprised me was that the simulation was still working and Unity didn't show any error message at all. Even if those variables were often used (comparing or dividing). o_O

I've already fixed the problem I found. But I'm worry that there may be more math error like this in my code which I still can't find. Is there a way to tell Unity to notify the user when the calculation has infinity or NaN?

Thank You

Actually, it isn't float.Infinity, it's Mathf.Infinity. And unfortunately, that only represents positive Infinite values, you would also need to compare to Mathf.NegativeInfinity.

A slightly better way would be:

if (float.IsInfinity(myFloat) || float.IsNaN(myFloat))
    Debug.Log("wups");

float.IsInfinity() checks for both positive and negative values of Infinity. Negative Infinity - what a concept...

No, you can't just notify randomly when any variable is equal to something, but you can do this to check each individual float:

if(myFloat == float.Infinity)

or

if(myFloat == float.NaN)

Most of the time you should be checking if you're dividing things by zero - that's when things really go wrong. It'll save you time later if you check if divisors are zero before using them, and throw errors or modify the values if they are