Stan Math Library  2.8.0
reverse mode automatic differentiation
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
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  using stan::math::inv;
17  T u = hypot(x1.val_, x2.val_);
18  return fvar<T>(u, (x1.d_ * x1.val_ + x2.d_ * x2.val_) * inv(u));
19  }
20 
21  template <typename T>
22  inline fvar<T> hypot(const fvar<T>& x1, const double x2) {
24  using std::sqrt;
25  using stan::math::inv;
26  T u = hypot(x1.val_, x2);
27  return fvar<T>(u, (x1.d_ * x1.val_) * inv(u));
28  }
29 
30  template <typename T>
31  inline fvar<T> hypot(const double x1, const fvar<T>& x2) {
33  using std::sqrt;
34  using stan::math::inv;
35  T u = hypot(x1, x2.val_);
36  return fvar<T>(u, (x2.d_ * x2.val_) * inv(u));
37  }
38 
39  }
40 }
41 #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:15
fvar< T > inv(const fvar< T > &x)
Definition: inv.hpp:15
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–2015, Stan Development Team.