From fa543bb0df5fb7c03f00be99ca146df341ffbc86 Mon Sep 17 00:00:00 2001 From: Luke Shingles Date: Mon, 2 Sep 2024 00:34:18 +0100 Subject: [PATCH] Update nonthermal.cc --- nonthermal.cc | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/nonthermal.cc b/nonthermal.cc index 30780dc11..a0d8bd6df 100644 --- a/nonthermal.cc +++ b/nonthermal.cc @@ -585,13 +585,7 @@ void zero_all_effionpot(const int modelgridindex) { { const int index = std::floor((energy_ev - SF_EMIN) / DELTA_E); - if (index < 0) { - return 0; - } - if (index > SFPTS - 1) { - return SFPTS - 1; - } - return index; + return std::clamp(index, 0, SFPTS - 1); } [[nodiscard]] constexpr auto get_energyindex_ev_gteq(const double energy_ev) -> int @@ -599,13 +593,7 @@ void zero_all_effionpot(const int modelgridindex) { { const int index = std::ceil((energy_ev - SF_EMIN) / DELTA_E); - if (index < 0) { - return 0; - } - if (index > SFPTS - 1) { - return SFPTS - 1; - } - return index; + return std::clamp(index, 0, SFPTS - 1); } // interpolate the y flux values to get the value at a given energy