| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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>
6 #include <stan/math/prim/scal/fun/inv.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) {
14 using ::hypot;
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) {
23 using ::hypot;
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) {
32 using ::hypot;
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
core.hpp
stan::math::fvar::d_
T d_
Definition: fvar.hpp:15
stan::math::hypot
fvar< T > hypot(const fvar< T > &x1, const fvar< T > &x2)
Definition: hypot.hpp:13
stan::math::sqrt
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:15
stan
Definition: log_sum_exp.hpp:8
stan::math::fvar::val_
T val_
Definition: fvar.hpp:14
inv.hpp
stan::math::fvar
Definition: fvar.hpp:13
stan::math::inv
fvar< T > inv(const fvar< T > &x)
Definition: inv.hpp:15
stan::math::hypot
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.