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
11#include <cmath>
12#include <complex>
13
14namespace stan {
15namespace math {
16
17template <typename T>
18inline fvar<T> sqrt(const fvar<T>& x) {
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:89
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:18
fvar< T > inv_sqrt(const fvar< T > &x)
Definition inv_sqrt.hpp:14
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