From be7c89396b7ad33500bcb9ab8b457d9a2e3dcf75 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 19 Mar 2024 21:40:39 +0100 Subject: [PATCH] GRIB: avoid floating-point issues with ICC 2024.0.2.29 (refs #9508) --- frmts/grib/gribdataset.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frmts/grib/gribdataset.cpp b/frmts/grib/gribdataset.cpp index f9c5725377af..13f6a809263b 100644 --- a/frmts/grib/gribdataset.cpp +++ b/frmts/grib/gribdataset.cpp @@ -1760,13 +1760,15 @@ void GRIBArray::Init(GRIBGroup *poGroup, GRIBDataset *poDS, { bool bOK = true; auto poVar = oIterX->second->GetIndexingVariable(); + constexpr double EPSILON = 1e-10; if (poVar) { GUInt64 nStart = 0; size_t nCount = 1; double dfVal = 0; poVar->Read(&nStart, &nCount, nullptr, nullptr, m_dt, &dfVal); - if (dfVal != adfGT[0] + 0.5 * adfGT[1]) + if (std::fabs(dfVal - (adfGT[0] + 0.5 * adfGT[1])) > + EPSILON * std::fabs(dfVal)) { bOK = false; } @@ -1781,8 +1783,10 @@ void GRIBArray::Init(GRIBGroup *poGroup, GRIBDataset *poDS, double dfVal = 0; poVar->Read(&nStart, &nCount, nullptr, nullptr, m_dt, &dfVal); - if (dfVal != adfGT[3] + poDS->nRasterYSize * adfGT[5] - - 0.5 * adfGT[5]) + if (std::fabs(dfVal - + (adfGT[3] + poDS->nRasterYSize * adfGT[5] - + 0.5 * adfGT[5])) > + EPSILON * std::fabs(dfVal)) { bOK = false; }