89 #include "pxr/base/gf/api.h" 93 PXR_NAMESPACE_OPEN_SCOPE
109 constexpr half (
const half &) noexcept =
default;
110 constexpr half (half &&) noexcept = default;
116 operator
float () const;
123 half operator - () const;
130 half & operator = (const half &h) = default;
131 half & operator = (half &&h) noexcept = default;
132 half & operator = (
float f);
134 half & operator += (half h);
135 half & operator += (
float f);
137 half & operator -= (half h);
138 half & operator -= (
float f);
140 half & operator *= (half h);
141 half & operator *= (
float f);
143 half & operator /= (half h);
144 half & operator /= (
float f);
153 half round (
unsigned int n) const;
177 bool isFinite () const;
178 bool isNormalized () const;
179 bool isDenormalized () const;
180 bool isZero () const;
182 bool isInfinity () const;
183 bool isNegative () const;
200 static half posInf ();
201 static half negInf ();
210 GF_API
unsigned short bits () const;
211 GF_API
void setBits (
unsigned short bits);
224 GF_API
static short convert (
int i);
225 GF_API
static float overflow ();
229 GF_API
static const uif _toFloat[1 << 16];
230 GF_API
static const unsigned short _eLut[1 << 9];
239 GF_API std::ostream &
operator << (std::ostream &os, half h);
240 GF_API std::istream & operator >> (std::istream &is, half &h);
247 GF_API
void printBits (std::ostream &os, half h);
248 GF_API
void printBits (std::ostream &os,
float f);
249 GF_API
void printBits (
char c[19], half h);
250 GF_API
void printBits (
char c[35],
float f);
261 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER 263 #define PXR_HALF_MIN 5.96046448e-08f // Smallest positive half 265 #define PXR_HALF_NRM_MIN 6.10351562e-05f // Smallest positive normalized half 267 #define PXR_HALF_MAX 65504.0f // Largest positive half 269 #define PXR_HALF_EPSILON 0.00097656f // Smallest positive e for which 273 #define PXR_HALF_MIN 5.96046448e-08 // Smallest positive half 275 #define PXR_HALF_NRM_MIN 6.10351562e-05 // Smallest positive normalized half 277 #define PXR_HALF_MAX 65504.0 // Largest positive half 279 #define PXR_HALF_EPSILON 0.00097656 // Smallest positive e for which 284 #define PXR_HALF_MANT_DIG 11 // Number of digits in mantissa 289 #define PXR_HALF_DIG 3 // Number of base 10 digits that 293 #define PXR_HALF_DECIMAL_DIG 5 // Number of base-10 digits that are 297 #define PXR_HALF_RADIX 2 // Base of the exponent 299 #define PXR_HALF_MIN_EXP -13 // Minimum negative integer such that 304 #define PXR_HALF_MAX_EXP 16 // Maximum positive integer such that 309 #define PXR_HALF_MIN_10_EXP -4 // Minimum positive integer such 313 #define PXR_HALF_MAX_10_EXP 4 // Maximum positive integer such 468 int e = (x.i >> 23) & 0x000001ff;
479 int m = x.i & 0x007fffff;
480 _h = e + ((m + 0x00000fff + ((m >> 13) & 1)) >> 13);
499 half::operator float ()
const 501 return _toFloat[_h].f;
510 half::round (
unsigned int n)
const 524 unsigned short s = _h & 0x8000;
525 unsigned short e = _h & 0x7fff;
569 half::operator - ()
const 578 half::operator = (
float f)
586 half::operator += (half h)
588 *
this = half (
float (*
this) +
float (h));
594 half::operator += (
float f)
596 *
this = half (
float (*
this) + f);
602 half::operator -= (half h)
604 *
this = half (
float (*
this) -
float (h));
610 half::operator -= (
float f)
612 *
this = half (
float (*
this) - f);
618 half::operator *= (half h)
620 *
this = half (
float (*
this) *
float (h));
626 half::operator *= (
float f)
628 *
this = half (
float (*
this) * f);
634 half::operator /= (half h)
636 *
this = half (
float (*
this) /
float (h));
642 half::operator /= (
float f)
644 *
this = half (
float (*
this) / f);
650 half::isFinite ()
const 652 unsigned short e = (_h >> 10) & 0x001f;
658 half::isNormalized ()
const 660 unsigned short e = (_h >> 10) & 0x001f;
661 return e > 0 && e < 31;
666 half::isDenormalized ()
const 668 unsigned short e = (_h >> 10) & 0x001f;
669 unsigned short m = _h & 0x3ff;
670 return e == 0 && m != 0;
675 half::isZero ()
const 677 return (_h & 0x7fff) == 0;
684 unsigned short e = (_h >> 10) & 0x001f;
685 unsigned short m = _h & 0x3ff;
686 return e == 31 && m != 0;
691 half::isInfinity ()
const 693 unsigned short e = (_h >> 10) & 0x001f;
694 unsigned short m = _h & 0x3ff;
695 return e == 31 && m == 0;
700 half::isNegative ()
const 702 return (_h & 0x8000) != 0;
742 inline unsigned short 750 half::setBits (
unsigned short bits)
757 PXR_NAMESPACE_CLOSE_SCOPE
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].