moved test for nan into its own function
moved test for nan into its own function

stan-dev/stan,stan-dev/math,stan-dev/stan,stan-dev/math,stan-dev/math,stan-dev/stan,stan-dev/math,stan-dev/stan,stan-dev/math,stan-dev/math,stan-dev/math,stan-dev/math,stan-dev/math,stan-dev/stan