60 void* p = (
void*) &x2;
61 float *pf = (
float*) p;
69 double *pf = (
double*) p;
81 default:
fatal(
"ieee_interpret_float_value(): "
82 "unimplemented format %i\n", fmt);
85 fvp->
nan = isnan(fvp->
f);
87 int n_frac = 0, n_exp = 0;
88 int i, nan, sign = 0, exponent;
93 case IEEE_FMT_S: n_frac = 23; n_exp = 8;
break;
94 case IEEE_FMT_W: n_frac = 31; n_exp = 0;
break;
95 case IEEE_FMT_D: n_frac = 52; n_exp = 11;
break;
96 case IEEE_FMT_L: n_frac = 63; n_exp = 0;
break;
97 default:
fatal(
"ieee_interpret_float_value(): "
98 "unimplemented format %i\n", fmt);
111 exponent = (x >> n_frac) & ((1 << n_exp) - 1);
112 exponent -= (1 << (n_exp-1)) - 1;
114 default:
fatal(
"ieee_interpret_float_value(): unimplemented "
122 sign = (x >> 31) & 1;
123 if ((x & ~0x80000000ULL) == 0x7f800000ULL) {
125 goto zero_or_no_reasonable_result;
127 if ((x & 0x7f800000ULL) == 0x7f800000ULL)
131 sign = (x >> 63) & 1;
132 if ((x & ~0x8000000000000000ULL) == 0x7ff0000000000000ULL) {
134 goto zero_or_no_reasonable_result;
136 if ((x & 0x7ff0000000000000ULL) == 0x7ff0000000000000ULL)
143 goto no_reasonable_result;
168 (fmt ==
IEEE_FMT_D && x == 0x8000000000000000ULL) ||
171 goto zero_or_no_reasonable_result;
175 for (i=0; i<n_frac; i++) {
176 int bit = (x >> i) & 1;
183 fraction = (fraction / 2.0) + 1.0;
186 default:
fatal(
"ieee_interpret_float_value(): "
187 "unimplemented format %i\n", fmt);
194 fatal(
"{ ieee: x=%016"PRIx64
" => sign=%i exponent=%i frac=%f ",
195 (uint64_t) x, sign, exponent, fraction);
208 if (exponent == 1024)
211 while (exponent-- > 0)
213 }
else if (exponent < 0) {
214 while (exponent++ < 0)
218 zero_or_no_reasonable_result:
222 no_reasonable_result:
226 fatal(
"nan=%i (f=%f) }\n", nan, fvp->
f);
240 int n_frac = 0, n_exp = 0, signofs = 0, i, exponent;
246 case IEEE_FMT_S: n_frac = 23; n_exp = 8; signofs = 31;
break;
247 case IEEE_FMT_W: n_frac = 31; n_exp = 0; signofs = 31;
break;
248 case IEEE_FMT_D: n_frac = 52; n_exp = 11; signofs = 63;
break;
249 case IEEE_FMT_L: n_frac = 63; n_exp = 0; signofs = 63;
break;
250 default:
fatal(
"ieee_store_float_value(): unimplemented format"
270 r |= ((uint64_t)1 << signofs);
274 switch (fpclassify(nf)) {
277 r |= 0x7ff0000000000000ULL;
283 r |= 0x7fffffffffffffffULL;
300 while (nf < 1.0 && exponent > -1023) {
304 while (nf >= 2.0 && exponent < 1023) {
311 for (i=n_frac-1; i>=0; i--) {
314 r |= ((uint64_t)1 << i);
321 exponent += (((uint64_t)1 << (n_exp-1)) - 1);
324 if (exponent >= ((int64_t)1 << n_exp))
325 exponent = ((int64_t)1 << n_exp) - 1;
326 r |= (uint64_t)exponent << n_frac;
341 fatal(
"ieee_store_float_value(): unimplemented format %i\n",