7 #ifndef PXR_BASE_GF_NUMERIC_CAST_H
8 #define PXR_BASE_GF_NUMERIC_CAST_H
17 #include <type_traits>
28 template <
class T,
class U>
32 static_assert(std::is_integral_v<T> && std::is_integral_v<U>);
34 if constexpr (std::is_signed_v<T> == std::is_signed_v<U>) {
37 else if constexpr (std::is_signed_v<T>) {
73 template <
class To,
class From>
80 using FromLimits = std::numeric_limits<From>;
81 using ToLimits = std::numeric_limits<To>;
90 if constexpr (std::is_integral_v<From> &&
91 std::is_integral_v<To>) {
102 return static_cast<To
>(from);
106 std::is_integral_v<To>) {
108 if (std::isnan(from)) {
113 if (std::isinf(from)) {
126 From low =
static_cast<From
>(ToLimits::lowest()) - static_cast<From>(1);
127 From high =
static_cast<From
>(
ToLimits::max()) + static_cast<From>(1);
138 return static_cast<To
>(from);
145 return static_cast<To
>(from);
151 #endif // PXR_BASE_GF_NUMERIC_CAST_H
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Value too high to convert.
PXR_NAMESPACE_OPEN_SCOPE constexpr bool GfIntegerCompareLess(T t, U u) noexcept
std::optional< To > GfNumericCast(From from, GfNumericCastFailureType *failType=nullptr)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define PXR_NAMESPACE_CLOSE_SCOPE
Value is a floating-point NaN.
Value too low to convert.