pow.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_SCAL_FUN_POW_HPP
2 #define STAN_MATH_FWD_SCAL_FUN_POW_HPP
3 
4 #include <stan/math/fwd/core.hpp>
5 
10 
11 namespace stan {
12 namespace math {
13 
14 template <typename T>
15 inline fvar<T> pow(const fvar<T>& x1, const fvar<T>& x2) {
16  using std::log;
17  using std::pow;
18  T pow_x1_x2(pow(x1.val_, x2.val_));
19  return fvar<T>(pow_x1_x2, (x2.d_ * log(x1.val_) + x2.val_ * x1.d_ / x1.val_)
20  * pow_x1_x2);
21 }
22 
23 template <typename T>
24 inline fvar<T> pow(double x1, const fvar<T>& x2) {
25  using std::log;
26  using std::pow;
27  T u = pow(x1, x2.val_);
28  return fvar<T>(u, x2.d_ * log(x1) * u);
29 }
30 
31 template <typename T>
32 inline fvar<T> pow(const fvar<T>& x1, double x2) {
33  using std::pow;
34  using std::sqrt;
35 
36  if (x2 == -2)
37  return inv_square(x1);
38  if (x2 == -1)
39  return inv(x1);
40  if (x2 == -0.5)
41  return inv_sqrt(x1);
42  if (x2 == 0.5)
43  return sqrt(x1);
44  if (x2 == 1.0)
45  return x1;
46  if (x2 == 2.0)
47  return square(x1);
48 
49  return fvar<T>(pow(x1.val_, x2), x1.d_ * x2 * pow(x1.val_, x2 - 1));
50 }
51 } // namespace math
52 } // namespace stan
53 #endif
fvar< T > inv_sqrt(const fvar< T > &x)
Definition: inv_sqrt.hpp:12
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:12
Float_t x1[n_points_granero]
Definition: compare.C:5
T sqrt(T number)
Definition: d0nt_math.hpp:156
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:12
fvar< T > square(const fvar< T > &x)
Definition: square.hpp:12
fvar< T > inv_square(const fvar< T > &x)
Definition: inv_square.hpp:12
var pow(double base, const var &exponent)
Definition: pow.hpp:148
double T
Definition: Xdiff_gwt.C:5
fvar< T > pow(const fvar< T > &x1, const fvar< T > &x2)
Definition: pow.hpp:15
fvar< T > inv(const fvar< T > &x)
Definition: inv.hpp:12