The half Class¶
-
class
half
¶ class half represents a 16-bit floating point number
Type half can represent positive and negative numbers whose magnitude is between roughly 6.1e-5 and 6.5e+4 with a relative error of 9.8e-4; numbers smaller than 6.1e-5 can be represented with an absolute error of 6.0e-8. All integers from -2048 to +2048 can be represented exactly.
Type half behaves (almost) like the built-in C++ floating point types. In arithmetic expressions, half, float and double can be mixed freely. Here are a few examples:
Conversions from half to float are lossless; all half numbers are exactly representable as floats.half a (3.5); float b (a + sqrt (a)); a += b; b += a; b = a + 7;
Conversions from float to half may not preserve a float’s value exactly. If a float is not representable as a half, then the float value is rounded to the nearest representable half. If a float value is exactly in the middle between the two closest representable half values, then the float value is rounded to the closest half whose least significant bit is zero.
Overflows during float-to-half conversions cause arithmetic exceptions. An overflow occurs when the float value to be converted is too large to be represented as a half, or if the float value is an infinity or a NAN.
The implementation of type half makes the following assumptions about the implementation of the built-in C++ types:
- float is an IEEE 754 single-precision number
- sizeof (float) == 4
- sizeof (unsigned int) == sizeof (float)
- alignof (unsigned int) == alignof (float)
- sizeof (uint16_t) == 2
Constructors
-
half
()¶ Default construction provides no initialization (hence it is not constexpr).
-
half
(float f)¶ Construct from float.
-
constexpr
half
(FromBitsTag, uint16_t bits)¶ Construct from bit-vector.
-
~half
()¶ Destructor.
Basic Algebra
Classification
-
constexpr bool
isFinite
() const¶ Return true if a normalized number, a denormalized number, or zero.
-
constexpr bool
isNormalized
() const¶ Return true if a normalized number.
-
constexpr bool
isDenormalized
() const¶ Return true if a denormalized number.
-
constexpr bool
isZero
() const¶ Return true if zero.
-
constexpr bool
isNan
() const¶ Return true if NAN.
-
constexpr bool
isInfinity
() const¶ Return true if a positive or a negative infinity.
-
constexpr bool
isNegative
() const¶ Return true if the sign bit is set (negative)
Access to the internal representation
-
constexpr uint16_t
bits
() const¶ Return the bit pattern.
-
constexpr void
setBits
(uint16_t bits)¶ Set the bit pattern.
Special values
Public Types
-
using
uif
= imath_half_uif¶
Warning
doxygenfunction: Unable to resolve multiple matches for function “operator<<” with arguments (std::ostream& os, Imath::half h) in doxygen xml output for project “Imath” from directory: /build/ilmbase-pisqTC/ilmbase-3.1.11/obj-x86_64-linux-gnu/website/doxygen/xml. Potential matches:
- std::ostream &operator<<(std::ostream&, Imath::half)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Color4<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Euler<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Interval<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Line3<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Matrix22<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Matrix33<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Matrix44<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Plane3<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Quat<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Shear6<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Vec2<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Vec3<T>&)
- template<class T>
std::ostream &Imath::operator<<(std::ostream&, const Vec4<T>&)