It more or less doesn't know anything after a NAN. It is implicitly assumed that the user writes code that does not produce NANS. For the exp you can use mfexp (hopefully) which modifies the value fo exp for large numbers to avoid NANS.