Skip to content

Commit

Permalink
GRIB: avoid floating-point issues with ICC 2024.0.2.29 (refs OSGeo#9508)
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Mar 20, 2024
1 parent b620c87 commit be7c893
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions frmts/grib/gribdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit be7c893

Please sign in to comment.