Skip to content

Commit

Permalink
With C++23 and __STDCPP_FLOAT16_T__, make GFloat16 an alias of std::f…
Browse files Browse the repository at this point in the history
…loat16_t
  • Loading branch information
rouault committed Nov 8, 2024
1 parent f6c74ec commit 66b1b09
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions port/cpl_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
#include <cstdint>
#include <cstring>
#include <limits>
#if defined(__STDCPP_FLOAT16_T__)
#include <stdfloat>
#endif
#endif

CPL_C_START
Expand All @@ -70,6 +73,8 @@ GUInt16 CPL_DLL CPLFloatToHalf(GUInt32 iFloat32, bool &bHasWarned);
GUInt16 CPL_DLL CPLConvertFloatToHalf(float fFloat32);
float CPL_DLL CPLConvertHalfToFloat(GUInt16 nHalf);

#if !defined(__STDCPP_FLOAT16_T__)

namespace cpl
{

Expand Down Expand Up @@ -538,7 +543,13 @@ struct CPLFloat16
//! @endcond
} // namespace cpl

#endif // !defined(__STDCPP_FLOAT16_T__)

#ifdef __STDCPP_FLOAT16_T__
using GFloat16 = std::float16_t;
#else
using GFloat16 = cpl::CPLFloat16;
#endif

// Define some GDAL wrappers. Their C equivalents are defined in `cpl_port.h`.
// (These wrappers are not necessary any mroe in C++, one can always
Expand Down Expand Up @@ -567,6 +578,7 @@ template <typename T> constexpr int CPLIsFinite(T x)
return isfinite(x);
}

#if !defined(__STDCPP_FLOAT16_T__)
namespace std
{

Expand Down Expand Up @@ -627,6 +639,7 @@ template <> struct numeric_limits<cpl::CPLFloat16>
//! @endcond

} // namespace std
#endif // !defined(__STDCPP_FLOAT16_T__)

#endif

Expand Down

0 comments on commit 66b1b09

Please sign in to comment.