09-08-2023, 03:57 PM
An easy way to test for NaN is to compare the result against itself - NaN is the only floating-point value which is not equal to itself. That said, arguably the better way to handle this is to check for the NaN-causing situations before doing the math.