Stan Math Library  2.11.0
reverse mode automatic differentiation
ub_constrain.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_UB_CONSTRAIN_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_UB_CONSTRAIN_HPP
3 
4 #include <boost/math/tools/promotion.hpp>
6 #include <cmath>
7 #include <limits>
8 
9 namespace stan {
10 
11  namespace math {
12 
13  // UPPER BOUND
14 
34  template <typename T, typename TU>
35  inline
36  typename boost::math::tools::promote_args<T, TU>::type
37  ub_constrain(const T x, const TU ub) {
38  using std::exp;
39  if (ub == std::numeric_limits<double>::infinity())
40  return identity_constrain(x);
41  return ub - exp(x);
42  }
43 
67  template <typename T, typename TU>
68  inline
69  typename boost::math::tools::promote_args<T, TU>::type
70  ub_constrain(const T x, const TU ub, T& lp) {
71  using std::exp;
72  if (ub == std::numeric_limits<double>::infinity())
73  return identity_constrain(x, lp);
74  lp += x;
75  return ub - exp(x);
76  }
77 
78  }
79 
80 }
81 
82 #endif
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
boost::math::tools::promote_args< T, TU >::type ub_constrain(const T x, const TU ub)
Return the upper-bounded value for the specified unconstrained scalar and upper bound.
T identity_constrain(T x)
Returns the result of applying the identity constraint transform to the input.

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