Rewrite detection of NaN in formula result to improve the exception message.