From 29945fc47ebc0ad268f8336a7aa2c9a3e53a42c9 Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Tue, 3 Nov 2026 14:41:53 -0500 Subject: [PATCH 1/2] fix: div by zero guard in find0_quadratic --- docs/source/changelog.rst | 2 ++ num/public/num_lib.f90 | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 817a9c24ea..8b00882955 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -73,6 +73,8 @@ conserving total angular momentum. See Bug Fixes --------- +Add a division by zero guard in `find0_quadratic`. This could occur 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 970fa29637..39d7bb96e4 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 From fa44a10d385edbe2018acd3177de433541e557dc Mon Sep 17 00:00:00 2001 From: Brandon Bright-Barker Date: Tue, 3 Nov 2026 15:39:25 -0500 Subject: [PATCH 2/2] tweak changelog Co-authored-by: Ebraheem Farag <63124736+Debraheem@users.noreply.github.com> --- docs/source/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 8b00882955..ca8edf25bc 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -73,7 +73,7 @@ conserving total angular momentum. See Bug Fixes --------- -Add a division by zero guard in `find0_quadratic`. This could occur when the points used for the quadratic interpolant did not bracket a root. +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