Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * return (*acc) scaled by 10**dexp.
  3.  */
  4.  
  5. #include <_ansi.h>
  6. #include <reent.h>
  7. #include "std.h"
  8.  
  9. #define abs(x) (((x) < 0) ? -(x) : (x))
  10.  
  11. double
  12. _DEFUN (__adjust, (ptr, acc, dexp, sign),
  13.         struct _reent *ptr _AND
  14.         double *acc _AND
  15.         int dexp _AND
  16.         int sign)
  17.      /* *acc    the 64 bit accumulator */
  18.      /* dexp    decimal exponent       */
  19.      /* sign    sign flag              */
  20. {
  21.   double r;
  22.  
  23.   if (dexp > MAXE)
  24.     {
  25.       ptr->_errno = ERANGE;
  26.       return (sign) ? -HUGE_VAL : HUGE_VAL;
  27.     }
  28.   else if (dexp < MINE)
  29.     {
  30.       ptr->_errno = ERANGE;
  31.       return 0.0;
  32.     }
  33.  
  34.   r = *acc;
  35.   if (sign)
  36.     r = -r;
  37.   if (dexp == 0)
  38.     return r;
  39.  
  40.   if (dexp < 0)
  41.     return r / __exp10 (abs (dexp));
  42.   else
  43.     return r * __exp10 (dexp);
  44. }
  45.