Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Phi.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__FUNCTIONS__PHI_HPP
2 #define STAN__MATH__FUNCTIONS__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
34  check_not_nan("Phi(%1%)", x, "x", static_cast<double*>(0));
35  if (x < -37.5)
36  return 0;
37  else if (x < -5.0)
38  return 0.5 * boost::math::erfc(-INV_SQRT_2 * x);
39  else if (x > 8.25)
40  return 1;
41  else
42  return 0.5 * (1.0 + boost::math::erf(INV_SQRT_2 * x));
43  }
44 
45  }
46 }
47 
48 #endif
fvar< T > erf(const fvar< T > &x)
Definition: erf.hpp:17
fvar< T > erfc(const fvar< T > &x)
Definition: erfc.hpp:17
boost::math::tools::promote_args< T >::type Phi(const T x)
The unit normal cumulative distribution function.
Definition: Phi.hpp:31
const double INV_SQRT_2
The value of 1 over the square root of 2, .
Definition: constants.hpp:26
bool check_not_nan(const char *function, const T_y &y, const char *name, T_result *result)
Checks if the variable y is nan.

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