Stan Math Library  2.10.0
reverse mode automatic differentiation
Phi.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_PHI_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_PHI_HPP
3 
4 #include <boost/math/tools/promotion.hpp>
5 #include <boost/math/special_functions/erf.hpp>
8 
9 namespace stan {
10  namespace math {
11 
29  template <typename T>
30  inline typename boost::math::tools::promote_args<T>::type
31  Phi(const T x) {
32  // overridden in fvar and var, so can hard-code boost versions
33  // here for scalars only
35 
36  check_not_nan("Phi", "x", x);
37  if (x < -37.5)
38  return 0;
39  else if (x < -5.0)
40  return 0.5 * boost::math::erfc(-INV_SQRT_2 * x);
41  else if (x > 8.25)
42  return 1;
43  else
44  return 0.5 * (1.0 + boost::math::erf(INV_SQRT_2 * x));
45  }
46 
47  }
48 }
49 
50 #endif
bool check_not_nan(const char *function, const char *name, const T_y &y)
Return true if y is not NaN.
fvar< T > erf(const fvar< T > &x)
Definition: erf.hpp:14
const double INV_SQRT_2
The value of 1 over the square root of 2, .
Definition: constants.hpp:27
fvar< T > Phi(const fvar< T > &x)
Definition: Phi.hpp:14
fvar< T > erfc(const fvar< T > &x)
Definition: erfc.hpp:14

     [ Stan Home Page ] © 2011–2016, Stan Development Team.