Stan Math Library  2.12.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 <math.h>
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> hypot(const fvar<T>& x1, const fvar<T>& x2) {
15  using std::sqrt;
16  T u = hypot(x1.val_, x2.val_);
17  return fvar<T>(u, (x1.d_ * x1.val_ + x2.d_ * x2.val_) * inv(u));
18  }
19 
20  template <typename T>
21  inline fvar<T> hypot(const fvar<T>& x1, const double x2) {
23  using std::sqrt;
24  T u = hypot(x1.val_, x2);
25  return fvar<T>(u, (x1.d_ * x1.val_) * inv(u));
26  }
27 
28  template <typename T>
29  inline fvar<T> hypot(const double x1, const fvar<T>& x2) {
31  using std::sqrt;
32  T u = hypot(x1, x2.val_);
33  return fvar<T>(u, (x2.d_ * x2.val_) * inv(u));
34  }
35 
36  }
37 }
38 #endif
fvar< T > hypot(const fvar< T > &x1, const fvar< T > &x2)
Definition: hypot.hpp:13
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:14
fvar< T > inv(const fvar< T > &x)
Definition: inv.hpp:14
var hypot(double a, const var &b)
Returns the length of the hypoteneuse of a right triangle with sides of the specified lengths (C99)...
Definition: hypot.hpp:116

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