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 T u = hypot(x1.val_, x2.val_);
28 return fvar<T>(u, (x1.d_ * x1.val_ + x2.d_ * x2.val_) / u);
29}
30
44template <typename T>
45inline fvar<T> hypot(const fvar<T>& x1, double x2) {
46 T u = hypot(x1.val_, x2);
47 return fvar<T>(u, (x1.d_ * x1.val_) / u);
48}
49
63template <typename T>
64inline fvar<T> hypot(double x1, const fvar<T>& x2) {
65 T u = hypot(x1, x2.val_);
66 return fvar<T>(u, (x2.d_ * x2.val_) / u);
67}
68
69} // namespace math
70} // namespace stan
71#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