Skip to content

Commit 79d17c4

Browse files
authored
Merge pull request #12165 from rouault/float16_isnan
Fix build issues with isnan() on GFloat16
2 parents 754168f + 6f12ac7 commit 79d17c4

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

gcore/gdalnodatamaskband.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ bool GDALNoDataMaskBand::IsNoDataInRange(double dfNoDataValue,
188188

189189
case GDT_Float16:
190190
{
191-
return isnan(dfNoDataValue) || isinf(dfNoDataValue) ||
191+
return std::isnan(dfNoDataValue) || std::isinf(dfNoDataValue) ||
192192
GDALIsValueInRange<GFloat16>(dfNoDataValue);
193193
}
194194

gcore/gdalrasterband.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4078,7 +4078,7 @@ struct GDALNoDataValues
40784078
bGotFloat16NoDataValue(false), hfNoDataValue(GFloat16(0.0f))
40794079
{
40804080
dfNoDataValue = poRasterBand->GetNoDataValue(&bGotNoDataValue);
4081-
bGotNoDataValue = bGotNoDataValue && !CPLIsNan(dfNoDataValue);
4081+
bGotNoDataValue = bGotNoDataValue && !std::isnan(dfNoDataValue);
40824082

40834083
ComputeFloatNoDataValue(eDataType, dfNoDataValue, bGotNoDataValue,
40844084
fNoDataValue, bGotFloatNoDataValue);
@@ -4322,9 +4322,10 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets,
43224322
break;
43234323
case GDT_Float16:
43244324
{
4325+
using namespace std;
43254326
const GFloat16 hfValue =
43264327
static_cast<GFloat16 *>(pData)[iOffset];
4327-
if (CPLIsNan(hfValue) ||
4328+
if (isnan(hfValue) ||
43284329
(sNoDataValues.bGotFloat16NoDataValue &&
43294330
ARE_REAL_EQUAL(hfValue,
43304331
sNoDataValues.hfNoDataValue)))
@@ -4336,7 +4337,7 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets,
43364337
{
43374338
const float fValue =
43384339
static_cast<float *>(pData)[iOffset];
4339-
if (CPLIsNan(fValue) ||
4340+
if (std::isnan(fValue) ||
43404341
(sNoDataValues.bGotFloatNoDataValue &&
43414342
ARE_REAL_EQUAL(fValue,
43424343
sNoDataValues.fNoDataValue)))
@@ -4377,7 +4378,7 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets,
43774378
static_cast<GFloat16 *>(pData)[iOffset * 2];
43784379
const double dfImag =
43794380
static_cast<GFloat16 *>(pData)[iOffset * 2 + 1];
4380-
if (CPLIsNan(dfReal) || CPLIsNan(dfImag))
4381+
if (std::isnan(dfReal) || std::isnan(dfImag))
43814382
continue;
43824383
dfValue = sqrt(dfReal * dfReal + dfImag * dfImag);
43834384
break;
@@ -4593,9 +4594,10 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets,
45934594
break;
45944595
case GDT_Float16:
45954596
{
4597+
using namespace std;
45964598
const GFloat16 hfValue =
45974599
static_cast<GFloat16 *>(pData)[iOffset];
4598-
if (CPLIsNan(hfValue) ||
4600+
if (isnan(hfValue) ||
45994601
(sNoDataValues.bGotFloat16NoDataValue &&
46004602
ARE_REAL_EQUAL(hfValue,
46014603
sNoDataValues.hfNoDataValue)))
@@ -4607,7 +4609,7 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets,
46074609
{
46084610
const float fValue =
46094611
static_cast<float *>(pData)[iOffset];
4610-
if (CPLIsNan(fValue) ||
4612+
if (std::isnan(fValue) ||
46114613
(sNoDataValues.bGotFloatNoDataValue &&
46124614
ARE_REAL_EQUAL(fValue,
46134615
sNoDataValues.fNoDataValue)))
@@ -4644,7 +4646,7 @@ CPLErr GDALRasterBand::GetHistogram(double dfMin, double dfMax, int nBuckets,
46444646
static_cast<GFloat16 *>(pData)[iOffset * 2];
46454647
double dfImag =
46464648
static_cast<GFloat16 *>(pData)[iOffset * 2 + 1];
4647-
if (CPLIsNan(dfReal) || CPLIsNan(dfImag))
4649+
if (std::isnan(dfReal) || std::isnan(dfImag))
46484650
continue;
46494651
dfValue = sqrt(dfReal * dfReal + dfImag * dfImag);
46504652
break;
@@ -6306,9 +6308,10 @@ static inline double GetPixelValue(GDALDataType eDataType, bool bSignedByte,
63066308
break;
63076309
case GDT_Float16:
63086310
{
6311+
using namespace std;
63096312
const GFloat16 hfValue =
63106313
static_cast<const GFloat16 *>(pData)[iOffset];
6311-
if (CPLIsNan(hfValue) ||
6314+
if (isnan(hfValue) ||
63126315
(sNoDataValues.bGotFloat16NoDataValue &&
63136316
ARE_REAL_EQUAL(hfValue, sNoDataValues.hfNoDataValue)))
63146317
{
@@ -6321,7 +6324,7 @@ static inline double GetPixelValue(GDALDataType eDataType, bool bSignedByte,
63216324
case GDT_Float32:
63226325
{
63236326
const float fValue = static_cast<const float *>(pData)[iOffset];
6324-
if (CPLIsNan(fValue) ||
6327+
if (std::isnan(fValue) ||
63256328
(sNoDataValues.bGotFloatNoDataValue &&
63266329
ARE_REAL_EQUAL(fValue, sNoDataValues.fNoDataValue)))
63276330
{
@@ -6347,7 +6350,7 @@ static inline double GetPixelValue(GDALDataType eDataType, bool bSignedByte,
63476350
break;
63486351
case GDT_CFloat16:
63496352
dfValue = static_cast<const GFloat16 *>(pData)[iOffset * 2];
6350-
if (isnan(dfValue))
6353+
if (std::isnan(dfValue))
63516354
{
63526355
bValid = false;
63536356
return 0.0;

0 commit comments

Comments
 (0)