We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 294f312 commit 7272c82Copy full SHA for 7272c82
stan/math/fwd/fun/sqrt.hpp
@@ -16,8 +16,9 @@ namespace math {
16
template <typename T>
17
inline fvar<T> sqrt(const fvar<T>& x) {
18
using std::sqrt;
19
- if (value_of_rec(x.val_) == 0.0)
+ 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
stan/math/rev/fun/sqrt.hpp
@@ -43,8 +43,9 @@ namespace math {
43
*/
44
inline var sqrt(const var& a) {
45
return make_callback_var(std::sqrt(a.val()), [a](auto& vi) mutable {
46
- if (vi.val() != 0.0)
+ if (vi.val() != 0.0) {
47
a.adj() += vi.adj() / (2.0 * vi.val());
48
49
});
50
51
0 commit comments