Stan Math Library  2.12.0
reverse mode automatic differentiation
atan2.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_SCAL_FUN_ATAN2_HPP
2 #define STAN_MATH_FWD_SCAL_FUN_ATAN2_HPP
3 
4 #include <stan/math/fwd/core.hpp>
6 #include <cmath>
7 
8 namespace stan {
9  namespace math {
10 
11  template <typename T>
12  inline fvar<T> atan2(const fvar<T>& x1, const fvar<T>& x2) {
13  using std::atan2;
14  return fvar<T>(atan2(x1.val_, x2.val_),
15  (x1.d_ * x2.val_ - x1.val_ * x2.d_) /
16  (square(x2.val_) + square(x1.val_)));
17  }
18 
19  template <typename T>
20  inline fvar<T> atan2(const double x1, const fvar<T>& x2) {
21  using std::atan2;
22  return fvar<T>(atan2(x1, x2.val_),
23  (-x1 * x2.d_) / (square(x1) + square(x2.val_)));
24  }
25 
26  template <typename T>
27  inline fvar<T> atan2(const fvar<T>& x1, const double x2) {
28  using std::atan2;
29  return fvar<T>(atan2(x1.val_, x2),
30  (x1.d_ * x2) / (square(x2) + square(x1.val_)));
31  }
32 
33  }
34 }
35 #endif
fvar< T > atan2(const fvar< T > &x1, const fvar< T > &x2)
Definition: atan2.hpp:12
fvar< T > square(const fvar< T > &x)
Definition: square.hpp:14
var atan2(const double a, const var &b)
Return the principal value of the arc tangent, in radians, of the first scalar divided by the second ...
Definition: atan2.hpp:119

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