use NaNMath package to return NaNs instead of throwing DomainErrors

This seems to be a cleaner workaround than #6, at least until there's a solution in base Julia.