From a0ed390edbecd117b4c5576a1a05313326d657d0 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Tue, 17 Sep 2024 12:30:12 -0500 Subject: [PATCH] ParmParse::queryAsDouble: Fix bug in #4152 & #4149 (#4154) std::round should only be used when the value type is an integer, not a floating point number. --- Src/Base/AMReX_ParmParse.H | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Src/Base/AMReX_ParmParse.H b/Src/Base/AMReX_ParmParse.H index a29ac163d6..dc4fa07fb4 100644 --- a/Src/Base/AMReX_ParmParse.H +++ b/Src/Base/AMReX_ParmParse.H @@ -1470,9 +1470,11 @@ public: double dref; int exist = queryWithParser(name, dref); if (exist) { - dref = std::round(dref); + if (std::is_integral_v) { + dref = std::round(dref); + } auto vref = static_cast(dref); - if constexpr (!std::is_same_v) { + if constexpr (std::is_integral_v && !std::is_same_v) { if (static_cast(vref) != dref) { amrex::Abort("ParmParse:: queryAsDouble is not safe"); } @@ -1498,9 +1500,11 @@ public: int exist = queryarrWithParser(name, nvals, dref.data()); if (exist) { for (int i = 0; i < nvals; ++i) { - dref[i] = std::round(dref[i]); + if (std::is_integral_v) { + dref[i] = std::round(dref[i]); + } auto vref = static_cast(dref[i]); - if constexpr (!std::is_same_v) { + if constexpr (std::is_integral_v && !std::is_same_v) { if (static_cast(vref) != dref[i]) { amrex::Abort("ParmParse:: queryarrAsDouble is not safe"); }