36 #define INFINITY 1.0/0.0
59 int binary16 = (u.
i & 0x80000000) >> 16;
61 int expon = (u.
i & 0x7f800000) >> 23;
64 return binary16 | 0x7e00;
77 binary16 |= expon << 10;
78 binary16 |= (u.
i & 0x007FFFFF) >> 13;
86 s = (u.
i & ((1<<11)-1)) ? 1 : 0;
87 if(g && (l || (r||s)))
102 static const uint32_t half_inf_mask = 0x7C00;
103 static const uint32_t half_mant_mask = 0x03FF;
104 static const uint32_t float_inf_mask = 0x7F800000;
107 uint32_t exp = (value.
getBinaryRep() & half_inf_mask) >> 10;
108 uint32_t mant = (value.
getBinaryRep() & half_mant_mask);
111 u.
u = sign | float_inf_mask | mant << 13;
115 if ((exp == 0 && mant != 0)) {
118 while (!(mant & 0x400)) {
123 u.
u = sign | exp << 23 | mant << 13;
126 u.
u = sign | (exp-15+127) << 23 | mant << 13;
131 #pragma GCC diagnostic warning "-Wstrict-aliasing"
144 binaryRep_(convertFloatToHalfWordRep(value)) {}
148 binaryRep_(hw.binaryRep_) {}
150 #pragma GCC diagnostic ignored "-Wdiv-by-zero"
152 HalfFloatWord::operator float()
const {
153 if (binaryRep_ == 0xFC00) {
156 if (binaryRep_ == 0x7C00) {
160 bool sgn = ((binaryRep_ & 0x8000) >> 15);
161 int exp = (binaryRep_ & 0x7C00) >> 10;
162 int mant = binaryRep_ & 0x03FF;
164 if (exp == 0x1F && mant != 0) {
168 float value = (exp == 0) ? mant : mant | 0x0400;
170 float mul = exp2(exp - 15);
179 #pragma GCC diagnostic warning "-Wdiv-by-zero"