Handling of NaN values in mathematical operations