Stan Math Library  2.20.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/meta.hpp>
5 #include <stan/math/fwd/core.hpp>
7 #include <cmath>
8 
9 namespace stan {
10 namespace math {
11 
12 template <typename T>
13 inline fvar<T> atan2(const fvar<T>& x1, const fvar<T>& x2) {
14  using std::atan2;
15  return fvar<T>(atan2(x1.val_, x2.val_),
16  (x1.d_ * x2.val_ - x1.val_ * x2.d_)
17  / (square(x2.val_) + square(x1.val_)));
18 }
19 
20 template <typename T>
21 inline fvar<T> atan2(double x1, const fvar<T>& x2) {
22  using std::atan2;
23  return fvar<T>(atan2(x1, x2.val_),
24  (-x1 * x2.d_) / (square(x1) + square(x2.val_)));
25 }
26 
27 template <typename T>
28 inline fvar<T> atan2(const fvar<T>& x1, double x2) {
29  using std::atan2;
30  return fvar<T>(atan2(x1.val_, x2),
31  (x1.d_ * x2) / (square(x2) + square(x1.val_)));
32 }
33 
34 } // namespace math
35 } // namespace stan
36 #endif
T d_
The tangent (derivative) of this variable.
Definition: fvar.hpp:50
fvar< T > atan2(const fvar< T > &x1, const fvar< T > &x2)
Definition: atan2.hpp:13
fvar< T > square(const fvar< T > &x)
Definition: square.hpp:12
T val_
The value of this variable.
Definition: fvar.hpp:45
var atan2(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:117
This template class represents scalars used in forward-mode automatic differentiation, which consist of values and directional derivatives of the specified template type.
Definition: fvar.hpp:41

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