Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace use of CPLIsNan() -> std::isnan(), CPLIsInf() -> std::isinf(), CPLIsFinite() -> std::isfinite() #10605

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion alg/gdalapplyverticalshiftgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include "proj.h"

#include <cmath>
#include <limits>

/************************************************************************/
Expand Down Expand Up @@ -255,7 +256,7 @@ CPLErr GDALApplyVSGRasterBand::IReadBlock(int nBlockXOff, int nBlockYOff,
if (bHasNoData && fSrcVal == fNoDataValue)
{
}
else if (CPLIsInf(fGridVal))
else if (std::isinf(fGridVal))
{
CPLError(CE_Failure, CPLE_AppDefined,
"Missing vertical grid value at source (%d,%d)",
Expand Down
19 changes: 11 additions & 8 deletions alg/gdalwarper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <string.h>

#include <algorithm>
#include <cmath>
#include <limits>

#include "cpl_conv.h"
Expand Down Expand Up @@ -397,7 +398,7 @@ CPLErr GDALWarpNoDataMasker(void *pMaskFuncArg, int nBandCount,
{
const float fNoData = static_cast<float>(padfNoData[0]);
const float *pafData = reinterpret_cast<float *>(*ppImageData);
const bool bIsNoDataNan = CPL_TO_BOOL(CPLIsNan(fNoData));
const bool bIsNoDataNan = CPL_TO_BOOL(std::isnan(fNoData));

// Nothing to do if value is out of range.
if (padfNoData[1] != 0.0)
Expand All @@ -410,7 +411,7 @@ CPLErr GDALWarpNoDataMasker(void *pMaskFuncArg, int nBandCount,
for (size_t iOffset = 0; iOffset < nPixels; ++iOffset)
{
float fVal = pafData[iOffset];
if ((bIsNoDataNan && CPLIsNan(fVal)) ||
if ((bIsNoDataNan && std::isnan(fVal)) ||
(!bIsNoDataNan && ARE_REAL_EQUAL(fVal, fNoData)))
{
bAllValid = FALSE;
Expand All @@ -425,7 +426,7 @@ CPLErr GDALWarpNoDataMasker(void *pMaskFuncArg, int nBandCount,
{
const double dfNoData = padfNoData[0];
const double *padfData = reinterpret_cast<double *>(*ppImageData);
const bool bIsNoDataNan = CPL_TO_BOOL(CPLIsNan(dfNoData));
const bool bIsNoDataNan = CPL_TO_BOOL(std::isnan(dfNoData));

// Nothing to do if value is out of range.
if (padfNoData[1] != 0.0)
Expand All @@ -438,7 +439,7 @@ CPLErr GDALWarpNoDataMasker(void *pMaskFuncArg, int nBandCount,
for (size_t iOffset = 0; iOffset < nPixels; ++iOffset)
{
double dfVal = padfData[iOffset];
if ((bIsNoDataNan && CPLIsNan(dfVal)) ||
if ((bIsNoDataNan && std::isnan(dfVal)) ||
(!bIsNoDataNan && ARE_REAL_EQUAL(dfVal, dfNoData)))
{
bAllValid = FALSE;
Expand All @@ -453,7 +454,8 @@ CPLErr GDALWarpNoDataMasker(void *pMaskFuncArg, int nBandCount,
{
const int nWordSize = GDALGetDataTypeSizeBytes(eType);

const bool bIsNoDataRealNan = CPL_TO_BOOL(CPLIsNan(padfNoData[0]));
const bool bIsNoDataRealNan =
CPL_TO_BOOL(std::isnan(padfNoData[0]));

double *padfWrk =
static_cast<double *>(CPLMalloc(nXSize * sizeof(double) * 2));
Expand All @@ -466,7 +468,8 @@ CPLErr GDALWarpNoDataMasker(void *pMaskFuncArg, int nBandCount,

for (int iPixel = 0; iPixel < nXSize; ++iPixel)
{
if (((bIsNoDataRealNan && CPLIsNan(padfWrk[iPixel * 2])) ||
if (((bIsNoDataRealNan &&
std::isnan(padfWrk[iPixel * 2])) ||
(!bIsNoDataRealNan &&
ARE_REAL_EQUAL(padfWrk[iPixel * 2], padfNoData[0]))))
{
Expand Down Expand Up @@ -1801,7 +1804,7 @@ CPLXMLNode *CPL_STDCALL GDALSerializeWarpOptions(const GDALWarpOptions *psWO)

if (psWO->padfSrcNoDataImag != nullptr)
{
if (CPLIsNan(psWO->padfSrcNoDataImag[i]))
if (std::isnan(psWO->padfSrcNoDataImag[i]))
CPLCreateXMLElementAndValue(psBand, "SrcNoDataImag", "nan");
else
CPLCreateXMLElementAndValue(
Expand All @@ -1826,7 +1829,7 @@ CPLXMLNode *CPL_STDCALL GDALSerializeWarpOptions(const GDALWarpOptions *psWO)

if (psWO->padfDstNoDataImag != nullptr)
{
if (CPLIsNan(psWO->padfDstNoDataImag[i]))
if (std::isnan(psWO->padfDstNoDataImag[i]))
CPLCreateXMLElementAndValue(psBand, "DstNoDataImag", "nan");
else
CPLCreateXMLElementAndValue(
Expand Down
2 changes: 1 addition & 1 deletion alg/gdalwarpkernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4999,7 +4999,7 @@ GWKCheckAndComputeSrcOffsets(GWKJobStruct *psJob, int *_pabSuccess, int _iDstX,
return false;

// If this happens this is likely the symptom of a bug somewhere.
if (CPLIsNan(_padfX[_iDstX]) || CPLIsNan(_padfY[_iDstX]))
if (std::isnan(_padfX[_iDstX]) || std::isnan(_padfY[_iDstX]))
{
static bool bNanCoordFound = false;
if (!bNanCoordFound)
Expand Down
8 changes: 4 additions & 4 deletions alg/gdalwarpoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,12 +756,12 @@ void *GDALWarpOperation::CreateDestinationBuffer(int nDstXSize, int nDstYSize,
0, std::min(255, static_cast<int>(adfInitRealImag[0]))),
nBandSize);
}
else if (!CPLIsNan(adfInitRealImag[0]) && adfInitRealImag[0] == 0.0 &&
!CPLIsNan(adfInitRealImag[1]) && adfInitRealImag[1] == 0.0)
else if (!std::isnan(adfInitRealImag[0]) && adfInitRealImag[0] == 0.0 &&
!std::isnan(adfInitRealImag[1]) && adfInitRealImag[1] == 0.0)
{
memset(pBandData, 0, nBandSize);
}
else if (!CPLIsNan(adfInitRealImag[1]) && adfInitRealImag[1] == 0.0)
else if (!std::isnan(adfInitRealImag[1]) && adfInitRealImag[1] == 0.0)
{
GDALCopyWords64(&adfInitRealImag, GDT_Float64, 0, pBandData,
psOptions->eWorkingDataType, nWordSize,
Expand Down Expand Up @@ -2830,7 +2830,7 @@ bool GDALWarpOperation::ComputeSourceWindowTransformPoints(
}

// If this happens this is likely the symptom of a bug somewhere.
if (CPLIsNan(padfX[i]) || CPLIsNan(padfY[i]))
if (std::isnan(padfX[i]) || std::isnan(padfY[i]))
{
static bool bNanCoordFound = false;
if (!bNanCoordFound)
Expand Down
1 change: 1 addition & 0 deletions alg/marching_squares/square.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <math.h>
#include "utility.h"
Expand Down
18 changes: 10 additions & 8 deletions apps/gdaldem_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
#endif

#include <algorithm>
#include <cmath>
#include <limits>

#include "cpl_error.h"
Expand Down Expand Up @@ -217,7 +218,7 @@ float ComputeVal(bool bSrcHasNoData, float fSrcNoDataValue,
{
if (bSrcHasNoData &&
((!bIsSrcNoDataNan && ARE_REAL_EQUAL(afWin[4], fSrcNoDataValue)) ||
(bIsSrcNoDataNan && CPLIsNan(afWin[4]))))
(bIsSrcNoDataNan && std::isnan(afWin[4]))))
{
return fDstNoDataValue;
}
Expand All @@ -227,7 +228,7 @@ float ComputeVal(bool bSrcHasNoData, float fSrcNoDataValue,
{
if ((!bIsSrcNoDataNan &&
ARE_REAL_EQUAL(afWin[k], fSrcNoDataValue)) ||
(bIsSrcNoDataNan && CPLIsNan(afWin[k])))
(bIsSrcNoDataNan && std::isnan(afWin[k])))
{
if (bComputeAtEdges)
afWin[k] = afWin[4];
Expand Down Expand Up @@ -373,7 +374,7 @@ static CPLErr GDALGeneric3x3Processing(
{
eReadDT = GDT_Float32;
fSrcNoDataValue = static_cast<T>(dfNoDataValue);
bIsSrcNoDataNan = bSrcHasNoData && CPLIsNan(dfNoDataValue);
bIsSrcNoDataNan = bSrcHasNoData && std::isnan(dfNoDataValue);
}

int bDstHasNoData = FALSE;
Expand Down Expand Up @@ -1432,7 +1433,8 @@ static int GDALColorReliefSortColors(const ColorAssociation &pA,
const ColorAssociation &pB)
{
/* Sort NaN in first position */
return (CPLIsNan(pA.dfVal) && !CPLIsNan(pB.dfVal)) || pA.dfVal < pB.dfVal;
return (std::isnan(pA.dfVal) && !std::isnan(pB.dfVal)) ||
pA.dfVal < pB.dfVal;
}

static void
Expand Down Expand Up @@ -1549,9 +1551,9 @@ GDALColorReliefGetRGBA(const std::vector<ColorAssociation> &asColorAssociation,
size_t lower = 0;

// Special case for NaN
if (CPLIsNan(asColorAssociation[0].dfVal))
if (std::isnan(asColorAssociation[0].dfVal))
{
if (CPLIsNan(dfVal))
if (std::isnan(dfVal))
{
*pnR = asColorAssociation[0].nR;
*pnG = asColorAssociation[0].nG;
Expand Down Expand Up @@ -1678,7 +1680,7 @@ GDALColorReliefGetRGBA(const std::vector<ColorAssociation> &asColorAssociation,
return true;
}

if (CPLIsNan(asColorAssociation[i - 1].dfVal))
if (std::isnan(asColorAssociation[i - 1].dfVal))
{
*pnR = asColorAssociation[i].nR;
*pnG = asColorAssociation[i].nG;
Expand Down Expand Up @@ -2758,7 +2760,7 @@ GDALGeneric3x3RasterBand<T>::GDALGeneric3x3RasterBand(
{
eReadDT = GDT_Float32;
fSrcNoDataValue = static_cast<T>(dfNoDataValue);
bIsSrcNoDataNan = bSrcHasNoData && CPLIsNan(dfNoDataValue);
bIsSrcNoDataNan = bSrcHasNoData && std::isnan(dfNoDataValue);
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/gdalinfo_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ char *GDALInfo(GDALDatasetH hDataset, const GDALInfoOptions *psOptions)
json_object_object_add(poBand, "noDataValue",
poNoDataValue);
}
else if (CPLIsNan(dfNoData))
else if (std::isnan(dfNoData))
{
Concat(osStr, psOptions->bStdoutOutput,
" NoData Value=nan\n");
Expand Down
1 change: 1 addition & 0 deletions apps/gdallocationinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "ogr_spatialref.h"
#include "gdalargumentparser.h"

#include <cmath>
#include <limits>
#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion apps/gdalwarp_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1987,7 +1987,7 @@ static void SetupNoData(const char *pszDest, int iSrc, GDALDatasetH hSrcDS,
{
if (!psOptions->bQuiet)
{
if (CPLIsNan(dfReal))
if (std::isnan(dfReal))
printf("Using internal nodata values (e.g. nan) for image "
"%s.\n",
GDALGetDescription(hSrcDS));
Expand Down
1 change: 1 addition & 0 deletions apps/ogrinfo_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "commonutils.h"
#include "gdalargumentparser.h"

#include <cmath>
#include <set>

/*! output format */
Expand Down
1 change: 1 addition & 0 deletions autotest/cpp/test_ogr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include <string>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <limits>

Expand Down
8 changes: 4 additions & 4 deletions frmts/aaigrid/aaigriddataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ float DoubleToFloatClamp(double dfValue)
// to be needed for other formats.
double MapNoDataToFloat(double dfNoDataValue)
{
if (CPLIsInf(dfNoDataValue) || CPLIsNan(dfNoDataValue))
if (std::isinf(dfNoDataValue) || std::isnan(dfNoDataValue))
return dfNoDataValue;

if (dfNoDataValue >= std::numeric_limits<float>::max())
Expand Down Expand Up @@ -611,7 +611,7 @@ int AAIGDataset::ParseHeader(const char *pszHeader, const char *pszDataType)
dfNoDataValue > std::numeric_limits<int>::max()))
{
eDataType = GDT_Float32;
if (!CPLIsInf(dfNoDataValue) &&
if (!std::isinf(dfNoDataValue) &&
(fabs(dfNoDataValue) < std::numeric_limits<float>::min() ||
fabs(dfNoDataValue) > std::numeric_limits<float>::max()))
{
Expand Down Expand Up @@ -1523,8 +1523,8 @@ GDALDataset *AAIGDataset::CreateCopy(const char *pszFilename,
{
bHasOutputDecimalDot = true;
}
else if (!CPLIsInf(padfScanline[iPixel]) &&
!CPLIsNan(padfScanline[iPixel]))
else if (!std::isinf(padfScanline[iPixel]) &&
!std::isnan(padfScanline[iPixel]))
{
strcat(szHeader, ".0");
bHasOutputDecimalDot = true;
Expand Down
2 changes: 2 additions & 0 deletions frmts/ecw/ecwdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

#include "ecwdrivercore.h"

#include <cmath>

#undef NOISY_DEBUG

static CPLMutex *hECWDatasetMutex = nullptr;
Expand Down
3 changes: 2 additions & 1 deletion frmts/grib/degrib/degrib/degrib1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <stdlib.h>
#include <math.h>

#include <cmath>
#include <limits>

#include "degrib2.h"
Expand Down Expand Up @@ -1680,7 +1681,7 @@ static int ReadGrib1Sect4 (uChar *bds, uInt4 gribLen, uInt4 *curLoc,
meta->gridAttrib.max = meta->gridAttrib.min;
meta->gridAttrib.f_maxmin = 1;
meta->gridAttrib.numMiss = 0;
if (refVal >= std::numeric_limits<float>::max() || CPLIsNan(refVal)) {
if (refVal >= std::numeric_limits<float>::max() || std::isnan(refVal)) {
meta->gridAttrib.refVal = std::numeric_limits<float>::max();
} else if (refVal <= -std::numeric_limits<float>::max()) {
meta->gridAttrib.refVal = -std::numeric_limits<float>::max();
Expand Down
2 changes: 1 addition & 1 deletion frmts/grib/degrib/degrib/grib2api.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extern const struct drstemplate templatesdrs[MAXDRSTEMP];
static sInt4 FloatToSInt4Clamp(float val) {
if ((double)val >= (double)INT_MAX) return INT_MAX;
if ((double)val <= (double)INT_MIN) return INT_MIN;
if (CPLIsNan(val)) return 0;
if (val != val) return 0;
return (sInt4)val;
}

Expand Down
3 changes: 2 additions & 1 deletion frmts/grib/degrib/degrib/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <math.h>

#include <algorithm>
#include <cmath>
#include <limits>

#include "clock.h"
Expand All @@ -44,7 +45,7 @@
static sInt4 DoubleToSInt4Clamp(double val) {
if (val >= INT_MAX) return INT_MAX;
if (val <= INT_MIN) return INT_MIN;
if (CPLIsNan(val)) return 0;
if (std::isnan(val)) return 0;
return (sInt4)val;
}

Expand Down
4 changes: 3 additions & 1 deletion frmts/grib/degrib/degrib/metaname.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "cpl_port.h"
#include "cpl_csv.h"

#include <cmath>

static const char* GetGRIB2_CSVFilename(const char* pszFilename)
{
const char* pszGribTableDirectory = CPLGetConfigOption("GRIB_RESOURCE_DIR", nullptr);
Expand Down Expand Up @@ -427,7 +429,7 @@ static void ElemNameProb (uChar mstrVersion, uShort2 center, uShort2 subcenter,
if (upperProb > tmp ||
tmp > std::numeric_limits<int>::max() ||
tmp < std::numeric_limits<int>::min() ||
CPLIsNan(tmp) ) {
std::isnan(tmp) ) {
// TODO(schwehr): What is the correct response?
errSprintf ("ERROR: upperProb out of range. Setting to 0.\n");
upperProb = 0.0;
Expand Down
3 changes: 2 additions & 1 deletion frmts/grib/gribcreatecopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "memdataset.h"

#include <algorithm>
#include <cmath>
#include <limits>

#include "degrib/degrib/meta.h"
Expand Down Expand Up @@ -970,7 +971,7 @@ float *GRIB2Section567Writer::GetFloatData()
bHasNoDataValuePoint = true;
continue;
}
if (!CPLIsFinite(pafData[i]))
if (!std::isfinite(pafData[i]))
{
CPLError(CE_Failure, CPLE_NotSupported,
"Non-finite values not supported for "
Expand Down
3 changes: 2 additions & 1 deletion frmts/gtiff/geotiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "tif_jxl.h"
#include "xtiffio.h"
#include <cctype>
#include <cmath>

// Needed to expose WEBP_LOSSLESS option
#ifdef WEBP_SUPPORT
Expand Down Expand Up @@ -580,7 +581,7 @@ char **GTiffDatasetReadRPCTag(TIFF *hTIFF)
CPLString GTiffFormatGDALNoDataTagValue(double dfNoData)
{
CPLString osVal;
if (CPLIsNan(dfNoData))
if (std::isnan(dfNoData))
osVal = "nan";
else
osVal.Printf("%.18g", dfNoData);
Expand Down
Loading
Loading