85 #ifndef OPENVDB_MATH_HALF_HAS_BEEN_INCLUDED 86 #define OPENVDB_MATH_HALF_HAS_BEEN_INCLUDED 89 #include <openvdb/version.h> 117 operator float ()
const;
131 half & operator = (
const half &h) =
default;
132 half & operator = (
half &&h) noexcept =
default;
133 half & operator = (
float f);
136 half & operator += (
float f);
139 half & operator -= (
float f);
142 half & operator *= (
float f);
145 half & operator /= (
float f);
154 half round (
unsigned int n)
const;
179 bool isNormalized ()
const;
180 bool isDenormalized ()
const;
183 bool isInfinity ()
const;
201 static half posInf ();
202 static half negInf ();
211 unsigned short bits ()
const;
212 void setBits (
unsigned short bits);
225 static short convert (
int i);
226 static float overflow ();
230 static const uif _toFloat[1 << 16];
231 static const unsigned short _eLut[1 << 9];
262 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER 264 #define VDB_HALF_MIN 5.96046448e-08f // Smallest positive half 266 #define VDB_HALF_NRM_MIN 6.10351562e-05f // Smallest positive normalized half 268 #define VDB_HALF_MAX 65504.0f // Largest positive half 270 #define VDB_HALF_EPSILON 0.00097656f // Smallest positive e for which 274 #define VDB_HALF_MIN 5.96046448e-08 // Smallest positive half 276 #define VDB_HALF_NRM_MIN 6.10351562e-05 // Smallest positive normalized half 278 #define VDB_HALF_MAX 65504.0 // Largest positive half 280 #define VDB_HALF_EPSILON 0.00097656 // Smallest positive e for which 285 #define VDB_HALF_MANT_DIG 11 // Number of digits in mantissa 290 #define VDB_HALF_DIG 3 // Number of base 10 digits that 294 #define VDB_HALF_DECIMAL_DIG 5 // Number of base-10 digits that are 298 #define VDB_HALF_RADIX 2 // Base of the exponent 300 #define VDB_HALF_MIN_EXP -13 // Minimum negative integer such that 305 #define VDB_HALF_MAX_EXP 16 // Maximum positive integer such that 310 #define VDB_HALF_MIN_10_EXP -4 // Minimum positive integer such 314 #define VDB_HALF_MAX_10_EXP 4 // Maximum positive integer such 449 _h = (
unsigned short)(x.
i >> 16);
469 int e = (x.
i >> 23) & 0x000001ff;
480 int m = x.
i & 0x007fffff;
481 _h = (
unsigned short)(e + ((m + 0x00000fff + ((m >> 13) & 1)) >> 13));
500 half::operator float ()
const 502 return _toFloat[_h].f;
511 half::round (
unsigned int n)
const 525 unsigned short s = _h & 0x8000;
526 unsigned short e = _h & 0x7fff;
535 e = (
unsigned short)(e >> (9 - n));
536 e = (
unsigned short)(e + (e & 1));
537 e = (
unsigned short)(e << (9 - n));
550 e = (
unsigned short)(e >> (10 - n));
551 e = (
unsigned short)(e << (10 - n));
559 h._h = (
unsigned short)(s | e);
579 half::operator = (
float f)
589 *
this =
half (
float (*
this) +
float (h));
595 half::operator += (
float f)
597 *
this =
half (
float (*
this) + f);
605 *
this =
half (
float (*
this) -
float (h));
611 half::operator -= (
float f)
613 *
this =
half (
float (*
this) - f);
621 *
this =
half (
float (*
this) *
float (h));
627 half::operator *= (
float f)
629 *
this =
half (
float (*
this) * f);
637 *
this =
half (
float (*
this) /
float (h));
643 half::operator /= (
float f)
645 *
this =
half (
float (*
this) / f);
653 unsigned short e = (_h >> 10) & 0x001f;
659 half::isNormalized ()
const 661 unsigned short e = (_h >> 10) & 0x001f;
662 return e > 0 && e < 31;
667 half::isDenormalized ()
const 669 unsigned short e = (_h >> 10) & 0x001f;
670 unsigned short m = _h & 0x3ff;
671 return e == 0 && m != 0;
678 return (_h & 0x7fff) == 0;
685 unsigned short e = (_h >> 10) & 0x001f;
686 unsigned short m = _h & 0x3ff;
687 return e == 31 && m != 0;
692 half::isInfinity ()
const 694 unsigned short e = (_h >> 10) & 0x001f;
695 unsigned short m = _h & 0x3ff;
696 return e == 31 && m == 0;
703 return (_h & 0x8000) != 0;
743 inline unsigned short 751 half::setBits (
unsigned short bits)
761 #endif // OPENVDB_MATH_HALF_HAS_BEEN_INCLUDED
bool isNan(const float x)
Return true if x is a NaN (Not-A-Number) value.
Definition: Math.h:396
OPENVDB_API void printBits(char c[35], float f)
bool isFinite(const float x)
Return true if x is finite.
Definition: Math.h:376
OPENVDB_API std::istream & operator>>(std::istream &is, half &h)
unsigned int i
Definition: Half.h:219
bool isNegative(const Type &x)
Return true if x is less than zero.
Definition: Math.h:368
Definition: Exceptions.h:13
Vec3< typename promote< T, Coord::ValueType >::type > operator-(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be subtracted from a Vec3.
Definition: Coord.h:550
float f
Definition: Half.h:220
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:338
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
internal::half half
Definition: Types.h:29
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202
OPENVDB_API std::ostream & operator<<(std::ostream &os, half h)