diff --git a/alg/gdalapplyverticalshiftgrid.cpp b/alg/gdalapplyverticalshiftgrid.cpp index 8b46fd3818b7..74c99fb12314 100644 --- a/alg/gdalapplyverticalshiftgrid.cpp +++ b/alg/gdalapplyverticalshiftgrid.cpp @@ -38,6 +38,7 @@ #include "proj.h" +#include #include /************************************************************************/ @@ -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)", diff --git a/alg/gdalwarper.cpp b/alg/gdalwarper.cpp index 129e8d54a855..b2f8a2495856 100644 --- a/alg/gdalwarper.cpp +++ b/alg/gdalwarper.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include "cpl_conv.h" @@ -397,7 +398,7 @@ CPLErr GDALWarpNoDataMasker(void *pMaskFuncArg, int nBandCount, { const float fNoData = static_cast(padfNoData[0]); const float *pafData = reinterpret_cast(*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) @@ -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; @@ -425,7 +426,7 @@ CPLErr GDALWarpNoDataMasker(void *pMaskFuncArg, int nBandCount, { const double dfNoData = padfNoData[0]; const double *padfData = reinterpret_cast(*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) @@ -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; @@ -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(CPLMalloc(nXSize * sizeof(double) * 2)); @@ -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])))) { @@ -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( @@ -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( diff --git a/alg/gdalwarpkernel.cpp b/alg/gdalwarpkernel.cpp index 747216c76ee5..2c046b67f055 100644 --- a/alg/gdalwarpkernel.cpp +++ b/alg/gdalwarpkernel.cpp @@ -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) diff --git a/alg/gdalwarpoperation.cpp b/alg/gdalwarpoperation.cpp index bd26ba86a78d..16dbc0a202d5 100644 --- a/alg/gdalwarpoperation.cpp +++ b/alg/gdalwarpoperation.cpp @@ -756,12 +756,12 @@ void *GDALWarpOperation::CreateDestinationBuffer(int nDstXSize, int nDstYSize, 0, std::min(255, static_cast(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, @@ -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) diff --git a/alg/marching_squares/square.h b/alg/marching_squares/square.h index caf1698fdf05..68dab5b5ddff 100644 --- a/alg/marching_squares/square.h +++ b/alg/marching_squares/square.h @@ -30,6 +30,7 @@ #include #include +#include #include #include #include "utility.h" diff --git a/apps/gdaldem_lib.cpp b/apps/gdaldem_lib.cpp index c4f3284a000e..6d9ef904c02a 100644 --- a/apps/gdaldem_lib.cpp +++ b/apps/gdaldem_lib.cpp @@ -110,6 +110,7 @@ #endif #include +#include #include #include "cpl_error.h" @@ -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; } @@ -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]; @@ -373,7 +374,7 @@ static CPLErr GDALGeneric3x3Processing( { eReadDT = GDT_Float32; fSrcNoDataValue = static_cast(dfNoDataValue); - bIsSrcNoDataNan = bSrcHasNoData && CPLIsNan(dfNoDataValue); + bIsSrcNoDataNan = bSrcHasNoData && std::isnan(dfNoDataValue); } int bDstHasNoData = FALSE; @@ -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 @@ -1549,9 +1551,9 @@ GDALColorReliefGetRGBA(const std::vector &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; @@ -1678,7 +1680,7 @@ GDALColorReliefGetRGBA(const std::vector &asColorAssociation, return true; } - if (CPLIsNan(asColorAssociation[i - 1].dfVal)) + if (std::isnan(asColorAssociation[i - 1].dfVal)) { *pnR = asColorAssociation[i].nR; *pnG = asColorAssociation[i].nG; @@ -2758,7 +2760,7 @@ GDALGeneric3x3RasterBand::GDALGeneric3x3RasterBand( { eReadDT = GDT_Float32; fSrcNoDataValue = static_cast(dfNoDataValue); - bIsSrcNoDataNan = bSrcHasNoData && CPLIsNan(dfNoDataValue); + bIsSrcNoDataNan = bSrcHasNoData && std::isnan(dfNoDataValue); } } diff --git a/apps/gdalinfo_lib.cpp b/apps/gdalinfo_lib.cpp index 4b9a346ef65a..293bdbbf66d2 100644 --- a/apps/gdalinfo_lib.cpp +++ b/apps/gdalinfo_lib.cpp @@ -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"); diff --git a/apps/gdallocationinfo.cpp b/apps/gdallocationinfo.cpp index 6fa81b24abb1..13613475e98d 100644 --- a/apps/gdallocationinfo.cpp +++ b/apps/gdallocationinfo.cpp @@ -36,6 +36,7 @@ #include "ogr_spatialref.h" #include "gdalargumentparser.h" +#include #include #include diff --git a/apps/gdalwarp_lib.cpp b/apps/gdalwarp_lib.cpp index b79dbf15b75f..7e43acdce3ad 100644 --- a/apps/gdalwarp_lib.cpp +++ b/apps/gdalwarp_lib.cpp @@ -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)); diff --git a/apps/ogrinfo_lib.cpp b/apps/ogrinfo_lib.cpp index 42538bc65f6b..b227370ddbb9 100644 --- a/apps/ogrinfo_lib.cpp +++ b/apps/ogrinfo_lib.cpp @@ -40,6 +40,7 @@ #include "commonutils.h" #include "gdalargumentparser.h" +#include #include /*! output format */ diff --git a/autotest/cpp/test_ogr.cpp b/autotest/cpp/test_ogr.cpp index 498ba17f627f..e75d0b6253b9 100644 --- a/autotest/cpp/test_ogr.cpp +++ b/autotest/cpp/test_ogr.cpp @@ -35,6 +35,7 @@ #include #include +#include #include #include diff --git a/frmts/aaigrid/aaigriddataset.cpp b/frmts/aaigrid/aaigriddataset.cpp index 910b77a3c8f0..3714d40c8f5d 100644 --- a/frmts/aaigrid/aaigriddataset.cpp +++ b/frmts/aaigrid/aaigriddataset.cpp @@ -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::max()) @@ -611,7 +611,7 @@ int AAIGDataset::ParseHeader(const char *pszHeader, const char *pszDataType) dfNoDataValue > std::numeric_limits::max())) { eDataType = GDT_Float32; - if (!CPLIsInf(dfNoDataValue) && + if (!std::isinf(dfNoDataValue) && (fabs(dfNoDataValue) < std::numeric_limits::min() || fabs(dfNoDataValue) > std::numeric_limits::max())) { @@ -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; diff --git a/frmts/ecw/ecwdataset.cpp b/frmts/ecw/ecwdataset.cpp index 961a927cd1c9..dd7bde5a9b1a 100644 --- a/frmts/ecw/ecwdataset.cpp +++ b/frmts/ecw/ecwdataset.cpp @@ -40,6 +40,8 @@ #include "ecwdrivercore.h" +#include + #undef NOISY_DEBUG static CPLMutex *hECWDatasetMutex = nullptr; diff --git a/frmts/grib/degrib/degrib/degrib1.cpp b/frmts/grib/degrib/degrib/degrib1.cpp index f956815b6752..59bc47d4eb08 100644 --- a/frmts/grib/degrib/degrib/degrib1.cpp +++ b/frmts/grib/degrib/degrib/degrib1.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include "degrib2.h" @@ -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::max() || CPLIsNan(refVal)) { + if (refVal >= std::numeric_limits::max() || std::isnan(refVal)) { meta->gridAttrib.refVal = std::numeric_limits::max(); } else if (refVal <= -std::numeric_limits::max()) { meta->gridAttrib.refVal = -std::numeric_limits::max(); diff --git a/frmts/grib/degrib/degrib/grib2api.c b/frmts/grib/degrib/degrib/grib2api.c index dfe37afd6439..5b9af26594e4 100644 --- a/frmts/grib/degrib/degrib/grib2api.c +++ b/frmts/grib/degrib/degrib/grib2api.c @@ -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; } diff --git a/frmts/grib/degrib/degrib/inventory.cpp b/frmts/grib/degrib/degrib/inventory.cpp index fda275e02fb3..2697b31b88a4 100644 --- a/frmts/grib/degrib/degrib/inventory.cpp +++ b/frmts/grib/degrib/degrib/inventory.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include "clock.h" @@ -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; } diff --git a/frmts/grib/degrib/degrib/metaname.cpp b/frmts/grib/degrib/degrib/metaname.cpp index a4d169ce14cb..4ab5576c7833 100644 --- a/frmts/grib/degrib/degrib/metaname.cpp +++ b/frmts/grib/degrib/degrib/metaname.cpp @@ -25,6 +25,8 @@ #include "cpl_port.h" #include "cpl_csv.h" +#include + static const char* GetGRIB2_CSVFilename(const char* pszFilename) { const char* pszGribTableDirectory = CPLGetConfigOption("GRIB_RESOURCE_DIR", nullptr); @@ -427,7 +429,7 @@ static void ElemNameProb (uChar mstrVersion, uShort2 center, uShort2 subcenter, if (upperProb > tmp || tmp > std::numeric_limits::max() || tmp < std::numeric_limits::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; diff --git a/frmts/grib/gribcreatecopy.cpp b/frmts/grib/gribcreatecopy.cpp index 763c98b7114f..20815c97d2e8 100644 --- a/frmts/grib/gribcreatecopy.cpp +++ b/frmts/grib/gribcreatecopy.cpp @@ -37,6 +37,7 @@ #include "memdataset.h" #include +#include #include #include "degrib/degrib/meta.h" @@ -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 " diff --git a/frmts/gtiff/geotiff.cpp b/frmts/gtiff/geotiff.cpp index 21406e1dc551..40fb829ad0c3 100644 --- a/frmts/gtiff/geotiff.cpp +++ b/frmts/gtiff/geotiff.cpp @@ -40,6 +40,7 @@ #include "tif_jxl.h" #include "xtiffio.h" #include +#include // Needed to expose WEBP_LOSSLESS option #ifdef WEBP_SUPPORT @@ -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); diff --git a/frmts/gtiff/gtiffdataset_write.cpp b/frmts/gtiff/gtiffdataset_write.cpp index 402368800c82..f94b36b0f0f5 100644 --- a/frmts/gtiff/gtiffdataset_write.cpp +++ b/frmts/gtiff/gtiffdataset_write.cpp @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -527,18 +528,18 @@ inline bool GTiffDataset::IsFirstPixelEqualToNoData(const void *pBuffer) } if (m_nBitsPerSample == 32 && eDT == GDT_Float32) { - if (CPLIsNan(m_dfNoDataValue)) + if (std::isnan(m_dfNoDataValue)) return CPL_TO_BOOL( - CPLIsNan(*(static_cast(pBuffer)))); + std::isnan(*(static_cast(pBuffer)))); return GDALIsValueInRange(dfEffectiveNoData) && *(static_cast(pBuffer)) == static_cast(dfEffectiveNoData); } if (m_nBitsPerSample == 64 && eDT == GDT_Float64) { - if (CPLIsNan(dfEffectiveNoData)) + if (std::isnan(dfEffectiveNoData)) return CPL_TO_BOOL( - CPLIsNan(*(static_cast(pBuffer)))); + std::isnan(*(static_cast(pBuffer)))); return *(static_cast(pBuffer)) == dfEffectiveNoData; } return false; diff --git a/frmts/gtiff/gtiffrasterband_write.cpp b/frmts/gtiff/gtiffrasterband_write.cpp index d91eddbbab4c..6c5567e3e2d5 100644 --- a/frmts/gtiff/gtiffrasterband_write.cpp +++ b/frmts/gtiff/gtiffrasterband_write.cpp @@ -31,6 +31,7 @@ #include "gtiffdataset.h" #include +#include #include #include "cpl_vsi_virtual.h" diff --git a/frmts/hdf5/bagdataset.cpp b/frmts/hdf5/bagdataset.cpp index 7fceddf017ca..b97dae94906c 100644 --- a/frmts/hdf5/bagdataset.cpp +++ b/frmts/hdf5/bagdataset.cpp @@ -47,6 +47,7 @@ #include "rat.h" #include +#include #include #include #include @@ -2248,7 +2249,7 @@ CPLErr BAGGeorefMDBandBase::IReadBlockFromElevBand(int nBlockXOff, { pbyImage[y * nBlockXSize + x] = (afData[y * nBlockXSize + x] == fNoDataValue || - CPLIsNan(afData[y * nBlockXSize + x])) + std::isnan(afData[y * nBlockXSize + x])) ? 0 : 1; } diff --git a/frmts/hdf5/s102dataset.cpp b/frmts/hdf5/s102dataset.cpp index f062d354b0e8..fb84cc49cbb1 100644 --- a/frmts/hdf5/s102dataset.cpp +++ b/frmts/hdf5/s102dataset.cpp @@ -37,6 +37,7 @@ #include "gdal_proxy.h" #include "gdal_rat.h" +#include #include /************************************************************************/ diff --git a/frmts/hf2/hf2dataset.cpp b/frmts/hf2/hf2dataset.cpp index 1a4adcd58f6a..ce683aa8fa2b 100644 --- a/frmts/hf2/hf2dataset.cpp +++ b/frmts/hf2/hf2dataset.cpp @@ -1061,7 +1061,7 @@ GDALDataset *HF2Dataset::CreateCopy(const char *pszFilename, for (int k = 1; k < nReqYSize * nReqXSize; k++) { float fVal = ((float *)pTileBuffer)[k]; - if (CPLIsNan(fVal)) + if (std::isnan(fVal)) { CPLError(CE_Failure, CPLE_NotSupported, "NaN value found"); diff --git a/frmts/hfa/hfadataset.cpp b/frmts/hfa/hfadataset.cpp index 4615d4d86366..4a5ef12a82a8 100644 --- a/frmts/hfa/hfadataset.cpp +++ b/frmts/hfa/hfadataset.cpp @@ -2058,7 +2058,7 @@ void HFARasterBand::ReadHistogramMetadata() static_cast(std::numeric_limits::max()) || dfNumber < static_cast(std::numeric_limits::min()) || - CPLIsNan(dfNumber)) + std::isnan(dfNumber)) { CPLError(CE_Failure, CPLE_FileIO, "Out of range hist vals."); CPLFree(panHistValues); diff --git a/frmts/hfa/hfafield.cpp b/frmts/hfa/hfafield.cpp index 42ab23c57524..01f560a99818 100644 --- a/frmts/hfa/hfafield.cpp +++ b/frmts/hfa/hfafield.cpp @@ -40,6 +40,7 @@ #include #endif #include +#include #include #include @@ -55,7 +56,7 @@ namespace int FloatToIntClamp(float fValue) { - if (CPLIsNan(fValue)) + if (std::isnan(fValue)) return 0; if (fValue >= static_cast(std::numeric_limits::max())) return std::numeric_limits::max(); @@ -1011,7 +1012,7 @@ bool HFAField::ExtractInstValue(const char *pszField, int nIndexValue, std::numeric_limits::max() || static_cast(fNumber) < std::numeric_limits::min() || - CPLIsNan(fNumber)) + std::isnan(fNumber)) { CPLError(CE_Failure, CPLE_AppDefined, "Too large for int: %f", fNumber); @@ -1035,7 +1036,7 @@ bool HFAField::ExtractInstValue(const char *pszField, int nIndexValue, dfDoubleRet = dfNumber; if (dfNumber > std::numeric_limits::max() || dfNumber < std::numeric_limits::min() || - CPLIsNan(dfNumber)) + std::isnan(dfNumber)) { CPLError(CE_Failure, CPLE_AppDefined, "Too large for int: %f", dfNumber); @@ -1247,7 +1248,7 @@ bool HFAField::ExtractInstValue(const char *pszField, int nIndexValue, { nIntRet = nMin; } - else if (CPLIsNan(dfDoubleRet)) + else if (std::isnan(dfDoubleRet)) { CPLError(CE_Warning, CPLE_AppDefined, "NaN converted to INT_MAX."); diff --git a/frmts/ilwis/ilwisdataset.cpp b/frmts/ilwis/ilwisdataset.cpp index c2f84f907f22..5fde2deaa05e 100644 --- a/frmts/ilwis/ilwisdataset.cpp +++ b/frmts/ilwis/ilwisdataset.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -1194,8 +1195,8 @@ GDALDataset *ILWISDataset::CreateCopy(const char *pszFilename, adfMinMax[1] = poBand->GetMaximum(&bGotMax); if (!(bGotMin && bGotMax)) GDALComputeRasterMinMax((GDALRasterBandH)poBand, FALSE, adfMinMax); - if ((!CPLIsNan(adfMinMax[0])) && CPLIsFinite(adfMinMax[0]) && - (!CPLIsNan(adfMinMax[1])) && CPLIsFinite(adfMinMax[1])) + if ((!std::isnan(adfMinMax[0])) && std::isfinite(adfMinMax[0]) && + (!std::isnan(adfMinMax[1])) && std::isfinite(adfMinMax[1])) { // only write a range if we got a correct one from the source // dataset (otherwise ILWIS can't show the map properly) @@ -1260,13 +1261,13 @@ GDALDataset *ILWISDataset::CreateCopy(const char *pszFilename, else if (EQUAL(sStoreType.c_str(), "float")) { if ((((float *)pData)[iCol] == dNoDataValue) || - (CPLIsNan(((float *)pData)[iCol]))) + (std::isnan(((float *)pData)[iCol]))) ((float *)pData)[iCol] = flUNDEF; } else if (EQUAL(sStoreType.c_str(), "Real")) { if ((((double *)pData)[iCol] == dNoDataValue) || - (CPLIsNan(((double *)pData)[iCol]))) + (std::isnan(((double *)pData)[iCol]))) ((double *)pData)[iCol] = rUNDEF; } } diff --git a/frmts/netcdf/netcdfdataset.cpp b/frmts/netcdf/netcdfdataset.cpp index 5e5ce8d0cbe4..8d3d670bb2c0 100644 --- a/frmts/netcdf/netcdfdataset.cpp +++ b/frmts/netcdf/netcdfdataset.cpp @@ -2173,7 +2173,7 @@ void netCDFRasterBand::CheckData(void *pImage, void *pImageNC, // Check for nodata and nan. if (CPLIsEqual((double)ptrImage[k], m_dfNoDataValue)) continue; - if (bCheckIsNan && CPLIsNan((double)ptrImage[k])) + if (bCheckIsNan && std::isnan((double)ptrImage[k])) { ptrImage[k] = (T)m_dfNoDataValue; continue; @@ -2258,7 +2258,7 @@ void netCDFRasterBand::CheckDataCpx(void *pImage, void *pImageNC, // Check for nodata and nan. if (CPLIsEqual((double)ptrImage[k], m_dfNoDataValue)) continue; - if (bCheckIsNan && CPLIsNan((double)ptrImage[k])) + if (bCheckIsNan && std::isnan((double)ptrImage[k])) { ptrImage[k] = (T)m_dfNoDataValue; continue; diff --git a/frmts/nitf/rpftocfile.cpp b/frmts/nitf/rpftocfile.cpp index 4abe10da8588..34736a558097 100644 --- a/frmts/nitf/rpftocfile.cpp +++ b/frmts/nitf/rpftocfile.cpp @@ -47,6 +47,7 @@ #include "rpftoclib.h" #include +#include #include #if HAVE_FCNTL_H #include @@ -320,9 +321,9 @@ RPFToc *RPFTOCReadFromBuffer(const char *pszFilename, VSILFILE *fp, // do some basic plausibility checks for all entries if (toc->entries[i].vertInterval <= 1e-10 || - !CPLIsFinite(toc->entries[i].vertInterval) || + !std::isfinite(toc->entries[i].vertInterval) || toc->entries[i].horizInterval <= 1e-10 || - !CPLIsFinite(toc->entries[i].horizInterval) || + !std::isfinite(toc->entries[i].horizInterval) || toc->entries[i].nHorizFrames == 0 || toc->entries[i].nVertFrames == 0 || toc->entries[i].nHorizFrames > diff --git a/frmts/pdf/pdfwritabledataset.cpp b/frmts/pdf/pdfwritabledataset.cpp index 6c9ec9cff973..0c355dd44e02 100644 --- a/frmts/pdf/pdfwritabledataset.cpp +++ b/frmts/pdf/pdfwritabledataset.cpp @@ -31,6 +31,8 @@ #include "memdataset.h" #include "pdfcreatefromcomposition.h" +#include + /************************************************************************/ /* PDFWritableVectorDataset() */ /************************************************************************/ @@ -203,7 +205,7 @@ OGRErr PDFWritableVectorDataset::SyncToDisk() { nWidth = 1024; const double dfHeight = nWidth * dfRatio; - if (dfHeight < 1 || dfHeight > INT_MAX || CPLIsNan(dfHeight)) + if (dfHeight < 1 || dfHeight > INT_MAX || std::isnan(dfHeight)) { CPLError(CE_Failure, CPLE_AppDefined, "Invalid image dimensions"); return OGRERR_FAILURE; @@ -214,7 +216,7 @@ OGRErr PDFWritableVectorDataset::SyncToDisk() { nHeight = 1024; const double dfWidth = nHeight / dfRatio; - if (dfWidth < 1 || dfWidth > INT_MAX || CPLIsNan(dfWidth)) + if (dfWidth < 1 || dfWidth > INT_MAX || std::isnan(dfWidth)) { CPLError(CE_Failure, CPLE_AppDefined, "Invalid image dimensions"); return OGRERR_FAILURE; diff --git a/frmts/raw/doq1dataset.cpp b/frmts/raw/doq1dataset.cpp index ad6a2bbecf6b..edae98a6eed3 100644 --- a/frmts/raw/doq1dataset.cpp +++ b/frmts/raw/doq1dataset.cpp @@ -32,6 +32,7 @@ #include "rawdataset.h" #include +#include #ifndef UTM_FORMAT_defined #define UTM_FORMAT_defined @@ -231,10 +232,10 @@ GDALDataset *DOQ1Dataset::Open(GDALOpenInfo *poOpenInfo) /* Do these values look coherent for a DOQ file? It would be */ /* nice to do a more comprehensive test than this! */ /* -------------------------------------------------------------------- */ - if (dfWidth < 500 || dfWidth > 25000 || CPLIsNan(dfWidth) || - dfHeight < 500 || dfHeight > 25000 || CPLIsNan(dfHeight) || - dfBandStorage < 0 || dfBandStorage > 4 || CPLIsNan(dfBandStorage) || - dfBandTypes < 1 || dfBandTypes > 9 || CPLIsNan(dfBandTypes)) + if (dfWidth < 500 || dfWidth > 25000 || std::isnan(dfWidth) || + dfHeight < 500 || dfHeight > 25000 || std::isnan(dfHeight) || + dfBandStorage < 0 || dfBandStorage > 4 || std::isnan(dfBandStorage) || + dfBandTypes < 1 || dfBandTypes > 9 || std::isnan(dfBandTypes)) return nullptr; const int nWidth = static_cast(dfWidth); diff --git a/frmts/raw/rrasterdataset.cpp b/frmts/raw/rrasterdataset.cpp index 778799aa857b..807abc172b77 100644 --- a/frmts/raw/rrasterdataset.cpp +++ b/frmts/raw/rrasterdataset.cpp @@ -36,6 +36,7 @@ #include "ogr_spatialref.h" #include +#include #include #include @@ -330,7 +331,7 @@ static void GetMinMax(const T *buffer, int nBufXSize, int nBufYSize, for (int iX = 0; iX < nBufXSize; iX++) { const double dfVal = buffer[iY * nLineSpace + iX * nPixelSpace]; - if (dfVal != dfNoDataValue && !CPLIsNan(dfVal)) + if (dfVal != dfNoDataValue && !std::isnan(dfVal)) { dfMin = std::min(dfMin, dfVal); dfMax = std::max(dfMax, dfVal); @@ -1025,7 +1026,7 @@ bool RRASTERDataset::ComputeSpacings(const CPLString &osBandOrder, int nCols, static float CastToFloat(double dfVal) { - if (CPLIsInf(dfVal) || CPLIsNan(dfVal) || + if (std::isinf(dfVal) || std::isnan(dfVal) || (dfVal >= -std::numeric_limits::max() && dfVal <= std::numeric_limits::max())) { diff --git a/frmts/rik/rikdataset.cpp b/frmts/rik/rikdataset.cpp index f669e972f2d3..5bb81ce60680 100644 --- a/frmts/rik/rikdataset.cpp +++ b/frmts/rik/rikdataset.cpp @@ -32,6 +32,8 @@ #include "gdal_frmts.h" #include "gdal_pam.h" +#include + #define RIK_HEADER_DEBUG 0 #define RIK_CLEAR_DEBUG 0 #define RIK_PIXEL_DEBUG 0 @@ -901,8 +903,8 @@ GDALDataset *RIKDataset::Open(GDALOpenInfo *poOpenInfo) CPL_SWAP32PTR(&header.iMPPNum); #endif - if (!CPLIsFinite(header.fSouth) || !CPLIsFinite(header.fWest) || - !CPLIsFinite(header.fNorth) || !CPLIsFinite(header.fEast) || + if (!std::isfinite(header.fSouth) || !std::isfinite(header.fWest) || + !std::isfinite(header.fNorth) || !std::isfinite(header.fEast) || header.iMPPNum == 0) { return nullptr; diff --git a/frmts/tiledb/tiledbdense.cpp b/frmts/tiledb/tiledbdense.cpp index 9cd92f0e22e1..93218b6cdb80 100644 --- a/frmts/tiledb/tiledbdense.cpp +++ b/frmts/tiledb/tiledbdense.cpp @@ -27,6 +27,7 @@ ****************************************************************************/ #include +#include #include #include diff --git a/frmts/usgsdem/usgsdemdataset.cpp b/frmts/usgsdem/usgsdemdataset.cpp index 0638bb2a4895..ff3b2cd5560e 100644 --- a/frmts/usgsdem/usgsdemdataset.cpp +++ b/frmts/usgsdem/usgsdemdataset.cpp @@ -35,6 +35,7 @@ #include "ogr_spatialref.h" #include +#include typedef struct { @@ -452,7 +453,7 @@ CPLErr USGSDEMRasterBand::IReadBlock(CPL_UNUSED int nBlockXOff, dyStart = dyStart / 3600.0; double dygap = (dfYMin - dyStart) / poGDS->adfGeoTransform[5] + 0.5; - if (dygap <= INT_MIN || dygap >= INT_MAX || !CPLIsFinite(dygap)) + if (dygap <= INT_MIN || dygap >= INT_MAX || !std::isfinite(dygap)) { CPLFree(sBuffer.buffer); return CE_Failure; diff --git a/frmts/vrt/gdaltileindexdataset.cpp b/frmts/vrt/gdaltileindexdataset.cpp index b33ea497a488..03991a53b1a4 100644 --- a/frmts/vrt/gdaltileindexdataset.cpp +++ b/frmts/vrt/gdaltileindexdataset.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/frmts/vrt/vrtrasterband.cpp b/frmts/vrt/vrtrasterband.cpp index af3b14ef6d23..ff0f8c300aa8 100644 --- a/frmts/vrt/vrtrasterband.cpp +++ b/frmts/vrt/vrtrasterband.cpp @@ -30,6 +30,7 @@ #include "cpl_port.h" #include "vrtdataset.h" +#include #include #include #include @@ -616,7 +617,7 @@ CPLErr VRTRasterBand::XMLInit(const CPLXMLNode *psTree, const char *pszVRTPath, CPLString VRTSerializeNoData(double dfVal, GDALDataType eDataType, int nPrecision) { - if (CPLIsNan(dfVal)) + if (std::isnan(dfVal)) { return "nan"; } diff --git a/frmts/vrt/vrtsources.cpp b/frmts/vrt/vrtsources.cpp index 80604ec5e42e..0eb3e2793a85 100644 --- a/frmts/vrt/vrtsources.cpp +++ b/frmts/vrt/vrtsources.cpp @@ -994,8 +994,8 @@ int VRTSimpleSource::GetSrcDstWindow( *pdfReqXSize = dfRXSize * dfScaleX; *pdfReqYSize = dfRYSize * dfScaleY; - if (!CPLIsFinite(*pdfReqXOff) || !CPLIsFinite(*pdfReqYOff) || - !CPLIsFinite(*pdfReqXSize) || !CPLIsFinite(*pdfReqYSize) || + if (!std::isfinite(*pdfReqXOff) || !std::isfinite(*pdfReqYOff) || + !std::isfinite(*pdfReqXSize) || !std::isfinite(*pdfReqYSize) || *pdfReqXOff > INT_MAX || *pdfReqYOff > INT_MAX || *pdfReqXSize < 0 || *pdfReqYSize < 0) { @@ -1938,7 +1938,7 @@ CPLErr VRTAveragedSource::RasterIO(GDALDataType /*eVRTBandDataType*/, int nXOff, const float fSampledValue = pafSrc[iX + static_cast(iY) * nReqXSize]; - if (CPLIsNan(fSampledValue)) + if (std::isnan(fSampledValue)) continue; if (m_bNoDataSet && @@ -3295,9 +3295,9 @@ CPLErr VRTComplexSource::RasterIOInternal( dfNoDataValue = poSourceBand->GetNoDataValue(&bNoDataSet); } - const bool bNoDataSetIsNan = bNoDataSet && CPLIsNan(dfNoDataValue); + const bool bNoDataSetIsNan = bNoDataSet && std::isnan(dfNoDataValue); const bool bNoDataSetAndNotNan = - bNoDataSet && !CPLIsNan(dfNoDataValue) && + bNoDataSet && !std::isnan(dfNoDataValue) && GDALIsValueInRange(dfNoDataValue); const auto fWorkingDataTypeNoData = static_cast(dfNoDataValue); @@ -3425,7 +3425,7 @@ CPLErr VRTComplexSource::RasterIOInternal( if (pafData && !bIsComplex) { WorkingDT fResult = pafData[idxBuffer]; - if (bNoDataSetIsNan && CPLIsNan(fResult)) + if (bNoDataSetIsNan && std::isnan(fResult)) continue; if (bNoDataSetAndNotNan && ARE_REAL_EQUAL(fResult, fWorkingDataTypeNoData)) diff --git a/frmts/zarr/zarr_array.cpp b/frmts/zarr/zarr_array.cpp index afb2da159046..2e187345332f 100644 --- a/frmts/zarr/zarr_array.cpp +++ b/frmts/zarr/zarr_array.cpp @@ -35,6 +35,7 @@ #include #include +#include #include #include #include diff --git a/frmts/zarr/zarr_v3_array.cpp b/frmts/zarr/zarr_v3_array.cpp index 442c3ec58957..d1ca0d2632c7 100644 --- a/frmts/zarr/zarr_v3_array.cpp +++ b/frmts/zarr/zarr_v3_array.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include diff --git a/gcore/gdal_misc.cpp b/gcore/gdal_misc.cpp index 00d1496ae724..af3d01d6e96b 100644 --- a/gcore/gdal_misc.cpp +++ b/gcore/gdal_misc.cpp @@ -826,7 +826,7 @@ double GDALAdjustValueToDataType(GDALDataType eDT, double dfValue, break; case GDT_Float32: { - if (!CPLIsFinite(dfValue)) + if (!std::isfinite(dfValue)) break; // TODO(schwehr): ::min() versus ::lowest. diff --git a/gcore/gdal_priv_templates.hpp b/gcore/gdal_priv_templates.hpp index dd41417855a3..0b7bd7f72482 100644 --- a/gcore/gdal_priv_templates.hpp +++ b/gcore/gdal_priv_templates.hpp @@ -149,12 +149,12 @@ template inline bool GDALIsValueInRange(double dfValue) template <> inline bool GDALIsValueInRange(double dfValue) { - return !CPLIsNan(dfValue); + return !std::isnan(dfValue); } template <> inline bool GDALIsValueInRange(double dfValue) { - return CPLIsInf(dfValue) || + return std::isinf(dfValue) || (dfValue >= -std::numeric_limits::max() && dfValue <= std::numeric_limits::max()); } @@ -288,7 +288,7 @@ template struct sGDALCopyWord { static inline void f(const float fValueIn, Tout &tValueOut) { - if (CPLIsNan(fValueIn)) + if (std::isnan(fValueIn)) { tValueOut = 0; return; @@ -304,7 +304,7 @@ template <> struct sGDALCopyWord { static inline void f(const float fValueIn, short &nValueOut) { - if (CPLIsNan(fValueIn)) + if (std::isnan(fValueIn)) { nValueOut = 0; return; @@ -321,7 +321,7 @@ template <> struct sGDALCopyWord { static inline void f(const float fValueIn, signed char &nValueOut) { - if (CPLIsNan(fValueIn)) + if (std::isnan(fValueIn)) { nValueOut = 0; return; @@ -338,7 +338,7 @@ template struct sGDALCopyWord { static inline void f(const double dfValueIn, Tout &tValueOut) { - if (CPLIsNan(dfValueIn)) + if (std::isnan(dfValueIn)) { tValueOut = 0; return; @@ -354,7 +354,7 @@ template <> struct sGDALCopyWord { static inline void f(const double dfValueIn, int &nValueOut) { - if (CPLIsNan(dfValueIn)) + if (std::isnan(dfValueIn)) { nValueOut = 0; return; @@ -417,7 +417,7 @@ template <> struct sGDALCopyWord { static inline void f(const double dfValueIn, short &nValueOut) { - if (CPLIsNan(dfValueIn)) + if (std::isnan(dfValueIn)) { nValueOut = 0; return; @@ -434,7 +434,7 @@ template <> struct sGDALCopyWord { static inline void f(const double dfValueIn, signed char &nValueOut) { - if (CPLIsNan(dfValueIn)) + if (std::isnan(dfValueIn)) { nValueOut = 0; return; diff --git a/gcore/gdalexif.cpp b/gcore/gdalexif.cpp index 780333c2cdbf..409366fb24c3 100644 --- a/gcore/gdalexif.cpp +++ b/gcore/gdalexif.cpp @@ -35,6 +35,7 @@ #include "gdalexif.h" #include +#include #include #include #include @@ -1016,7 +1017,7 @@ static bool GetNumDenomFromDouble(GDALEXIFTIFFDataType datatype, double dfVal, { nNum = 0; nDenom = 1; - if (CPLIsNan(dfVal)) + if (std::isnan(dfVal)) { return false; } diff --git a/gcore/gdalmultidim.cpp b/gcore/gdalmultidim.cpp index 6d3d550bf2c1..86beb490871a 100644 --- a/gcore/gdalmultidim.cpp +++ b/gcore/gdalmultidim.cpp @@ -36,6 +36,7 @@ #include #include +#include #include // isalnum #include "cpl_error_internal.h" diff --git a/gcore/gdalnodatamaskband.cpp b/gcore/gdalnodatamaskband.cpp index cb2e5eb10c17..cd3b121acbbd 100644 --- a/gcore/gdalnodatamaskband.cpp +++ b/gcore/gdalnodatamaskband.cpp @@ -32,6 +32,7 @@ #include "gdal_priv.h" #include +#include #include #include @@ -200,7 +201,7 @@ bool GDALNoDataMaskBand::IsNoDataInRange(double dfNoDataValue, case GDT_Float32: { - return CPLIsNan(dfNoDataValue) || CPLIsInf(dfNoDataValue) || + return std::isnan(dfNoDataValue) || std::isinf(dfNoDataValue) || GDALIsValueInRange(dfNoDataValue); } @@ -417,7 +418,7 @@ CPLErr GDALNoDataMaskBand::IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, return eErr; } - const bool bIsNoDataNan = CPLIsNan(m_dfNoDataValue) != 0; + const bool bIsNoDataNan = std::isnan(m_dfNoDataValue) != 0; GByte *pabyDest = static_cast(pData); /* -------------------------------------------------------------------- @@ -475,7 +476,7 @@ CPLErr GDALNoDataMaskBand::IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, for (int iX = 0; iX < nBufXSize; iX++) { const float fVal = pafSrc[i]; - if (bIsNoDataNan && CPLIsNan(fVal)) + if (bIsNoDataNan && std::isnan(fVal)) *pabyLineDest = 0; else if (ARE_REAL_EQUAL(fVal, fNoData)) *pabyLineDest = 0; @@ -499,7 +500,7 @@ CPLErr GDALNoDataMaskBand::IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, for (int iX = 0; iX < nBufXSize; iX++) { const double dfVal = padfSrc[i]; - if (bIsNoDataNan && CPLIsNan(dfVal)) + if (bIsNoDataNan && std::isnan(dfVal)) *pabyLineDest = 0; else if (ARE_REAL_EQUAL(dfVal, m_dfNoDataValue)) *pabyLineDest = 0; diff --git a/gcore/gdalpamrasterband.cpp b/gcore/gdalpamrasterband.cpp index b168ee81f319..670a4d3b38a4 100644 --- a/gcore/gdalpamrasterband.cpp +++ b/gcore/gdalpamrasterband.cpp @@ -111,7 +111,7 @@ CPLXMLNode *GDALPamRasterBand::SerializeToXML(const char * /* pszUnused */) if (psPam->bNoDataValueSet) { - if (CPLIsNan(psPam->dfNoDataValue)) + if (std::isnan(psPam->dfNoDataValue)) CPLSetXMLValue(psTree, "NoDataValue", "nan"); else CPLSetXMLValue(psTree, "NoDataValue", diff --git a/gcore/gdalrasterband.cpp b/gcore/gdalrasterband.cpp index e91968be8826..c9dbcec41059 100644 --- a/gcore/gdalrasterband.cpp +++ b/gcore/gdalrasterband.cpp @@ -3978,7 +3978,7 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets, int bGotNoDataValue = FALSE; const double dfNoDataValue = GetNoDataValue(&bGotNoDataValue); - bGotNoDataValue = bGotNoDataValue && !CPLIsNan(dfNoDataValue); + bGotNoDataValue = bGotNoDataValue && !std::isnan(dfNoDataValue); bool bGotFloatNoDataValue = false; float fNoDataValue = 0.0f; ComputeFloatNoDataValue(eDataType, dfNoDataValue, bGotNoDataValue, @@ -4115,7 +4115,7 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets, { const float fValue = static_cast(pData)[iOffset]; - if (CPLIsNan(fValue) || + if (std::isnan(fValue) || (bGotFloatNoDataValue && ARE_REAL_EQUAL(fValue, fNoDataValue))) continue; @@ -4124,7 +4124,7 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets, } case GDT_Float64: dfValue = static_cast(pData)[iOffset]; - if (CPLIsNan(dfValue)) + if (std::isnan(dfValue)) continue; break; case GDT_CInt16: @@ -4133,7 +4133,7 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets, static_cast(pData)[iOffset * 2]; const double dfImag = static_cast(pData)[iOffset * 2 + 1]; - if (CPLIsNan(dfReal) || CPLIsNan(dfImag)) + if (std::isnan(dfReal) || std::isnan(dfImag)) continue; dfValue = sqrt(dfReal * dfReal + dfImag * dfImag); } @@ -4144,7 +4144,7 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets, static_cast(pData)[iOffset * 2]; const double dfImag = static_cast(pData)[iOffset * 2 + 1]; - if (CPLIsNan(dfReal) || CPLIsNan(dfImag)) + if (std::isnan(dfReal) || std::isnan(dfImag)) continue; dfValue = sqrt(dfReal * dfReal + dfImag * dfImag); } @@ -4155,7 +4155,7 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets, static_cast(pData)[iOffset * 2]; const double dfImag = static_cast(pData)[iOffset * 2 + 1]; - if (CPLIsNan(dfReal) || CPLIsNan(dfImag)) + if (std::isnan(dfReal) || std::isnan(dfImag)) continue; dfValue = sqrt(dfReal * dfReal + dfImag * dfImag); } @@ -4166,7 +4166,7 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets, static_cast(pData)[iOffset * 2]; const double dfImag = static_cast(pData)[iOffset * 2 + 1]; - if (CPLIsNan(dfReal) || CPLIsNan(dfImag)) + if (std::isnan(dfReal) || std::isnan(dfImag)) continue; dfValue = sqrt(dfReal * dfReal + dfImag * dfImag); } @@ -4360,7 +4360,7 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets, { const float fValue = static_cast(pData)[iOffset]; - if (CPLIsNan(fValue) || + if (std::isnan(fValue) || (bGotFloatNoDataValue && ARE_REAL_EQUAL(fValue, fNoDataValue))) continue; @@ -4369,7 +4369,7 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets, } case GDT_Float64: dfValue = static_cast(pData)[iOffset]; - if (CPLIsNan(dfValue)) + if (std::isnan(dfValue)) continue; break; case GDT_CInt16: @@ -4396,7 +4396,7 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets, static_cast(pData)[iOffset * 2]; double dfImag = static_cast(pData)[iOffset * 2 + 1]; - if (CPLIsNan(dfReal) || CPLIsNan(dfImag)) + if (std::isnan(dfReal) || std::isnan(dfImag)) continue; dfValue = sqrt(dfReal * dfReal + dfImag * dfImag); } @@ -4407,7 +4407,7 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets, static_cast(pData)[iOffset * 2]; double dfImag = static_cast(pData)[iOffset * 2 + 1]; - if (CPLIsNan(dfReal) || CPLIsNan(dfImag)) + if (std::isnan(dfReal) || std::isnan(dfImag)) continue; dfValue = sqrt(dfReal * dfReal + dfImag * dfImag); } @@ -6052,7 +6052,7 @@ static inline double GetPixelValue(GDALDataType eDataType, bool bSignedByte, case GDT_Float32: { const float fValue = static_cast(pData)[iOffset]; - if (CPLIsNan(fValue) || + if (std::isnan(fValue) || (bGotFloatNoDataValue && ARE_REAL_EQUAL(fValue, fNoDataValue))) { bValid = false; @@ -6063,7 +6063,7 @@ static inline double GetPixelValue(GDALDataType eDataType, bool bSignedByte, } case GDT_Float64: dfValue = static_cast(pData)[iOffset]; - if (CPLIsNan(dfValue)) + if (std::isnan(dfValue)) { bValid = false; return 0.0; @@ -6077,7 +6077,7 @@ static inline double GetPixelValue(GDALDataType eDataType, bool bSignedByte, break; case GDT_CFloat32: dfValue = static_cast(pData)[iOffset * 2]; - if (CPLIsNan(dfValue)) + if (std::isnan(dfValue)) { bValid = false; return 0.0; @@ -6085,7 +6085,7 @@ static inline double GetPixelValue(GDALDataType eDataType, bool bSignedByte, break; case GDT_CFloat64: dfValue = static_cast(pData)[iOffset * 2]; - if (CPLIsNan(dfValue)) + if (std::isnan(dfValue)) { bValid = false; return 0.0; @@ -6264,7 +6264,7 @@ CPLErr GDALRasterBand::ComputeStatistics(int bApproxOK, double *pdfMin, int bGotNoDataValue = FALSE; const double dfNoDataValue = GetNoDataValue(&bGotNoDataValue); - bGotNoDataValue = bGotNoDataValue && !CPLIsNan(dfNoDataValue); + bGotNoDataValue = bGotNoDataValue && !std::isnan(dfNoDataValue); bool bGotFloatNoDataValue = false; float fNoDataValue = 0.0f; ComputeFloatNoDataValue(eDataType, dfNoDataValue, bGotNoDataValue, @@ -7099,7 +7099,7 @@ CPLErr GDALRasterBand::ComputeRasterMinMax(int bApproxOK, double *adfMinMax) /* -------------------------------------------------------------------- */ int bGotNoDataValue = FALSE; const double dfNoDataValue = GetNoDataValue(&bGotNoDataValue); - bGotNoDataValue = bGotNoDataValue && !CPLIsNan(dfNoDataValue); + bGotNoDataValue = bGotNoDataValue && !std::isnan(dfNoDataValue); bool bGotFloatNoDataValue = false; float fNoDataValue = 0.0f; ComputeFloatNoDataValue(eDataType, dfNoDataValue, bGotNoDataValue, diff --git a/ogr/ogr_core.h b/ogr/ogr_core.h index 590be6ba6ceb..7ff3645bccc4 100644 --- a/ogr/ogr_core.h +++ b/ogr/ogr_core.h @@ -968,20 +968,8 @@ typedef union /*! @endcond */ } OGRField; -#ifdef __cplusplus /** Return the number of milliseconds from a datetime with decimal seconds */ -inline int OGR_GET_MS(float fSec) -{ - if (CPLIsNan(fSec)) - return 0; - if (fSec >= 999) - return 999; - if (fSec <= 0) - return 0; - const float fValue = (fSec - static_cast(fSec)) * 1000 + 0.5f; - return static_cast(fValue); -} -#endif // __cplusplus +int CPL_DLL OGR_GET_MS(float fSec); /** Option for OGRParseDate() to ask for lax checks on the input format */ #define OGRPARSEDATE_OPTION_LAX 1 diff --git a/ogr/ogr_srs_esri.cpp b/ogr/ogr_srs_esri.cpp index df0180b48b0b..77b1134fc60f 100644 --- a/ogr/ogr_srs_esri.cpp +++ b/ogr/ogr_srs_esri.cpp @@ -349,7 +349,7 @@ OGRErr OGRSpatialReference::importFromESRI(char **papszPrj) const double dfZone = OSR_GDV(papszPrj, "zone", 0.0); if (dfZone < std::numeric_limits::min() || - dfZone > std::numeric_limits::max() || CPLIsNan(dfZone)) + dfZone > std::numeric_limits::max() || std::isnan(dfZone)) { CPLError(CE_Failure, CPLE_AppDefined, "zone out of range: %f", dfZone); @@ -366,7 +366,7 @@ OGRErr OGRSpatialReference::importFromESRI(char **papszPrj) if (dfFipszone < std::numeric_limits::min() || dfFipszone > std::numeric_limits::max() || - CPLIsNan(dfFipszone)) + std::isnan(dfFipszone)) { CPLError(CE_Failure, CPLE_AppDefined, "fipszone out of range: %f", dfFipszone); @@ -468,7 +468,7 @@ OGRErr OGRSpatialReference::importFromESRI(char **papszPrj) const double dfStdPCount = OSR_GDV(papszPrj, "PARAM_1", 0.0); // TODO(schwehr): What is a reasonable range for StdPCount? if (dfStdPCount < 0 || dfStdPCount > std::numeric_limits::max() || - CPLIsNan(dfStdPCount)) + std::isnan(dfStdPCount)) { CPLError(CE_Failure, CPLE_AppDefined, "StdPCount out of range: %lf", dfStdPCount); diff --git a/ogr/ogrcircularstring.cpp b/ogr/ogrcircularstring.cpp index 0a6ae655095c..585e1eef2d7f 100644 --- a/ogr/ogrcircularstring.cpp +++ b/ogr/ogrcircularstring.cpp @@ -294,7 +294,7 @@ void OGRCircularString::ExtendEnvelopeWithCircular( if (OGRGeometryFactory::GetCurveParameters( x0, y0, x1, y1, x2, y2, R, cx, cy, alpha0, alpha1, alpha2)) { - if (CPLIsNan(alpha0) || CPLIsNan(alpha2)) + if (std::isnan(alpha0) || std::isnan(alpha2)) { CPLError(CE_Failure, CPLE_AppDefined, "GetCurveParameters returned NaN"); @@ -415,7 +415,7 @@ bool OGRCircularString::segmentize(double dfMaxLength) const double dfVal = 1 + 2 * std::floor(dfSegmentLength1 / dfMaxLength / 2.0); if (dfVal >= std::numeric_limits::max() || dfVal < 0.0 || - CPLIsNan(dfVal)) + std::isnan(dfVal)) { CPLError(CE_Failure, CPLE_AppDefined, "segmentize nIntermediatePoints invalid: %lf", @@ -451,7 +451,7 @@ bool OGRCircularString::segmentize(double dfMaxLength) const double dfVal = 1 + 2 * std::floor(dfSegmentLength2 / dfMaxLength / 2.0); if (dfVal >= std::numeric_limits::max() || dfVal < 0.0 || - CPLIsNan(dfVal)) + std::isnan(dfVal)) { CPLError(CE_Failure, CPLE_AppDefined, "segmentize nIntermediatePoints invalid 2: %lf", @@ -490,7 +490,7 @@ bool OGRCircularString::segmentize(double dfMaxLength) const double dfVal = 1 + 2 * std::ceil(dfSegmentLength1 / dfMaxLength / 2.0); if (dfVal >= std::numeric_limits::max() || dfVal < 0.0 || - CPLIsNan(dfVal)) + std::isnan(dfVal)) { CPLError(CE_Failure, CPLE_AppDefined, "segmentize nIntermediatePoints invalid 2: %lf", @@ -521,7 +521,7 @@ bool OGRCircularString::segmentize(double dfMaxLength) const double dfVal = 1 + 2 * std::ceil(dfSegmentLength2 / dfMaxLength / 2.0); if (dfVal >= std::numeric_limits::max() || dfVal < 0.0 || - CPLIsNan(dfVal)) + std::isnan(dfVal)) { CPLError(CE_Failure, CPLE_AppDefined, "segmentize nIntermediatePoints invalid 3: %lf", diff --git a/ogr/ogrfeature.cpp b/ogr/ogrfeature.cpp index 7680b1c5fa99..2304e8cbf516 100644 --- a/ogr/ogrfeature.cpp +++ b/ogr/ogrfeature.cpp @@ -2348,7 +2348,7 @@ static void OGRFeatureFormatDateTimeBuffer(char *szTempBuffer, size_t nMaxSize, nYear, nMonth, nDay, nHour, nMinute, fSecond); else // Default format. { - if (CPLIsNan(fSecond) || fSecond < 0.0 || fSecond > 62.0) + if (std::isnan(fSecond) || fSecond < 0.0 || fSecond > 62.0) { fSecond = 0.0; CPLError(CE_Failure, CPLE_NotSupported, @@ -2598,7 +2598,7 @@ const char *OGRFeature::GetFieldAsString(int iField) const constexpr size_t MAX_SIZE = 12 + EXTRA_SPACE_TO_MAKE_GCC_HAPPY + 1; m_pszTmpFieldValue = static_cast(CPLMalloc(MAX_SIZE)); const int ms = OGR_GET_MS(pauFields[iField].Date.Second); - if (ms != 0 || CPLIsNan(pauFields[iField].Date.Second)) + if (ms != 0 || std::isnan(pauFields[iField].Date.Second)) snprintf(m_pszTmpFieldValue, MAX_SIZE, "%02d:%02d:%06.3f", pauFields[iField].Date.Hour, pauFields[iField].Date.Minute, pauFields[iField].Date.Second); diff --git a/ogr/ogrgeometryfactory.cpp b/ogr/ogrgeometryfactory.cpp index eb9bcc4e5f30..756a608d7ad5 100644 --- a/ogr/ogrgeometryfactory.cpp +++ b/ogr/ogrgeometryfactory.cpp @@ -5063,8 +5063,8 @@ int OGRGeometryFactory::GetCurveParameters(double x0, double y0, double x1, double &alpha0, double &alpha1, double &alpha2) { - if (CPLIsNan(x0) || CPLIsNan(y0) || CPLIsNan(x1) || CPLIsNan(y1) || - CPLIsNan(x2) || CPLIsNan(y2)) + if (std::isnan(x0) || std::isnan(y0) || std::isnan(x1) || std::isnan(y1) || + std::isnan(x2) || std::isnan(y2)) { return FALSE; } @@ -5110,7 +5110,7 @@ int OGRGeometryFactory::GetCurveParameters(double x0, double y0, double x1, dy12 *= dfInvScale; const double det = dx01 * dy12 - dx12 * dy01; - if (fabs(det) < 1.0e-8 || CPLIsNan(det)) + if (fabs(det) < 1.0e-8 || std::isnan(det)) { return FALSE; } @@ -5165,7 +5165,7 @@ static void OGRGeometryFactoryStrokeArc(OGRLineString *poLine, double cx, // Constant angle between all points, so as to not depend on winding order. const double dfNumSteps = fabs((alpha1 - alpha0) / dfStep) + 0.5; if (dfNumSteps >= std::numeric_limits::max() || - dfNumSteps <= std::numeric_limits::min() || CPLIsNan(dfNumSteps)) + dfNumSteps <= std::numeric_limits::min() || std::isnan(dfNumSteps)) { CPLError(CE_Warning, CPLE_AppDefined, "OGRGeometryFactoryStrokeArc: bogus steps: " @@ -5448,7 +5448,7 @@ OGRLineString *OGRGeometryFactory::curveToLineString( dfAlphaRatio *= -1; } else if (dfAlphaRatio >= std::numeric_limits::max() || - CPLIsNan(dfAlphaRatio)) + std::isnan(dfAlphaRatio)) { CPLError(CE_Warning, CPLE_AppDefined, "AlphaRatio too large: %lf", dfAlphaRatio); diff --git a/ogr/ogrlinestring.cpp b/ogr/ogrlinestring.cpp index 5f6b3faba55c..82bbb87393c5 100644 --- a/ogr/ogrlinestring.cpp +++ b/ogr/ogrlinestring.cpp @@ -44,7 +44,7 @@ namespace int DoubleToIntClamp(double dfValue) { - if (CPLIsNan(dfValue)) + if (std::isnan(dfValue)) return 0; if (dfValue >= std::numeric_limits::max()) return std::numeric_limits::max(); diff --git a/ogr/ogrpgeogeometry.cpp b/ogr/ogrpgeogeometry.cpp index 57a781519ea8..fab888ab17ad 100644 --- a/ogr/ogrpgeogeometry.cpp +++ b/ogr/ogrpgeogeometry.cpp @@ -385,12 +385,15 @@ OGRGeometry *OGRCreateFromMultiPatch(int nParts, const GInt32 *panPartStart, padfX[nPartStart] == padfX[nPartStart + 3] && padfY[nPartStart] == padfY[nPartStart + 3] && padfZ[nPartStart] == padfZ[nPartStart + 3] && - !CPLIsNan(padfX[nPartStart]) && !CPLIsNan(padfX[nPartStart + 1]) && - !CPLIsNan(padfX[nPartStart + 2]) && !CPLIsNan(padfY[nPartStart]) && - !CPLIsNan(padfY[nPartStart + 1]) && - !CPLIsNan(padfY[nPartStart + 2]) && !CPLIsNan(padfZ[nPartStart]) && - !CPLIsNan(padfZ[nPartStart + 1]) && - !CPLIsNan(padfZ[nPartStart + 2])) + !std::isnan(padfX[nPartStart]) && + !std::isnan(padfX[nPartStart + 1]) && + !std::isnan(padfX[nPartStart + 2]) && + !std::isnan(padfY[nPartStart]) && + !std::isnan(padfY[nPartStart + 1]) && + !std::isnan(padfY[nPartStart + 2]) && + !std::isnan(padfZ[nPartStart]) && + !std::isnan(padfZ[nPartStart + 1]) && + !std::isnan(padfZ[nPartStart + 2])) { bool bDuplicate = false; if (iPart > 0) diff --git a/ogr/ogrpoint.cpp b/ogr/ogrpoint.cpp index 220dfc198de2..36fa1e0d7789 100644 --- a/ogr/ogrpoint.cpp +++ b/ogr/ogrpoint.cpp @@ -369,7 +369,7 @@ OGRErr OGRPoint::importFromWkb(const unsigned char *pabyData, size_t nSize, } // Detect coordinates are not NaN --> NOT EMPTY. - if (!(CPLIsNan(x) && CPLIsNan(y))) + if (!(std::isnan(x) && std::isnan(y))) flags |= OGR_G_NOT_EMPTY_POINT; return OGRERR_NONE; diff --git a/ogr/ogrsf_frmts/dxf/ogrdxfwriterds.cpp b/ogr/ogrsf_frmts/dxf/ogrdxfwriterds.cpp index 8cbfc1c05b31..c6f0e28e64a3 100644 --- a/ogr/ogrsf_frmts/dxf/ogrdxfwriterds.cpp +++ b/ogr/ogrsf_frmts/dxf/ogrdxfwriterds.cpp @@ -30,6 +30,7 @@ #include "cpl_port.h" +#include #include #include "ogr_dxf.h" @@ -352,10 +353,10 @@ bool OGRDXFWriterDS::TransferUpdateHeader(VSILFILE *fpOut) // We don't like non-finite extents. In this case, just write a generic // bounding box. Most CAD programs probably ignore this anyway. - if (!CPLIsFinite(oGlobalEnvelope.MinX) || - !CPLIsFinite(oGlobalEnvelope.MinY) || - !CPLIsFinite(oGlobalEnvelope.MaxX) || - !CPLIsFinite(oGlobalEnvelope.MaxY)) + if (!std::isfinite(oGlobalEnvelope.MinX) || + !std::isfinite(oGlobalEnvelope.MinY) || + !std::isfinite(oGlobalEnvelope.MaxX) || + !std::isfinite(oGlobalEnvelope.MaxY)) { oGlobalEnvelope.MinX = 0.0; oGlobalEnvelope.MinY = 0.0; diff --git a/ogr/ogrsf_frmts/filegdb/FGdbLayer.cpp b/ogr/ogrsf_frmts/filegdb/FGdbLayer.cpp index 7c7480f88b7a..81d3d6cc3bc9 100644 --- a/ogr/ogrsf_frmts/filegdb/FGdbLayer.cpp +++ b/ogr/ogrsf_frmts/filegdb/FGdbLayer.cpp @@ -30,6 +30,8 @@ ****************************************************************************/ #include +#include + #include "ogr_fgdb.h" #include "ogrpgeogeometry.h" #include "cpl_conv.h" @@ -4009,8 +4011,8 @@ OGRErr FGdbLayer::GetExtent(OGREnvelope *psExtent, int bForce) psExtent->MaxX = envelope.xMax; psExtent->MaxY = envelope.yMax; - if (CPLIsNan(psExtent->MinX) || CPLIsNan(psExtent->MinY) || - CPLIsNan(psExtent->MaxX) || CPLIsNan(psExtent->MaxY)) + if (std::isnan(psExtent->MinX) || std::isnan(psExtent->MinY) || + std::isnan(psExtent->MaxX) || std::isnan(psExtent->MaxY)) return OGRERR_FAILURE; return OGRERR_NONE; diff --git a/ogr/ogrsf_frmts/generic/ogrlayer.cpp b/ogr/ogrsf_frmts/generic/ogrlayer.cpp index 5a29e15822ff..82ac8464b073 100644 --- a/ogr/ogrsf_frmts/generic/ogrlayer.cpp +++ b/ogr/ogrsf_frmts/generic/ogrlayer.cpp @@ -38,6 +38,7 @@ #include "cpl_time.h" #include +#include #include #include @@ -348,8 +349,8 @@ OGRErr OGRLayer::GetExtentInternal(int iGeomField, OGREnvelope *psExtent, else if (!bExtentSet) { poGeom->getEnvelope(psExtent); - if (!(CPLIsNan(psExtent->MinX) || CPLIsNan(psExtent->MinY) || - CPLIsNan(psExtent->MaxX) || CPLIsNan(psExtent->MaxY))) + if (!(std::isnan(psExtent->MinX) || std::isnan(psExtent->MinY) || + std::isnan(psExtent->MaxX) || std::isnan(psExtent->MaxY))) { bExtentSet = true; } diff --git a/ogr/ogrsf_frmts/generic/ogrwarpedlayer.cpp b/ogr/ogrsf_frmts/generic/ogrwarpedlayer.cpp index 861dbc1360ac..1e77c950edea 100644 --- a/ogr/ogrsf_frmts/generic/ogrwarpedlayer.cpp +++ b/ogr/ogrsf_frmts/generic/ogrwarpedlayer.cpp @@ -28,6 +28,8 @@ #ifndef DOXYGEN_SKIP +#include + #include "ogrwarpedlayer.h" /************************************************************************/ @@ -112,8 +114,8 @@ void OGRWarpedLayer::SetSpatialFilter(int iGeomField, OGRGeometry *poGeom) { OGREnvelope sEnvelope; poGeom->getEnvelope(&sEnvelope); - if (CPLIsInf(sEnvelope.MinX) && CPLIsInf(sEnvelope.MinY) && - CPLIsInf(sEnvelope.MaxX) && CPLIsInf(sEnvelope.MaxY)) + if (std::isinf(sEnvelope.MinX) && std::isinf(sEnvelope.MinY) && + std::isinf(sEnvelope.MaxX) && std::isinf(sEnvelope.MaxY)) { m_poDecoratedLayer->SetSpatialFilterRect( m_iGeomFieldFilter, sEnvelope.MinX, sEnvelope.MinY, diff --git a/ogr/ogrsf_frmts/geojson/libjson/CMakeLists.txt b/ogr/ogrsf_frmts/geojson/libjson/CMakeLists.txt index 8cff23f5b51b..fbbe19539d78 100644 --- a/ogr/ogrsf_frmts/geojson/libjson/CMakeLists.txt +++ b/ogr/ogrsf_frmts/geojson/libjson/CMakeLists.txt @@ -26,6 +26,14 @@ add_library( printbuf.c random_seed.c strerror_override.c) + +if ((MSVC AND NOT (MSVC_VERSION LESS 1800)) OR MINGW OR CYGWIN OR UNIX) + check_symbol_exists(INFINITY "math.h" HAVE_DECL_INFINITY) + check_symbol_exists(isinf "math.h" HAVE_DECL_ISINF) + check_symbol_exists(isnan "math.h" HAVE_DECL_ISNAN) + check_symbol_exists(NAN "math.h" HAVE_DECL_NAN) +endif() + # -D_XOPEN_SOURCE=700 to enable strdup() definition in C11 mode target_compile_definitions(libjson PRIVATE -D_XOPEN_SOURCE=700) target_include_directories(libjson PRIVATE $ $) @@ -37,4 +45,17 @@ if (MSVC) endif () target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE $) +if(HAVE_DECL_INFINITY) + target_compile_definitions(libjson PRIVATE HAVE_DECL_INFINITY) +endif() +if(HAVE_DECL_ISINF) + target_compile_definitions(libjson PRIVATE HAVE_DECL_ISINF) +endif() +if(HAVE_DECL_ISNAN) + target_compile_definitions(libjson PRIVATE HAVE_DECL_ISNAN) +endif() +if(HAVE_DECL_NAN) + target_compile_definitions(libjson PRIVATE HAVE_DECL_NAN) +endif() + set_property(TARGET libjson PROPERTY UNITY_BUILD OFF) diff --git a/ogr/ogrsf_frmts/geojson/libjson/config.h b/ogr/ogrsf_frmts/geojson/libjson/config.h index 4b94043dd722..81cb191e03c0 100644 --- a/ogr/ogrsf_frmts/geojson/libjson/config.h +++ b/ogr/ogrsf_frmts/geojson/libjson/config.h @@ -122,11 +122,6 @@ /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 -#define HAVE_DECL_ISNAN -#define HAVE_DECL_ISINF -#define HAVE_DECL_INFINITY -#define HAVE_DECL_NAN - #include "cpl_config.h" #ifndef SIZE_T_MAX diff --git a/ogr/ogrsf_frmts/geojson/libjson/json_object.c b/ogr/ogrsf_frmts/geojson/libjson/json_object.c index 7a23c378cce3..4328538b0afd 100644 --- a/ogr/ogrsf_frmts/geojson/libjson/json_object.c +++ b/ogr/ogrsf_frmts/geojson/libjson/json_object.c @@ -1022,11 +1022,11 @@ static int json_object_double_to_json_string_format(struct json_object *jso, str * ECMA 262 section 9.8.1 defines * how to handle these cases as strings */ - if (CPLIsNan(jsodbl->c_double)) + if (isnan(jsodbl->c_double)) { size = snprintf(buf, sizeof(buf), "NaN"); } - else if (CPLIsInf(jsodbl->c_double)) + else if (isinf(jsodbl->c_double)) { if (jsodbl->c_double > 0) size = snprintf(buf, sizeof(buf), "Infinity"); diff --git a/ogr/ogrsf_frmts/geojson/libjson/math_compat.h b/ogr/ogrsf_frmts/geojson/libjson/math_compat.h index 2382fe15b30a..5d3b21ce79cb 100644 --- a/ogr/ogrsf_frmts/geojson/libjson/math_compat.h +++ b/ogr/ogrsf_frmts/geojson/libjson/math_compat.h @@ -18,6 +18,11 @@ #endif #endif +#ifdef __MINGW32__ +#undef isnan +#define isnan(x) __builtin_isnan(x) +#endif + #ifndef HAVE_DECL_ISINF #ifdef HAVE_DECL__FINITE #include @@ -29,6 +34,11 @@ #endif #endif +#ifdef __MINGW32__ +#undef isinf +#define isinf(x) __builtin_isinf(x) +#endif + #ifndef HAVE_DECL_INFINITY #include #define INFINITY (DBL_MAX + DBL_MAX) @@ -36,7 +46,9 @@ #endif #ifndef HAVE_DECL_NAN +#ifndef NAN #define NAN (INFINITY - INFINITY) +#endif #define HAVE_DECL_NAN #endif diff --git a/ogr/ogrsf_frmts/geojson/ogrgeojsonreader.cpp b/ogr/ogrsf_frmts/geojson/ogrgeojsonreader.cpp index bd08345f2645..368a21bfdbd6 100644 --- a/ogr/ogrsf_frmts/geojson/ogrgeojsonreader.cpp +++ b/ogr/ogrsf_frmts/geojson/ogrgeojsonreader.cpp @@ -33,6 +33,7 @@ #include "ogrjsoncollectionstreamingparser.h" #include "ogr_api.h" +#include #include #include #include diff --git a/ogr/ogrsf_frmts/geojson/ogrgeojsonwriter.cpp b/ogr/ogrsf_frmts/geojson/ogrgeojsonwriter.cpp index b1d1fdedf13d..b8cbba9ff1a5 100644 --- a/ogr/ogrsf_frmts/geojson/ogrgeojsonwriter.cpp +++ b/ogr/ogrsf_frmts/geojson/ogrgeojsonwriter.cpp @@ -44,6 +44,7 @@ #include "ogr_p.h" #include +#include #include #include @@ -936,7 +937,7 @@ json_object *OGRGeoJSONWriteAttributes(OGRFeature *poFeature, else if (OFTReal == eType) { const double val = poFeature->GetFieldAsDouble(nField); - if (!CPLIsFinite(val)) + if (!std::isfinite(val)) { if (!oOptions.bAllowNonFiniteValues) { @@ -1399,7 +1400,7 @@ json_object *OGRGeoJSONWriteCoords(double const &fX, double const &fY, const OGRGeoJSONWriteOptions &oOptions) { json_object *poObjCoords = nullptr; - if (CPLIsInf(fX) || CPLIsInf(fY) || CPLIsNan(fX) || CPLIsNan(fY)) + if (std::isinf(fX) || std::isinf(fY) || std::isnan(fX) || std::isnan(fY)) { CPLError(CE_Warning, CPLE_AppDefined, "Infinite or NaN coordinate encountered"); @@ -1416,8 +1417,8 @@ json_object *OGRGeoJSONWriteCoords(double const &fX, double const &fY, double const &fZ, const OGRGeoJSONWriteOptions &oOptions) { - if (CPLIsInf(fX) || CPLIsInf(fY) || CPLIsInf(fZ) || CPLIsNan(fX) || - CPLIsNan(fY) || CPLIsNan(fZ)) + if (std::isinf(fX) || std::isinf(fY) || std::isinf(fZ) || std::isnan(fX) || + std::isnan(fY) || std::isnan(fZ)) { CPLError(CE_Warning, CPLE_AppDefined, "Infinite or NaN coordinate encountered"); @@ -1628,7 +1629,7 @@ static int OGR_json_double_with_precision_to_string(struct json_object *jso, const uintptr_t nPrecision = reinterpret_cast(userData); char szBuffer[75] = {}; const double dfVal = json_object_get_double(jso); - if (fabs(dfVal) > 1e50 && !CPLIsInf(dfVal)) + if (fabs(dfVal) > 1e50 && !std::isinf(dfVal)) { CPLsnprintf(szBuffer, sizeof(szBuffer), "%.18g", dfVal); } @@ -1667,9 +1668,9 @@ static int OGR_json_double_with_significant_figures_to_string( char szBuffer[75] = {}; int nSize = 0; const double dfVal = json_object_get_double(jso); - if (CPLIsNan(dfVal)) + if (std::isnan(dfVal)) nSize = CPLsnprintf(szBuffer, sizeof(szBuffer), "NaN"); - else if (CPLIsInf(dfVal)) + else if (std::isinf(dfVal)) { if (dfVal > 0) nSize = CPLsnprintf(szBuffer, sizeof(szBuffer), "Infinity"); @@ -1767,9 +1768,9 @@ static int OGR_json_float_with_significant_figures_to_string( char szBuffer[75] = {}; int nSize = 0; const float fVal = static_cast(json_object_get_double(jso)); - if (CPLIsNan(fVal)) + if (std::isnan(fVal)) nSize = CPLsnprintf(szBuffer, sizeof(szBuffer), "NaN"); - else if (CPLIsInf(fVal)) + else if (std::isinf(fVal)) { if (fVal > 0) nSize = CPLsnprintf(szBuffer, sizeof(szBuffer), "Infinity"); diff --git a/ogr/ogrsf_frmts/gml/hugefileresolver.cpp b/ogr/ogrsf_frmts/gml/hugefileresolver.cpp index b5e204ad794c..403754a1d412 100644 --- a/ogr/ogrsf_frmts/gml/hugefileresolver.cpp +++ b/ogr/ogrsf_frmts/gml/hugefileresolver.cpp @@ -39,6 +39,7 @@ #include "gmlreaderp.h" #include +#include #include #include "cpl_conv.h" diff --git a/ogr/ogrsf_frmts/gmlas/ogrgmlaswriter.cpp b/ogr/ogrsf_frmts/gmlas/ogrgmlaswriter.cpp index 90e543f0847b..9ee11cf89027 100644 --- a/ogr/ogrsf_frmts/gmlas/ogrgmlaswriter.cpp +++ b/ogr/ogrsf_frmts/gmlas/ogrgmlaswriter.cpp @@ -34,6 +34,7 @@ #include "cpl_time.h" #include +#include namespace GMLAS { @@ -1641,14 +1642,14 @@ void GMLASWriter::PrintMultipleValuesSeparator( static void PrintXMLDouble(VSILFILE *fp, double dfVal) { - if (CPLIsInf(dfVal)) + if (std::isinf(dfVal)) { if (dfVal > 0) VSIFPrintfL(fp, "INF"); else VSIFPrintfL(fp, "-INF"); } - else if (CPLIsNan(dfVal)) + else if (std::isnan(dfVal)) VSIFPrintfL(fp, "NaN"); else VSIFPrintfL(fp, "%.16g", dfVal); diff --git a/ogr/ogrsf_frmts/gpkg/gdalgeopackagerasterband.cpp b/ogr/ogrsf_frmts/gpkg/gdalgeopackagerasterband.cpp index c11cca9f82ca..b8f068940b98 100644 --- a/ogr/ogrsf_frmts/gpkg/gdalgeopackagerasterband.cpp +++ b/ogr/ogrsf_frmts/gpkg/gdalgeopackagerasterband.cpp @@ -33,6 +33,7 @@ #include "cpl_error.h" #include +#include #include #include #include @@ -1752,7 +1753,7 @@ CPLErr GDALGPKGMBTilesLikePseudoDataset::WriteTileInternal() int bHasNoData = FALSE; double dfNoDataValue = IGetRasterBand(1)->GetNoDataValue(&bHasNoData); - const bool bHasNanNoData = bHasNoData && CPLIsNan(dfNoDataValue); + const bool bHasNanNoData = bHasNoData && std::isnan(dfNoDataValue); bool bAllOpaque = true; // Detect fully transparent tiles, but only if all bands are dirty (that is @@ -1818,7 +1819,7 @@ CPLErr GDALGPKGMBTilesLikePseudoDataset::WriteTileInternal() const float fVal = pSrc[i]; if (bHasNanNoData) { - if (CPLIsNan(fVal)) + if (std::isnan(fVal)) continue; } else if (fVal == fNoDataValueOrZero) @@ -2026,7 +2027,7 @@ CPLErr GDALGPKGMBTilesLikePseudoDataset::WriteTileInternal() const float fVal = pSrc[i]; if (bHasNanNoData) { - if (CPLIsNan(fVal)) + if (std::isnan(fVal)) continue; } else if (bHasNoData && @@ -2034,7 +2035,7 @@ CPLErr GDALGPKGMBTilesLikePseudoDataset::WriteTileInternal() { continue; } - if (CPLIsInf(fVal)) + if (std::isinf(fVal)) continue; if (nValidPixels == 0) @@ -2092,7 +2093,7 @@ CPLErr GDALGPKGMBTilesLikePseudoDataset::WriteTileInternal() const float fVal = pSrc[i]; if (bHasNanNoData) { - if (CPLIsNan(fVal)) + if (std::isnan(fVal)) { pTempTileBuffer[i] = m_usGPKGNull; continue; @@ -2107,7 +2108,7 @@ CPLErr GDALGPKGMBTilesLikePseudoDataset::WriteTileInternal() } } double dfVal = - CPLIsFinite(fVal) + std::isfinite(fVal) ? ((fVal - m_dfOffset) / m_dfScale - dfTileOffset) / dfTileScale : (fVal > 0) ? 65535 @@ -2141,7 +2142,7 @@ CPLErr GDALGPKGMBTilesLikePseudoDataset::WriteTileInternal() const float fVal = pSrc[i]; if (bHasNanNoData) { - if (CPLIsNan(fVal)) + if (std::isnan(fVal)) continue; } else if (bHasNoData && @@ -3740,7 +3741,7 @@ CPLErr GDALGeoPackageRasterBand::SetNoDataValue(double dfNoDataValue) return CE_None; } - if (CPLIsNan(dfNoDataValue)) + if (std::isnan(dfNoDataValue)) { CPLError(CE_Warning, CPLE_NotSupported, "A NaN nodata value cannot be recorded in " diff --git a/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp b/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp index 5383eb2e758d..5cf56b70c2d3 100644 --- a/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp +++ b/ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp @@ -3523,9 +3523,9 @@ OGRErr OGRGeoPackageTableLayer::ResetStatementInternal(GIntBig nStartIndex) bUseSpatialIndex = false; } - if (bUseSpatialIndex && !CPLIsInf(sEnvelope.MinX) && - !CPLIsInf(sEnvelope.MinY) && !CPLIsInf(sEnvelope.MaxX) && - !CPLIsInf(sEnvelope.MaxY)) + if (bUseSpatialIndex && !std::isinf(sEnvelope.MinX) && + !std::isinf(sEnvelope.MinY) && !std::isinf(sEnvelope.MaxX) && + !std::isinf(sEnvelope.MaxY)) { soSQL.Printf("SELECT %s FROM \"%s\" m " "JOIN \"%s\" r " @@ -4042,8 +4042,8 @@ GIntBig OGRGeoPackageTableLayer::GetFeatureCount(int /*bForce*/) m_poFilterGeom->getEnvelope(&sEnvelope); - if (!CPLIsInf(sEnvelope.MinX) && !CPLIsInf(sEnvelope.MinY) && - !CPLIsInf(sEnvelope.MaxX) && !CPLIsInf(sEnvelope.MaxY)) + if (!std::isinf(sEnvelope.MinX) && !std::isinf(sEnvelope.MinY) && + !std::isinf(sEnvelope.MaxX) && !std::isinf(sEnvelope.MaxY)) { soSQL.Printf("SELECT COUNT(*) FROM \"%s\" WHERE " "maxx >= %.12f AND minx <= %.12f AND " @@ -5503,10 +5503,10 @@ CPLString OGRGeoPackageTableLayer::GetSpatialWhere(int m_iGeomColIn, const char *pszC = m_poFeatureDefn->GetGeomFieldDefn(m_iGeomColIn)->GetNameRef(); - if (CPLIsInf(sEnvelope.MinX) && sEnvelope.MinX < 0 && - CPLIsInf(sEnvelope.MinY) && sEnvelope.MinY < 0 && - CPLIsInf(sEnvelope.MaxX) && sEnvelope.MaxX > 0 && - CPLIsInf(sEnvelope.MaxY) && sEnvelope.MaxY > 0) + if (std::isinf(sEnvelope.MinX) && sEnvelope.MinX < 0 && + std::isinf(sEnvelope.MinY) && sEnvelope.MinY < 0 && + std::isinf(sEnvelope.MaxX) && sEnvelope.MaxX > 0 && + std::isinf(sEnvelope.MaxY) && sEnvelope.MaxY > 0) { osSpatialWHERE.Printf( "(\"%s\" IS NOT NULL AND NOT ST_IsEmpty(\"%s\"))", @@ -8478,9 +8478,9 @@ void OGRGeoPackageTableLayer::GetNextArrowArrayAsynchronousWorker() bUseSpatialIndex = false; } - if (bUseSpatialIndex && !CPLIsInf(sEnvelope.MinX) && - !CPLIsInf(sEnvelope.MinY) && !CPLIsInf(sEnvelope.MaxX) && - !CPLIsInf(sEnvelope.MaxY)) + if (bUseSpatialIndex && !std::isinf(sEnvelope.MinX) && + !std::isinf(sEnvelope.MinY) && !std::isinf(sEnvelope.MaxX) && + !std::isinf(sEnvelope.MaxY)) { osSQL += CPLSPrintf(" JOIN \"%s\" r " diff --git a/ogr/ogrsf_frmts/hana/ogrhanafeaturereader.cpp b/ogr/ogrsf_frmts/hana/ogrhanafeaturereader.cpp index 03f07e3b1b79..62c50efb1a06 100644 --- a/ogr/ogrsf_frmts/hana/ogrhanafeaturereader.cpp +++ b/ogr/ogrsf_frmts/hana/ogrhanafeaturereader.cpp @@ -32,6 +32,7 @@ #include "cpl_time.h" #include +#include #include #include #include diff --git a/ogr/ogrsf_frmts/hana/ogrhanalayer.cpp b/ogr/ogrsf_frmts/hana/ogrhanalayer.cpp index 27541403796a..381341a30c04 100644 --- a/ogr/ogrsf_frmts/hana/ogrhanalayer.cpp +++ b/ogr/ogrsf_frmts/hana/ogrhanalayer.cpp @@ -31,6 +31,7 @@ #include "ogrhanautils.h" #include +#include #include #include #include @@ -74,8 +75,8 @@ CPLString BuildSpatialFilter(int dbVersion, const OGRGeometry &geom, OGREnvelope env; geom.getEnvelope(&env); - if ((CPLIsInf(env.MinX) || CPLIsInf(env.MinY) || CPLIsInf(env.MaxX) || - CPLIsInf(env.MaxY))) + if ((std::isinf(env.MinX) || std::isinf(env.MinY) || std::isinf(env.MaxX) || + std::isinf(env.MaxY))) return ""; auto clampValue = [](double v) diff --git a/ogr/ogrsf_frmts/kml/ogr2kmlgeometry.cpp b/ogr/ogrsf_frmts/kml/ogr2kmlgeometry.cpp index cdf44f9a97bb..329ef74ed2f1 100644 --- a/ogr/ogrsf_frmts/kml/ogr2kmlgeometry.cpp +++ b/ogr/ogrsf_frmts/kml/ogr2kmlgeometry.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include "cpl_conv.h" #include "cpl_error.h" @@ -100,7 +101,7 @@ static void MakeKMLCoordinate(char *pszTarget, size_t nTargetLen, double x, } // Trash drastically non-sensical values. - if (x > 1.0e6 || x < -1.0e6 || CPLIsNan(x)) + if (x > 1.0e6 || x < -1.0e6 || std::isnan(x)) { static bool bFirstWarning2 = true; if (bFirstWarning2) diff --git a/ogr/ogrsf_frmts/miramon/mm_wrlayr.h b/ogr/ogrsf_frmts/miramon/mm_wrlayr.h index 7520d30d6a82..24c1bb49ab5e 100644 --- a/ogr/ogrsf_frmts/miramon/mm_wrlayr.h +++ b/ogr/ogrsf_frmts/miramon/mm_wrlayr.h @@ -98,8 +98,9 @@ CPL_C_START // Necessary for compiling in GDAL project #define CPLFree_function(a) CPLFree((a)) #define form_filename_function(a, b) CPLFormFilename((a), (b), "") #define MM_CPLGetBasename(a) CPLGetBasename((a)) -#define MM_IsNANDouble(x) CPLIsNan((x)) -#define MM_IsDoubleInfinite(x) CPLIsInf((x)) + bool + MM_IsNANDouble(double x); +bool MM_IsDoubleInfinite(double x); #endif /* -------------------------------------------------------------------- */ @@ -111,8 +112,7 @@ CPL_C_START // Necessary for compiling in GDAL project #define MMCPLWarning CPLError #define MMCPLDebug CPLDebugOnly #else - void - MMCPLError(int code, const char *fmt, ...); +void MMCPLError(int code, const char *fmt, ...); void MMCPLWarning(int code, const char *fmt, ...); void MMCPLDebug(int code, const char *fmt, ...); #endif diff --git a/ogr/ogrsf_frmts/miramon/ogrmiramondriver.cpp b/ogr/ogrsf_frmts/miramon/ogrmiramondriver.cpp index 35e6c08ec0fd..d44f08a4c815 100644 --- a/ogr/ogrsf_frmts/miramon/ogrmiramondriver.cpp +++ b/ogr/ogrsf_frmts/miramon/ogrmiramondriver.cpp @@ -27,6 +27,18 @@ #include "ogrmiramon.h" +#include + +bool MM_IsNANDouble(double x) +{ + return std::isnan(x); +} + +bool MM_IsDoubleInfinite(double x) +{ + return std::isinf(x); +} + /****************************************************************************/ /* OGRMMDriverIdentify() */ /****************************************************************************/ diff --git a/ogr/ogrsf_frmts/mssqlspatial/ogrmssqlspatialtablelayer.cpp b/ogr/ogrsf_frmts/mssqlspatial/ogrmssqlspatialtablelayer.cpp index 41f51a9020e4..c54809492e4b 100644 --- a/ogr/ogrsf_frmts/mssqlspatial/ogrmssqlspatialtablelayer.cpp +++ b/ogr/ogrsf_frmts/mssqlspatial/ogrmssqlspatialtablelayer.cpp @@ -31,6 +31,7 @@ #include "ogr_mssqlspatial.h" #include "ogr_p.h" +#include #include #include @@ -608,10 +609,10 @@ OGRMSSQLSpatialTableLayer::BuildStatement(const char *pszColumns) if (nGeomColumnType == MSSQLCOLTYPE_GEOMETRY || nGeomColumnType == MSSQLCOLTYPE_GEOGRAPHY) { - if (!CPLIsInf(m_sFilterEnvelope.MinX) && - !CPLIsInf(m_sFilterEnvelope.MinY) && - !CPLIsInf(m_sFilterEnvelope.MaxX) && - !CPLIsInf(m_sFilterEnvelope.MaxY)) + if (!std::isinf(m_sFilterEnvelope.MinX) && + !std::isinf(m_sFilterEnvelope.MinY) && + !std::isinf(m_sFilterEnvelope.MaxX) && + !std::isinf(m_sFilterEnvelope.MaxY)) { if (pszQuery == nullptr) poStatement->Append(" where "); diff --git a/ogr/ogrsf_frmts/mvt/mvt_tile.cpp b/ogr/ogrsf_frmts/mvt/mvt_tile.cpp index 27e12d0c2264..b302fb1317da 100644 --- a/ogr/ogrsf_frmts/mvt/mvt_tile.cpp +++ b/ogr/ogrsf_frmts/mvt/mvt_tile.cpp @@ -28,6 +28,7 @@ #include "gpb.h" +#include #include #include #include @@ -183,7 +184,7 @@ void MVTTileLayerValue::setValue(double dfVal) { setSIntValue(static_cast(dfVal)); } - else if (!CPLIsFinite(dfVal) || + else if (!std::isfinite(dfVal) || (dfVal >= -std::numeric_limits::max() && dfVal <= std::numeric_limits::max() && dfVal == static_cast(dfVal))) diff --git a/ogr/ogrsf_frmts/odbc/ogrodbclayer.cpp b/ogr/ogrsf_frmts/odbc/ogrodbclayer.cpp index 9d12954148c9..a3566b5e95e7 100644 --- a/ogr/ogrsf_frmts/odbc/ogrodbclayer.cpp +++ b/ogr/ogrsf_frmts/odbc/ogrodbclayer.cpp @@ -31,6 +31,8 @@ #include "ogr_odbc.h" #include "cpl_string.h" +#include + /************************************************************************/ /* OGRODBCLayer() */ /************************************************************************/ diff --git a/ogr/ogrsf_frmts/openfilegdb/filegdbindex.cpp b/ogr/ogrsf_frmts/openfilegdb/filegdbindex.cpp index 1c3ddf445609..48db9dd5fb0e 100644 --- a/ogr/ogrsf_frmts/openfilegdb/filegdbindex.cpp +++ b/ogr/ogrsf_frmts/openfilegdb/filegdbindex.cpp @@ -29,6 +29,7 @@ #include "cpl_port.h" #include "filegdbtable_priv.h" +#include #include #include #include diff --git a/ogr/ogrsf_frmts/openfilegdb/filegdbtable.cpp b/ogr/ogrsf_frmts/openfilegdb/filegdbtable.cpp index 18936e188acb..569ce366c633 100644 --- a/ogr/ogrsf_frmts/openfilegdb/filegdbtable.cpp +++ b/ogr/ogrsf_frmts/openfilegdb/filegdbtable.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -1848,7 +1849,7 @@ int FileGDBDoubleDateToOGRDate(double dfVal, bool bHighPrecision, { // 25569: Number of days between 1899/12/30 00:00:00 and 1970/01/01 00:00:00 double dfSeconds = (dfVal - 25569.0) * 3600.0 * 24.0; - if (CPLIsNan(dfSeconds) || + if (std::isnan(dfSeconds) || dfSeconds < static_cast(std::numeric_limits::min()) + 1000 || dfSeconds > @@ -1890,7 +1891,7 @@ int FileGDBDoubleDateToOGRDate(double dfVal, bool bHighPrecision, int FileGDBDoubleTimeToOGRTime(double dfVal, OGRField *psField) { double dfSeconds = dfVal * 3600.0 * 24.0; - if (CPLIsNan(dfSeconds) || dfSeconds < 0 || dfSeconds > 86400) + if (std::isnan(dfSeconds) || dfSeconds < 0 || dfSeconds > 86400) { CPLError(CE_Failure, CPLE_NotSupported, "FileGDBDoubleTimeToOGRTime: Invalid time: %lf", dfVal); diff --git a/ogr/ogrsf_frmts/openfilegdb/filegdbtable_write.cpp b/ogr/ogrsf_frmts/openfilegdb/filegdbtable_write.cpp index 458b842f015c..ac75256d2450 100644 --- a/ogr/ogrsf_frmts/openfilegdb/filegdbtable_write.cpp +++ b/ogr/ogrsf_frmts/openfilegdb/filegdbtable_write.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include #include diff --git a/ogr/ogrsf_frmts/openfilegdb/gdalopenfilegdbrasterband.cpp b/ogr/ogrsf_frmts/openfilegdb/gdalopenfilegdbrasterband.cpp index 7e337ebb0910..45735d0f13cb 100644 --- a/ogr/ogrsf_frmts/openfilegdb/gdalopenfilegdbrasterband.cpp +++ b/ogr/ogrsf_frmts/openfilegdb/gdalopenfilegdbrasterband.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include #include diff --git a/ogr/ogrsf_frmts/pgdump/ogrpgdumplayer.cpp b/ogr/ogrsf_frmts/pgdump/ogrpgdumplayer.cpp index 36053c48709d..31004e329672 100644 --- a/ogr/ogrsf_frmts/pgdump/ogrpgdumplayer.cpp +++ b/ogr/ogrsf_frmts/pgdump/ogrpgdumplayer.cpp @@ -32,6 +32,7 @@ #include "cpl_string.h" #include "ogr_p.h" +#include #include // @@ -626,9 +627,9 @@ void OGRPGCommonAppendCopyRegularFields( nOff += static_cast(strlen(pszNeedToFree + nOff)); // Check for special values. They need to be quoted. - if (CPLIsNan(padfItems[j])) + if (std::isnan(padfItems[j])) snprintf(pszNeedToFree + nOff, nLen - nOff, "NaN"); - else if (CPLIsInf(padfItems[j])) + else if (std::isinf(padfItems[j])) snprintf(pszNeedToFree + nOff, nLen - nOff, (padfItems[j] > 0) ? "Infinity" : "-Infinity"); else @@ -663,9 +664,9 @@ void OGRPGCommonAppendCopyRegularFields( { // Check for special values. They need to be quoted. double dfVal = poFeature->GetFieldAsDouble(i); - if (CPLIsNan(dfVal)) + if (std::isnan(dfVal)) pszStrValue = "NaN"; - else if (CPLIsInf(dfVal)) + else if (std::isinf(dfVal)) pszStrValue = (dfVal > 0) ? "Infinity" : "-Infinity"; } @@ -1057,9 +1058,9 @@ void OGRPGCommonAppendFieldValue(CPLString &osCommand, OGRFeature *poFeature, nOff += static_cast(strlen(pszNeedToFree + nOff)); // Check for special values. They need to be quoted. - if (CPLIsNan(padfItems[j])) + if (std::isnan(padfItems[j])) snprintf(pszNeedToFree + nOff, nLen - nOff, "NaN"); - else if (CPLIsInf(padfItems[j])) + else if (std::isinf(padfItems[j])) snprintf(pszNeedToFree + nOff, nLen - nOff, (padfItems[j] > 0) ? "Infinity" : "-Infinity"); else @@ -1121,9 +1122,9 @@ void OGRPGCommonAppendFieldValue(CPLString &osCommand, OGRFeature *poFeature, { // Check for special values. They need to be quoted. double dfVal = poFeature->GetFieldAsDouble(i); - if (CPLIsNan(dfVal)) + if (std::isnan(dfVal)) pszStrValue = "'NaN'"; - else if (CPLIsInf(dfVal)) + else if (std::isinf(dfVal)) pszStrValue = (dfVal > 0) ? "'Infinity'" : "'-Infinity'"; } else if ((nOGRFieldType == OFTInteger || nOGRFieldType == OFTInteger64) && diff --git a/ogr/ogrsf_frmts/pgeo/ogrpgeolayer.cpp b/ogr/ogrsf_frmts/pgeo/ogrpgeolayer.cpp index d30b8616fd1a..4a522e480192 100644 --- a/ogr/ogrsf_frmts/pgeo/ogrpgeolayer.cpp +++ b/ogr/ogrsf_frmts/pgeo/ogrpgeolayer.cpp @@ -34,6 +34,7 @@ #include "ogrpgeogeometry.h" #include +#include /************************************************************************/ /* OGRPGeoLayer() */ diff --git a/ogr/ogrsf_frmts/shape/ogrshapelayer.cpp b/ogr/ogrsf_frmts/shape/ogrshapelayer.cpp index 432b792bd653..5e9e5584c521 100644 --- a/ogr/ogrsf_frmts/shape/ogrshapelayer.cpp +++ b/ogr/ogrsf_frmts/shape/ogrshapelayer.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -1699,8 +1700,8 @@ OGRErr OGRShapeLayer::GetExtent(OGREnvelope *psExtent, int bForce) psExtent->MaxX = adMax[0]; psExtent->MaxY = adMax[1]; - if (CPLIsNan(adMin[0]) || CPLIsNan(adMin[1]) || CPLIsNan(adMax[0]) || - CPLIsNan(adMax[1])) + if (std::isnan(adMin[0]) || std::isnan(adMin[1]) || std::isnan(adMax[0]) || + std::isnan(adMax[1])) { CPLDebug("SHAPE", "Invalid extent in shape header"); @@ -1753,8 +1754,8 @@ OGRErr OGRShapeLayer::GetExtent3D(int, OGREnvelope3D *psExtent3D, int bForce) psExtent3D->MaxZ = -std::numeric_limits::infinity(); } - if (CPLIsNan(adMin[0]) || CPLIsNan(adMin[1]) || CPLIsNan(adMax[0]) || - CPLIsNan(adMax[1])) + if (std::isnan(adMin[0]) || std::isnan(adMin[1]) || std::isnan(adMax[0]) || + std::isnan(adMax[1])) { CPLDebug("SHAPE", "Invalid extent in shape header"); diff --git a/ogr/ogrsf_frmts/sqlite/ogrsqlitelayer.cpp b/ogr/ogrsf_frmts/sqlite/ogrsqlitelayer.cpp index 631c9bb3a8da..480e8714d2d1 100644 --- a/ogr/ogrsf_frmts/sqlite/ogrsqlitelayer.cpp +++ b/ogr/ogrsf_frmts/sqlite/ogrsqlitelayer.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -3563,10 +3564,10 @@ CPLString OGRSQLiteLayer::FormatSpatialFilterFromRTree( poFilterGeom->getEnvelope(&sEnvelope); - if (CPLIsInf(sEnvelope.MinX) && sEnvelope.MinX < 0 && - CPLIsInf(sEnvelope.MinY) && sEnvelope.MinY < 0 && - CPLIsInf(sEnvelope.MaxX) && sEnvelope.MaxX > 0 && - CPLIsInf(sEnvelope.MaxY) && sEnvelope.MaxY > 0) + if (std::isinf(sEnvelope.MinX) && sEnvelope.MinX < 0 && + std::isinf(sEnvelope.MinY) && sEnvelope.MinY < 0 && + std::isinf(sEnvelope.MaxX) && sEnvelope.MaxX > 0 && + std::isinf(sEnvelope.MaxY) && sEnvelope.MaxY > 0) return ""; osSpatialWHERE.Printf( @@ -3592,10 +3593,10 @@ OGRSQLiteLayer::FormatSpatialFilterFromMBR(OGRGeometry *poFilterGeom, poFilterGeom->getEnvelope(&sEnvelope); - if (CPLIsInf(sEnvelope.MinX) && sEnvelope.MinX < 0 && - CPLIsInf(sEnvelope.MinY) && sEnvelope.MinY < 0 && - CPLIsInf(sEnvelope.MaxX) && sEnvelope.MaxX > 0 && - CPLIsInf(sEnvelope.MaxY) && sEnvelope.MaxY > 0) + if (std::isinf(sEnvelope.MinX) && sEnvelope.MinX < 0 && + std::isinf(sEnvelope.MinY) && sEnvelope.MinY < 0 && + std::isinf(sEnvelope.MaxX) && sEnvelope.MaxX > 0 && + std::isinf(sEnvelope.MaxY) && sEnvelope.MaxY > 0) return ""; /* A bit inefficient but still faster than OGR filtering */ diff --git a/ogr/ogrsf_frmts/vrt/ogrvrtlayer.cpp b/ogr/ogrsf_frmts/vrt/ogrvrtlayer.cpp index 2b4cedd558e6..af22aa41c077 100644 --- a/ogr/ogrsf_frmts/vrt/ogrvrtlayer.cpp +++ b/ogr/ogrsf_frmts/vrt/ogrvrtlayer.cpp @@ -31,6 +31,7 @@ #include "ogr_vrt.h" #include +#include #include #include #include @@ -1247,13 +1248,13 @@ bool OGRVRTLayer::ResetSourceReading() m_poFilterGeom->getEnvelope(&sEnvelope); } - if (!CPLIsInf(sEnvelope.MinX)) + if (!std::isinf(sEnvelope.MinX)) osFilter += CPLSPrintf("\"%s\" > %.15g", pszXField, sEnvelope.MinX); else if (sEnvelope.MinX > 0) osFilter += "0 = 1"; - if (!CPLIsInf(sEnvelope.MaxX)) + if (!std::isinf(sEnvelope.MaxX)) { if (!osFilter.empty()) osFilter += " AND "; @@ -1267,7 +1268,7 @@ bool OGRVRTLayer::ResetSourceReading() osFilter += "0 = 1"; } - if (!CPLIsInf(sEnvelope.MinY)) + if (!std::isinf(sEnvelope.MinY)) { if (!osFilter.empty()) osFilter += " AND "; @@ -1281,7 +1282,7 @@ bool OGRVRTLayer::ResetSourceReading() osFilter += "0 = 1"; } - if (!CPLIsInf(sEnvelope.MaxY)) + if (!std::isinf(sEnvelope.MaxY)) { if (!osFilter.empty()) osFilter += " AND "; @@ -1367,10 +1368,12 @@ bool OGRVRTLayer::ResetSourceReading() { OGREnvelope sEnvelope; m_poFilterGeom->getEnvelope(&sEnvelope); - if (CPLIsInf(sEnvelope.MinX) && CPLIsInf(sEnvelope.MinY) && - CPLIsInf(sEnvelope.MaxX) && CPLIsInf(sEnvelope.MaxY) && - sEnvelope.MinX < 0 && sEnvelope.MinY < 0 && - sEnvelope.MaxX > 0 && sEnvelope.MaxY > 0) + if (std::isinf(sEnvelope.MinX) && + std::isinf(sEnvelope.MinY) && + std::isinf(sEnvelope.MaxX) && + std::isinf(sEnvelope.MaxY) && sEnvelope.MinX < 0 && + sEnvelope.MinY < 0 && sEnvelope.MaxX > 0 && + sEnvelope.MaxY > 0) { poSpatialGeom = poSrcRegion; bDoIntersection = false; diff --git a/ogr/ogrspatialreference.cpp b/ogr/ogrspatialreference.cpp index ef664419206e..21a9ffb0f6d5 100644 --- a/ogr/ogrspatialreference.cpp +++ b/ogr/ogrspatialreference.cpp @@ -7850,7 +7850,7 @@ int OGRSpatialReference::GetUTMZone(int *pbNorth) const const double dfZone = (dfCentralMeridian + 186.0) / 6.0; if (dfCentralMeridian < -177.00001 || dfCentralMeridian > 177.000001 || - CPLIsNan(dfZone) || + std::isnan(dfZone) || std::abs(dfZone - static_cast(dfZone) - 0.5) > 0.00001) return 0; diff --git a/ogr/ogrutils.cpp b/ogr/ogrutils.cpp index 0b1383550a5b..39c11f6c613f 100644 --- a/ogr/ogrutils.cpp +++ b/ogr/ogrutils.cpp @@ -2330,3 +2330,15 @@ int OGRFormatFloat(char *pszBuffer, int nBufferLen, float fVal, int nPrecision, return nSize; } + +int OGR_GET_MS(float fSec) +{ + if (std::isnan(fSec)) + return 0; + if (fSec >= 999) + return 999; + if (fSec <= 0) + return 0; + const float fValue = (fSec - static_cast(fSec)) * 1000 + 0.5f; + return static_cast(fValue); +} diff --git a/port/cpl_conv.cpp b/port/cpl_conv.cpp index afcfd3eac95e..2a060d8da817 100644 --- a/port/cpl_conv.cpp +++ b/port/cpl_conv.cpp @@ -2529,7 +2529,7 @@ const char *CPLDecToDMS(double dfAngle, const char *pszAxis, int nPrecision) { VALIDATE_POINTER1(pszAxis, "CPLDecToDMS", ""); - if (CPLIsNan(dfAngle)) + if (std::isnan(dfAngle)) return "Invalid angle"; const double dfEpsilon = (0.5 / 3600.0) * pow(0.1, nPrecision); diff --git a/port/cpl_json_streaming_writer.cpp b/port/cpl_json_streaming_writer.cpp index ff9c3deef7f7..c11ac9fc3b2c 100644 --- a/port/cpl_json_streaming_writer.cpp +++ b/port/cpl_json_streaming_writer.cpp @@ -28,6 +28,7 @@ /*! @cond Doxygen_Suppress */ +#include #include #include @@ -240,11 +241,11 @@ void CPLJSonStreamingWriter::Add(std::uint64_t nVal) void CPLJSonStreamingWriter::Add(float fVal, int nPrecision) { EmitCommaIfNeeded(); - if (CPLIsNan(fVal)) + if (std::isnan(fVal)) { Print("\"NaN\""); } - else if (CPLIsInf(fVal)) + else if (std::isinf(fVal)) { Print(fVal > 0 ? "\"Infinity\"" : "\"-Infinity\""); } @@ -259,11 +260,11 @@ void CPLJSonStreamingWriter::Add(float fVal, int nPrecision) void CPLJSonStreamingWriter::Add(double dfVal, int nPrecision) { EmitCommaIfNeeded(); - if (CPLIsNan(dfVal)) + if (std::isnan(dfVal)) { Print("\"NaN\""); } - else if (CPLIsInf(dfVal)) + else if (std::isinf(dfVal)) { Print(dfVal > 0 ? "\"Infinity\"" : "\"-Infinity\""); } diff --git a/port/cpl_port.h b/port/cpl_port.h index da680fe0647c..35a0cc5c7d5f 100644 --- a/port/cpl_port.h +++ b/port/cpl_port.h @@ -568,6 +568,8 @@ static inline char *CPL_afl_friendly_strstr(const char *haystack, #endif /*! @endcond */ +#ifndef GDAL_COMPILATION +/*! @cond Doxygen_Suppress */ /* -------------------------------------------------------------------- */ /* Handle isnan() and isinf(). Note that isinf() and isnan() */ /* are supposed to be macros according to C99, defined in math.h */ @@ -680,6 +682,8 @@ extern "C++" #endif #endif #endif +/*! @endcond */ +#endif // GDAL_COMPILATION /*! @cond Doxygen_Suppress */ /*--------------------------------------------------------------------- diff --git a/port/cpl_string.cpp b/port/cpl_string.cpp index f7372c29f7cd..bd65493019ea 100644 --- a/port/cpl_string.cpp +++ b/port/cpl_string.cpp @@ -52,6 +52,7 @@ #include #include +#include #include #include @@ -2863,7 +2864,7 @@ CPLValueType CPLGetValueType(const char *pszValue) { // cppcheck-suppress unreadVariable const double dfVal = CPLAtof(pszValueInit); - if (CPLIsInf(dfVal)) + if (std::isinf(dfVal)) return CPL_VALUE_STRING; } diff --git a/scripts/detect_missing_include.sh b/scripts/detect_missing_include.sh index 74d9e03e2796..e9d3b2da0f0a 100755 --- a/scripts/detect_missing_include.sh +++ b/scripts/detect_missing_include.sh @@ -63,6 +63,20 @@ else echo "OK." fi +echo "Checking for missing #include statements..." +rm -f /tmp/missing_include.txt +while read -r i; do + grep -e std::isnan -e std::isinf -e std::isfinite $i >/dev/null && (grep "#include " $i >/dev/null || echo $i) | tee -a /tmp/missing_include.txt; +done < /tmp/gdal_list_files.txt + + +if test -s /tmp/missing_include.txt; then + echo "FAIL: missing #include in above listed files" + ret_code=1 +else + echo "OK." +fi + rm -f /tmp/missing_include.txt rm -f /tmp/gdal_list_files.txt