32 #ifndef HalfFloat_INCLUDE_ONCE 33 #define HalfFloat_INCLUDE_ONCE 55 operator float()
const 60 operator double()
const 70 operator long long()
const 123 return (
bits & ((1 << 15)-1)) == 0;
126 operator bool()
const 205 unsigned int mantissa = (
unsigned int) (
bits & (( 1 << 10) - 1) );
206 unsigned int exp = (
unsigned int) (
bits & HALF_FLOAT_MAX_BIASED_EXP);
207 return exp == HALF_FLOAT_MAX_BIASED_EXP && mantissa != 0;
212 unsigned int mantissa = (
unsigned int) (
bits & (( 1 << 10) - 1) );
213 unsigned int exp = (
unsigned int) (
bits & HALF_FLOAT_MAX_BIASED_EXP);
214 return exp == HALF_FLOAT_MAX_BIASED_EXP && mantissa == 0;
219 unsigned int sign = (
unsigned int) (
bits >> 15);
220 unsigned int mantissa = (
unsigned int) (
bits & (( 1 << 10) - 1) );
221 unsigned int exp = (
unsigned int) (
bits & HALF_FLOAT_MAX_BIASED_EXP);
222 return exp == HALF_FLOAT_MAX_BIASED_EXP && mantissa == 0 && sign == 0;
227 unsigned int sign = (
unsigned int) (
bits >> 15);
228 unsigned int mantissa = (
unsigned int) (
bits & (( 1 << 10) - 1) );
229 unsigned int exp = (
unsigned int) (
bits & HALF_FLOAT_MAX_BIASED_EXP);
230 return exp == HALF_FLOAT_MAX_BIASED_EXP && mantissa == 0 && sign == 1;
235 unsigned int mantissa = (
unsigned int) (
bits & (( 1 << 10) - 1) );
236 unsigned int exp = (
unsigned int) (
bits & HALF_FLOAT_MAX_BIASED_EXP);
237 return exp == 0 && mantissa != 0;
251 h.
bits = HALF_FLOAT_MAX_BIASED_EXP;
258 h.
bits = HALF_FLOAT_MAX_BIASED_EXP | (( 1 << 10) - 1);
264 for(
int i=0; i<count; ++i)
270 for(
int i=0; i<count; ++i)
276 union {
float f;
unsigned int x; } val;
278 unsigned int sign = (
unsigned short)(val.x>>31);
279 unsigned int mantissa = val.x & ((1 << 23)-1);
280 unsigned int exp = val.x & FLOAT_MAX_BIASED_EXP;
281 typedef unsigned short hfloat;
284 if (exp >= HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP)
287 if (mantissa && (exp == FLOAT_MAX_BIASED_EXP))
290 mantissa = (1<<23) - 1;
297 hf.
bits = (((hfloat)sign) << 15) | (hfloat)(HALF_FLOAT_MAX_BIASED_EXP) | (hfloat)(mantissa >> 13);
301 if (exp <= HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP)
304 exp = (HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP -
exp) >> 23;
305 mantissa >>= (14 +
exp);
306 hf.
bits = (((hfloat)sign) << 15) | (hfloat)(mantissa);
310 hf.
bits = (((hfloat)sign)<<15) |
311 (hfloat)((exp - HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP) >> 13) |
312 (hfloat)(mantissa >> 13);
319 unsigned short hf = h.
bits;
320 unsigned int sign = (
unsigned int) ( hf >> 15);
321 unsigned int mantissa = (
unsigned int) (hf & (( 1 << 10) - 1) );
322 unsigned int exp = (
unsigned int) (hf & HALF_FLOAT_MAX_BIASED_EXP);
324 if (exp == HALF_FLOAT_MAX_BIASED_EXP)
329 exp = FLOAT_MAX_BIASED_EXP;
331 mantissa = (1 << 23 ) - 1;
339 exp = HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP;
341 while ((mantissa & (1 << 10) ) == 0)
349 mantissa &= (( 1 << 10) - 1);
359 exp = ( exp << 13) + HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP;
361 union {
float f;
unsigned int x; } val;
362 val.x = ( sign << 31) | exp | mantissa;
368 for(
int i=0; i<count; ++i)
370 union {
float f;
unsigned int x; } val;
372 unsigned int sign = (
unsigned short)(val.x>>31);
373 unsigned int mantissa = val.x & ((1 << 23)-1);
374 unsigned int exp = val.x & FLOAT_MAX_BIASED_EXP;
375 typedef unsigned short hfloat;
376 hfloat& hf = h[i].
bits;
378 if (exp >= HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP)
381 if (mantissa && (exp == FLOAT_MAX_BIASED_EXP))
384 mantissa = (1<<23) - 1;
391 hf = (((hfloat)sign) << 15) | (hfloat)(HALF_FLOAT_MAX_BIASED_EXP) | (hfloat)(mantissa >> 13);
395 if (exp <= HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP)
398 exp = (HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP -
exp) >> 23;
399 mantissa >>= (14 +
exp);
400 hf = (((hfloat)sign) << 15) | (hfloat)(mantissa);
404 hf = (((hfloat)sign)<<15) |
405 (hfloat)((exp - HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP) >> 13) |
406 (hfloat)(mantissa >> 13);
413 for(
int i=0; i<count; ++i)
415 const unsigned short& hf = h[i].
bits;
416 unsigned int sign = (
unsigned int) ( hf >> 15);
417 unsigned int mantissa = (
unsigned int) (hf & (( 1 << 10) - 1) );
418 unsigned int exp = (
unsigned int) (hf & HALF_FLOAT_MAX_BIASED_EXP);
420 if (exp == HALF_FLOAT_MAX_BIASED_EXP)
425 exp = FLOAT_MAX_BIASED_EXP;
427 mantissa = (1 << 23 ) - 1;
435 exp = HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP;
437 while ((mantissa & (1 << 10) ) == 0)
445 mantissa &= (( 1 << 10) - 1);
455 exp = ( exp << 13) + HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP;
457 union {
float f;
unsigned int x; } val;
458 val.x = ( sign << 31) | exp | mantissa;
468 static const unsigned int HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP = 0x38000000;
472 static const unsigned int HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP = 0x47800000;
475 static const unsigned int FLOAT_MAX_BIASED_EXP = (0xFF << 23);
476 static const unsigned int HALF_FLOAT_MAX_BIASED_EXP = (0x1F << 10);
bool operator==(const half &other) const
bool operator==(const double &other) const
half operator+(const half &other) const
static void convertDoubleToHalf(const double *d, half *h, int count)
static void convertFloatToHalf(const float *f, half *h, int count)
bool operator==(const long long &other) const
half operator/(const half &other) const
The Matrix2 class is a template class that implements a generic 2x2 matrix, see also vl::dmat2...
bool operator!=(const int &other) const
T_Scalar lengthSquared() const
bool operator==(const float &other) const
static half convertFloatToHalf(float f)
The Vector4 class is a template class that implements a generic 4 components vector, see also vl::fvec4, vl::dvec4, vl::uvec4, vl::ivec4, vl::svec4, vl::usvec4, vl::bvec4, vl::ubvec4.
bool operator!=(const half &other) const
T_Scalar lengthSquared() const
bool operator<(const half &other) const
Visualization Library main namespace.
Represents an half-precision floating point value.
static float convertHalfToFloat(const half &h)
bool operator!=(const float &other) const
The Matrix3 class is a template class that implements a generic 3x3 matrix, see also vl::dmat3...
half & operator+=(const half &other)
static void convertHalfToDouble(const half *h, double *d, int count)
T_Scalar lengthSquared() const
The Vector3 class is a template class that implements a generic 3 components vector, see also vl::fvec3, vl::dvec3, vl::uvec3, vl::ivec3, vl::svec3, vl::usvec3, vl::bvec3, vl::ubvec3.
bool operator!=(const long long &other) const
bool operator==(const int &other) const
half operator-(const half &other) const
The Matrix4 class is a template class that implements a generic 4x4 matrix, see also vl::dmat4...
half & operator-=(const half &other)
bool operator!=(const double &other) const
The Vector2 class is a template class that implements a generic 2 components vector, see also vl::fvec2, vl::dvec2, vl::uvec2, vl::ivec2, vl::svec2, vl::usvec2, vl::bvec2, vl::ubvec2.
half & operator/=(const half &other)
static void convertHalfToFloat(const half *h, float *f, int count)
bool operator>(const half &other) const
half & operator*=(const half &other)
half operator*(const half &other) const
half & operator=(const half &other)