handle nan and inf