Automatic Differentiation
 
Loading...
Searching...
No Matches
sqrt.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_SQRT_HPP
2#define STAN_MATH_FWD_FUN_SQRT_HPP
3
10#include <cmath>
11#include <complex>
12
13namespace stan {
14namespace math {
15
16template <typename T>
17inline fvar<T> sqrt(const fvar<T>& x) {
18 using std::sqrt;
19 if (value_of_rec(x.val_) == 0.0) {
20 return fvar<T>(sqrt(x.val_), 0.0 * x.d_);
21 }
22 return fvar<T>(sqrt(x.val_), 0.5 * x.d_ * inv_sqrt(x.val_));
23}
24
32template <typename T>
33inline std::complex<fvar<T>> sqrt(const std::complex<fvar<T>>& z) {
34 return internal::complex_sqrt(z);
35}
36
37} // namespace math
38} // namespace stan
39#endif
std::complex< V > complex_sqrt(const std::complex< V > &z)
Return the square root of the complex argument.
Definition sqrt.hpp:70
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
fvar< T > sqrt(const fvar< T > &x)
Definition sqrt.hpp:17
fvar< T > inv_sqrt(const fvar< T > &x)
Definition inv_sqrt.hpp:12
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9
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