diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index dadfd53f8..77e976669 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -73,6 +73,8 @@ conserving total angular momentum. See Bug Fixes --------- +Fixed an issue where the `find0_quadratic` subroutine provided by the `num` module could accidentally divide by 0 when the points used for the quadratic interpolant did not bracket a root. + Fixed ``switch_to_radiative`` zeroing saved ``mlt_vc`` during TDC photo restarts and preparation for a new step. Mixing cleanup now preserves the velocity until it has been copied to ``mlt_vc_old``. diff --git a/num/public/num_lib.f90 b/num/public/num_lib.f90 index 970fa2963..39d7bb96e 100644 --- a/num/public/num_lib.f90 +++ b/num/public/num_lib.f90 @@ -550,6 +550,11 @@ real(dp) function find0_quadratic(xx1, yy1, xx2, yy2, xx3, yy3, ierr) result(x) b = sqrt(s2) a = xx3**2*(yy1 - yy2) + xx1**2*(yy2 - yy3) + xx2**2*(-yy1 + yy3) denom = 2*(xx3*(yy1 - yy2) + xx1*(yy2 - yy3) + xx2*(-yy1 + yy3)) + ! Guard against an unlikely, but unfortunate, division by 0. + if (denom == 0) then + ierr = -1 + return + end if x = (a + b)/denom if (x > max(xx1, xx2, xx3)) x = (a - b)/denom if (x < min(xx1, xx2, xx3) .or. x > max(xx1, xx2, xx3)) ierr = -1