Automatic Differentiation
 
Loading...
Searching...
No Matches
hypot.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_HYPOT_HPP
2#define STAN_MATH_FWD_FUN_HYPOT_HPP
3
7#include <cmath>
8
9namespace stan {
10namespace math {
11
25template <typename T>
26inline fvar<T> hypot(const fvar<T>& x1, const fvar<T>& x2) {
27 using std::sqrt;
28 T u = hypot(x1.val_, x2.val_);
29 return fvar<T>(u, (x1.d_ * x1.val_ + x2.d_ * x2.val_) / u);
30}
31
45template <typename T>
46inline fvar<T> hypot(const fvar<T>& x1, double x2) {
47 using std::sqrt;
48 T u = hypot(x1.val_, x2);
49 return fvar<T>(u, (x1.d_ * x1.val_) / u);
50}
51
65template <typename T>
66inline fvar<T> hypot(double x1, const fvar<T>& x2) {
67 using std::sqrt;
68 T u = hypot(x1, x2.val_);
69 return fvar<T>(u, (x2.d_ * x2.val_) / u);
70}
71
72} // namespace math
73} // namespace stan
74#endif
fvar< T > hypot(const fvar< T > &x1, const fvar< T > &x2)
Return the length of the hypotenuse of a right triangle with opposite and adjacent side lengths given...
Definition hypot.hpp:26
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Scalar val_
The value of this variable.
Definition fvar.hpp:49
Scalar d_
The tangent (derivative) of this variable.
Definition fvar.hpp:61
This template class represents scalars used in forward-mode automatic differentiation,...
Definition fvar.hpp:40