Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hypot.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__FWD__FUNCTIONS__HYPOT_HPP
2 #define STAN__AGRAD__FWD__FUNCTIONS__HYPOT_HPP
3 
5 #include <stan/meta/traits.hpp>
7 #include <math.h>
8 
9 namespace stan {
10 
11  namespace agrad {
12 
13  template <typename T>
14  inline
15  fvar<T>
16  hypot(const fvar<T>& x1, const fvar<T>& x2) {
19  using stan::math::inv;
20  T u = hypot(x1.val_, x2.val_);
21  return fvar<T>(u, (x1.d_ * x1.val_ + x2.d_ * x2.val_) * inv(u));
22  }
23 
24  template <typename T>
25  inline
26  fvar<T>
27  hypot(const fvar<T>& x1, const double x2) {
30  using stan::math::inv;
31  T u = hypot(x1.val_, x2);
32  return fvar<T>(u, (x1.d_ * x1.val_) * inv(u));
33  }
34 
35  template <typename T>
36  inline
37  fvar<T>
38  hypot(const double x1, const fvar<T>& x2) {
41  using stan::math::inv;
42  T u = hypot(x1, x2.val_);
43  return fvar<T>(u, (x2.d_ * x2.val_) * inv(u));
44  }
45 
46  }
47 }
48 #endif
boost::math::tools::promote_args< T >::type inv(const T x)
Definition: inv.hpp:12
var hypot(const double &a, const stan::agrad::var &b)
Returns the length of the hypoteneuse of a right triangle with sides of the specified lengths (C99)...
Definition: hypot.hpp:119
fvar< T > hypot(const fvar< T > &x1, const fvar< T > &x2)
Definition: hypot.hpp:16
fvar< T > inv(const fvar< T > &x)
Definition: inv.hpp:15
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:15

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