stan-dev/stan — pull request #851 by syclik (2014-08-11 16:51:51+00:00)
Title: Feature/issue 850 Phi nan input

#### Summary:

`stan::math::Phi`, for double inputs, correctly handles `NaN` input.

#### Intended Effect:

Fixes a bug. `NaN` input used to return 1.0.

#### How to Verify:

See added test in src/test/unit/math/functions/Phi.hpp

#### Side Effects:

Phi might be a little slower due to the error check up front. I think we could write it with another if statement and have the check come at the end taking advantage of knowing the rules for comparison with floating point numbers.

That is, we could do something like:
```
if (x <= 8.25 && x >= -5.0)
return 0.5 * (1.0 + boost::math::erf(INV_SQRT_2 * x));
...
else {
check_not_nan("Phi(%1%)", x, "x", (double *)0);
return 0.5 * (1.0 + boost::math::erf(INV_SQRT_2 * x));
}
```

But I think it might be overkill?

#### Documentation:

Not user facing. This is a bug.

#### Reviewer Suggestions:

Anyone.