Stan Math Library  2.14.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/core.hpp>
6 #include <cmath>
7 
8 namespace stan {
9  namespace math {
10 
24  template <typename T>
25  inline fvar<T> hypot(const fvar<T>& x1, const fvar<T>& x2) {
26  using std::sqrt;
27  T u = hypot(x1.val_, x2.val_);
28  return fvar<T>(u, (x1.d_ * x1.val_ + x2.d_ * x2.val_) / u);
29  }
30 
44  template <typename T>
45  inline fvar<T> hypot(const fvar<T>& x1, double x2) {
46  using std::sqrt;
47  T u = hypot(x1.val_, x2);
48  return fvar<T>(u, (x1.d_ * x1.val_) / u);
49  }
50 
64  template <typename T>
65  inline fvar<T> hypot(double x1, const fvar<T>& x2) {
66  using std::sqrt;
67  T u = hypot(x1, x2.val_);
68  return fvar<T>(u, (x2.d_ * x2.val_) / u);
69  }
70 
71  }
72 }
73 #endif
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:25
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:14

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