Skip to content

Commit f45148d

Browse files
author
Jean-Christophe Ruel
committed
fix pow(0, 0) -> undefined partials
1 parent ae90c3e commit f45148d

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

stan/math/rev/fun/pow.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ inline var pow(const Scal1& base, const Scal2& exponent) {
8787
return make_callback_var(
8888
std::pow(value_of(base), value_of(exponent)),
8989
[base, exponent](auto&& vi) mutable {
90-
if (value_of(base) == 0.0) {
91-
return; // partials zero, avoids 0 & log(0)
90+
if (value_of(base) == 0.0 && value_of(exponent) != 0.0) {
91+
return; // partials zero, avoids 0 & log(0)
9292
}
9393
const double vi_mul = vi.adj() * vi.val();
9494

test/unit/math/mix/fun/pow_part1_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ TEST(mathMixScalFun, pow) {
3939
return pow(x1, x2);
4040
};
4141

42+
stan::test::expect_ad(f, 0.0, 0.0);
4243
stan::test::expect_ad(f, -0.4, 0.5);
4344
stan::test::expect_ad(f, 0.5, 0.5);
4445
stan::test::expect_ad(f, 0.5, 1.0);

0 commit comments

Comments
 (0)