89#include "pxr/base/gf/api.h"
93PXR_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];
239GF_API std::ostream & operator << (std::ostream &os, half h);
240GF_API std::istream & operator >> (std::istream &is, half &h);
247GF_API
void printBits (std::ostream &os, half h);
248GF_API
void printBits (std::ostream &os,
float f);
249GF_API
void printBits (
char c[19], half h);
250GF_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
265 #define PXR_HALF_NRM_MIN 6.10351562e-05f
267 #define PXR_HALF_MAX 65504.0f
269 #define PXR_HALF_EPSILON 0.00097656f
273 #define PXR_HALF_MIN 5.96046448e-08
275 #define PXR_HALF_NRM_MIN 6.10351562e-05
277 #define PXR_HALF_MAX 65504.0
279 #define PXR_HALF_EPSILON 0.00097656
284#define PXR_HALF_MANT_DIG 11
289#define PXR_HALF_DIG 3
293#define PXR_HALF_DECIMAL_DIG 5
297#define PXR_HALF_RADIX 2
299#define PXR_HALF_MIN_EXP -13
304#define PXR_HALF_MAX_EXP 16
309#define PXR_HALF_MIN_10_EXP -4
313#define PXR_HALF_MAX_10_EXP 4
468 int e = (x.i >> 23) & 0x000001ff;
479 int m = x.i & 0x007fffff;
480 _h = e + ((m + 0x00000fff + ((m >> 13) & 1)) >> 13);
499half::operator float ()
const
501 return _toFloat[_h].f;
510half::round (
unsigned int n)
const
524 unsigned short s = _h & 0x8000;
525 unsigned short e = _h & 0x7fff;
569half::operator - ()
const
578half::operator = (
float f)
586half::operator += (half h)
588 *
this = half (
float (*
this) +
float (h));
594half::operator += (
float f)
596 *
this = half (
float (*
this) + f);
602half::operator -= (half h)
604 *
this = half (
float (*
this) -
float (h));
610half::operator -= (
float f)
612 *
this = half (
float (*
this) - f);
618half::operator *= (half h)
620 *
this = half (
float (*
this) *
float (h));
626half::operator *= (
float f)
628 *
this = half (
float (*
this) * f);
634half::operator /= (half h)
636 *
this = half (
float (*
this) /
float (h));
642half::operator /= (
float f)
644 *
this = half (
float (*
this) / f);
650half::isFinite ()
const
652 unsigned short e = (_h >> 10) & 0x001f;
658half::isNormalized ()
const
660 unsigned short e = (_h >> 10) & 0x001f;
661 return e > 0 && e < 31;
666half::isDenormalized ()
const
668 unsigned short e = (_h >> 10) & 0x001f;
669 unsigned short m = _h & 0x3ff;
670 return e == 0 && m != 0;
677 return (_h & 0x7fff) == 0;
684 unsigned short e = (_h >> 10) & 0x001f;
685 unsigned short m = _h & 0x3ff;
686 return e == 31 && m != 0;
691half::isInfinity ()
const
693 unsigned short e = (_h >> 10) & 0x001f;
694 unsigned short m = _h & 0x3ff;
695 return e == 31 && m == 0;
700half::isNegative ()
const
702 return (_h & 0x8000) != 0;
750half::setBits (
unsigned short bits)
757PXR_NAMESPACE_CLOSE_SCOPE