Page 276 - ARM 64 Bit Assembly Language
P. 276

Non-integral mathematics 265


                   55     {
                   56       if(negative)
                   57         value = -value;
                   58       return value << frac_bits;
                   59     }
                   60   ++point;
                   61   /* convert the remaining part into an unpacked BCD number. */
                   62   for(i=(MAX_DECIMAL_DIGITS-1);i>=0;i--)
                   63     {
                   64       if(*point == 0)
                   65         digits[i] = 0;
                   66       else
                   67         {
                   68           digits[i] = *point - ’0’;
                   69           ++point;
                   70         }
                   71     }
                   72   /* convert the unpacked BCD number into binary */
                   73   while(frac_bits > 0)
                   74     {
                   75       value <<= 1;
                   76       if(base10double(digits))
                   77         value |= 1;
                   78       frac_bits--;
                   79     }
                   80   /* negate if there was a leading ’-’ */
                   81   if(negative)
                   82     value = -value;
                   83   return value;
                   84  }
                   85
                   86  // Round a packed BCD fraction
                   87  int roundit(int *digits, int current)
                   88  {
                   89   while(current > 0)
                   90     {
                   91       if(digits[current] > 9)
                   92         {
                   93           digits[current] %= 10;
                   94           digits[current-1]++;
                   95         }
                   96       current--;
                   97     }
                   98   if((current == 0)&&(digits[current] > 9))
                   99     {
                   100      digits[current] %= 10;
                   101      return 1;
                   102    }
                   103  return 0;
   271   272   273   274   275   276   277   278   279   280   281