-
- size_t integer_leading_zeroes = 0;
- for (integer_leading_zeroes = 0; integer_leading_zeroes < max_bits; ++integer_leading_zeroes)
- {
- if ((integer >> (max_bits-1-integer_leading_zeroes)) & 1LL)
- break;
- }
- //Debug("%.16lx . %.16lx (%li, %li)", integer,fraction, integer_leading_zeroes, fraction_leading_zeroes);
-
- mantissa = (integer << (integer_leading_zeroes)); // shift integer part
- mantissa |= (fraction >> (max_bits-integer_leading_zeroes)); // append the fraction after it
- //Debug("%.16lx (%.16lx << %i)", mantissa, fraction, (fraction_leading_zeroes - max_bits + integer_leading_zeroes));
- mantissa = mantissa >> (max_bits - PREC); // shift back to the mantissa position
- biased_exponent = (max_bits - integer_leading_zeroes); // calculate exponent
+ mantissa = (fraction << (fraction_leading_zeroes));
+ }
+ //Debug("Mantissa with fraction %.16lx (%.16lx >><>?<< %lu)", mantissa, fraction, fraction_leading_zeroes);
+ mantissa = (mantissa >> (max_bits - PREC - 1));
+ //Debug("Mantissa is %.16lx (%.16lx . %.16lx)", mantissa, fraction, integer);
+ biased_exponent = (integer != 0) ? (max_bits - integer_leading_zeroes) : (-fraction_leading_zeroes);
+ if (biased_exponent < -(1LL << (EMAX-1))+1)
+ {
+ //Debug("Denormalising for glory or death! %li , %li", biased_exponent, -(1LL << (EMAX-1)) - biased_exponent + 1);
+ mantissa = mantissa >> (-(1LL << (EMAX-1)) - biased_exponent + 1);
+ biased_exponent = -(1LL << (EMAX-1))+1;