- /*
- * The floating point formats we support have:
- * Bit 15 is sign bit.
- * Bits 14:n are excess-whatever exponent.
- * Bits n-1:0 (if any) are most significant bits of fraction.
- * Bits 15:0 of the next word(s) are the next most significant bits.
- *
- * So we need: number of bits of exponent, number of bits of
- * mantissa.
- */
- bits_left_in_littlenum = LITTLENUM_NUMBER_OF_BITS;
- littlenum_pointer = generic_floating_point_number.leader;
- littlenums_left = 1+generic_floating_point_number.leader - generic_floating_point_number.low;
- /* Seek (and forget) 1st significant bit */
- for (exponent_skippage = 0;! next_bits(1); exponent_skippage ++)
- ;
- exponent_1 = generic_floating_point_number.exponent + generic_floating_point_number.leader + 1 -
- generic_floating_point_number.low;
- /* Radix LITTLENUM_RADIX, point just higher than generic_floating_point_number.leader. */
- exponent_2 = exponent_1 * LITTLENUM_NUMBER_OF_BITS;
- /* Radix 2. */
- exponent_3 = exponent_2 - exponent_skippage;
- /* Forget leading zeros, forget 1st bit. */
- exponent_4 = exponent_3 + ((1 << (exponent_bits - 1)) - 2);
- /* Offset exponent. */
-
- lp = words;
-
- /* Word 1. Sign, exponent and perhaps high bits. */
- word1 = (generic_floating_point_number.sign == '+') ? 0 : (1<<(LITTLENUM_NUMBER_OF_BITS-1));
-
- /* Assume 2's complement integers. */
- if(exponent_4<1 && exponent_4>=-62) {
- int prec_bits;
- int num_bits;
-
- unget_bits(1);
- num_bits= -exponent_4;
- prec_bits=LITTLENUM_NUMBER_OF_BITS*precision-(exponent_bits+1+num_bits);
- if(precision==X_PRECISION && exponent_bits==15)
- prec_bits-=LITTLENUM_NUMBER_OF_BITS+1;
-
- if(num_bits>=LITTLENUM_NUMBER_OF_BITS-exponent_bits) {
- /* Bigger than one littlenum */
- num_bits-=(LITTLENUM_NUMBER_OF_BITS-1)-exponent_bits;
- *lp++=word1;
- if(num_bits+exponent_bits+1>=precision*LITTLENUM_NUMBER_OF_BITS) {
- /* Exponent overflow */
- make_invalid_floating_point_number(words);
- return return_value;
- }
- if(precision==X_PRECISION && exponent_bits==15) {
- *lp++=0;
- *lp++=0;
- num_bits-=LITTLENUM_NUMBER_OF_BITS-1;
- }
- while(num_bits>=LITTLENUM_NUMBER_OF_BITS) {
- num_bits-=LITTLENUM_NUMBER_OF_BITS;
- *lp++=0;
- }
- if(num_bits)
- *lp++=next_bits(LITTLENUM_NUMBER_OF_BITS-(num_bits));
- } else {
- if(precision==X_PRECISION && exponent_bits==15) {
- *lp++=word1;
- *lp++=0;
- if(num_bits==LITTLENUM_NUMBER_OF_BITS) {
- *lp++=0;
- *lp++=next_bits(LITTLENUM_NUMBER_OF_BITS-1);
- } else if(num_bits==LITTLENUM_NUMBER_OF_BITS-1)
- *lp++=0;
- else
- *lp++=next_bits(LITTLENUM_NUMBER_OF_BITS-1-num_bits);
- num_bits=0;
- } else {
- word1|= next_bits ((LITTLENUM_NUMBER_OF_BITS-1) - (exponent_bits+num_bits));
- *lp++=word1;
- }
- }
- while(lp<words+precision)
- *lp++=next_bits(LITTLENUM_NUMBER_OF_BITS);
-
- /* Round the mantissa up, but don't change the number */
- if(next_bits(1)) {
- --lp;
- if(prec_bits>LITTLENUM_NUMBER_OF_BITS) {
- int n = 0;
- int tmp_bits;
-
- n=0;
- tmp_bits=prec_bits;
- while(tmp_bits>LITTLENUM_NUMBER_OF_BITS) {
- if(lp[n]!=(LITTLENUM_TYPE)-1)
- break;
- --n;
- tmp_bits-=LITTLENUM_NUMBER_OF_BITS;
- }
- if(tmp_bits>LITTLENUM_NUMBER_OF_BITS || (lp[n]&mask[tmp_bits])!=mask[tmp_bits]) {
- unsigned long carry;
-
- for (carry = 1; carry && (lp >= words); lp --) {
- carry = * lp + carry;
- * lp = carry;
- carry >>= LITTLENUM_NUMBER_OF_BITS;
- }
- }
- } else if((*lp&mask[prec_bits])!=mask[prec_bits])
- lp++;
- }