Stan Math Library  2.20.0
reverse mode automatic differentiation
hypot.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_SCAL_FUN_HYPOT_HPP
2 #define STAN_MATH_FWD_SCAL_FUN_HYPOT_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 
25 template <typename T>
26 inline fvar<T> hypot(const fvar<T>& x1, const fvar<T>& x2) {
27  using std::sqrt;
28  T u = hypot(x1.val_, x2.val_);
29  return fvar<T>(u, (x1.d_ * x1.val_ + x2.d_ * x2.val_) / u);
30 }
31 
45 template <typename T>
46 inline fvar<T> hypot(const fvar<T>& x1, double x2) {
47  using std::sqrt;
48  T u = hypot(x1.val_, x2);
49  return fvar<T>(u, (x1.d_ * x1.val_) / u);
50 }
51 
65 template <typename T>
66 inline fvar<T> hypot(double x1, const fvar<T>& x2) {
67  using std::sqrt;
68  T u = hypot(x1, x2.val_);
69  return fvar<T>(u, (x2.d_ * x2.val_) / u);
70 }
71 
72 } // namespace math
73 } // namespace stan
74 #endif
T d_
The tangent (derivative) of this variable.
Definition: fvar.hpp:50
fvar< T > hypot(const fvar< T > &x1, const fvar< T > &x2)
Return the length of the hypoteneuse of a right triangle with opposite and adjacent side lengths give...
Definition: hypot.hpp:26
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:13
T val_
The value of this variable.
Definition: fvar.hpp:45
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.