2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright Contributors to the OpenEXR Project.
7 // Primary original authors:
8 // Florian Kainz <kainz@ilm.com>
9 // Rod Bogart <rgb@ilm.com>
12 //---------------------------------------------------------------------------
15 // implementation of non-inline members
17 //---------------------------------------------------------------------------
24 #if defined(IMATH_DLL)
25 # define EXPORT_CONST __declspec(dllexport)
30 //-------------------------------------------------------------
31 // Lookup tables for half-to-float and float-to-half conversion
32 //-------------------------------------------------------------
36 #if !defined(IMATH_HALF_NO_LOOKUP_TABLE)
37 // Omit the table entirely if IMATH_HALF_NO_LOOKUP_TABLE is
38 // defined. Half-to-float conversion must be accomplished either by
39 // F16C instructions or the bit-shift algorithm.
40 const imath_half_uif_t imath_half_to_float_table_data[1 << 16] =
44 EXPORT_CONST const imath_half_uif_t *imath_half_to_float_table = imath_half_to_float_table_data;
51 //---------------------
52 // Stream I/O operators
53 //---------------------
56 operator<< (ostream& os, half h)
63 operator>> (istream& is, half& h)
71 //---------------------------------------
72 // Functions to print the bit-layout of
73 // floats and halfs, mostly for debugging
74 //---------------------------------------
77 printBits (ostream& os, half h)
79 unsigned short b = h.bits();
81 for (int i = 15; i >= 0; i--)
83 os << (((b >> i) & 1) ? '1' : '0');
85 if (i == 15 || i == 10)
91 printBits (ostream& os, float f)
96 for (int i = 31; i >= 0; i--)
98 os << (((x.i >> i) & 1) ? '1' : '0');
100 if (i == 31 || i == 23)
106 printBits (char c[19], half h)
108 unsigned short b = h.bits();
110 for (int i = 15, j = 0; i >= 0; i--, j++)
112 c[j] = (((b >> i) & 1) ? '1' : '0');
114 if (i == 15 || i == 10)
122 printBits (char c[35], float f)
127 for (int i = 31, j = 0; i >= 0; i--, j++)
129 c[j] = (((x.i >> i) & 1) ? '1' : '0');
131 if (i == 31 || i == 23)