⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 floatconv.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 5 页
字号:
    malloc(BIGINT_HEADER_SIZE + x * sizeof(unsigned32));  rv->k = k;  rv->maxwds = x;  rv->sign = rv->wds = 0;  rv->on_stack = 0;  return rv;}static voidBfree#ifdef KR_headers        (v) Bigint *v;#else        (Bigint *v)#endif{  if (v && !v->on_stack)    free (v);}static voidBcopy#ifdef KR_headers        (x, y) Bigint *x, *y;#else        (Bigint *x, Bigint *y)#endif{  register unsigned32 *xp, *yp;  register int i = y->wds;  x->sign = y->sign;  x->wds = i;  for (xp = x->x, yp = y->x; --i >= 0; )    *xp++ = *yp++;}/* Make sure b has room for at least 1<<k big digits. */static Bigint *Brealloc#ifdef KR_headers        (b, k) Bigint *b; int k;#else        (Bigint * b, int k)#endif{  if (b == NULL)    return Balloc(k);  if (b->k >= k)    return b;  else    {      Bigint *rv = Balloc (k);      Bcopy(rv, b);      Bfree(b);      return rv;    }}/* Return b*m+a.  b is modified.   Assumption:  0xFFFF*m+a fits in 32 bits. */static Bigint *multadd#ifdef KR_headers        (b, m, a) Bigint *b; int m, a;#else        (Bigint *b, int m, int a)#endif{        int i, wds;        unsigned32 *x, y;        unsigned32 xi, z;        wds = b->wds;        x = b->x;        i = 0;        do {                xi = *x;                y = (xi & 0xffff) * m + a;                z = (xi >> 16) * m + (y >> 16);                a = (int)(z >> 16);                *x++ = (z << 16) + (y & 0xffff);                }                while(++i < wds);        if (a) {                if (wds >= b->maxwds)                        b = Brealloc(b, b->k+1);                b->x[wds++] = a;                b->wds = wds;                }        return b;        }static Bigint *s2b#ifdef KR_headers        (result, s, nd0, nd, y9)	Bigint *result; CONST char *s; int nd0, nd; unsigned32 y9;#else        (Bigint *result, CONST char *s, int nd0, int nd, unsigned32 y9)#endif{  int i, k;  _G_int32_t x, y;  x = (nd + 8) / 9;  for(k = 0, y = 1; x > y; y <<= 1, k++) ;  result = Brealloc(result, k);  result->x[0] = y9;  result->wds = 1;  i = 9;  if (9 < nd0)    {      s += 9;      do	result = multadd(result, 10, *s++ - '0');      while (++i < nd0);      s++;    }  else    s += 10;  for(; i < nd; i++)    result = multadd(result, 10, *s++ - '0');  return result;}static inthi0bits#ifdef KR_headers        (x) register unsigned32 x;#else        (register unsigned32 x)#endif{        register int k = 0;        if (!(x & 0xffff0000)) {                k = 16;                x <<= 16;                }        if (!(x & 0xff000000)) {                k += 8;                x <<= 8;                }        if (!(x & 0xf0000000)) {                k += 4;                x <<= 4;                }        if (!(x & 0xc0000000)) {                k += 2;                x <<= 2;                }        if (!(x & 0x80000000)) {                k++;                if (!(x & 0x40000000))                        return 32;                }        return k;        }static intlo0bits#ifdef KR_headers        (y) unsigned32 *y;#else        (unsigned32 *y)#endif{        register int k;        register unsigned32 x = *y;        if (x & 7) {                if (x & 1)                        return 0;                if (x & 2) {                        *y = x >> 1;                        return 1;                        }                *y = x >> 2;                return 2;                }        k = 0;        if (!(x & 0xffff)) {                k = 16;                x >>= 16;                }        if (!(x & 0xff)) {                k += 8;                x >>= 8;                }        if (!(x & 0xf)) {                k += 4;                x >>= 4;                }        if (!(x & 0x3)) {                k += 2;                x >>= 2;                }        if (!(x & 1)) {                k++;                x >>= 1;                if (!x & 1)                        return 32;                }        *y = x;        return k;        }static Bigint *i2b#ifdef KR_headers        (result, i) Bigint *result; int i;#else        (Bigint* result, int i)#endif{  result = Brealloc(result, 1);  result->x[0] = i;  result->wds = 1;  return result;}/* Do: c = a * b. */static Bigint *mult#ifdef KR_headers        (c, a, b) Bigint *a, *b, *c;#else        (Bigint *c, Bigint *a, Bigint *b)#endif{        int k, wa, wb, wc;        unsigned32 carry, y, z;        unsigned32 *x, *xa, *xae, *xb, *xbe, *xc, *xc0;        unsigned32 z2;        if (a->wds < b->wds) {                Bigint *tmp = a;                a = b;                b = tmp;                }        k = a->k;        wa = a->wds;        wb = b->wds;        wc = wa + wb;        if (wc > a->maxwds)                k++;	c = Brealloc(c, k);        for(x = c->x, xa = x + wc; x < xa; x++)                *x = 0;        xa = a->x;        xae = xa + wa;        xb = b->x;        xbe = xb + wb;        xc0 = c->x;        for(; xb < xbe; xb++, xc0++) {                if ((y = *xb & 0xffff)) {                        x = xa;                        xc = xc0;                        carry = 0;                        do {                                z = (*x & 0xffff) * y + (*xc & 0xffff) + carry;                                carry = z >> 16;                                z2 = (*x++ >> 16) * y + (*xc >> 16) + carry;                                carry = z2 >> 16;                                Storeinc(xc, z2, z);                                }                                while(x < xae);                        *xc = carry;                        }                if ((y = *xb >> 16)) {                        x = xa;                        xc = xc0;                        carry = 0;                        z2 = *xc;                        do {                                z = (*x & 0xffff) * y + (*xc >> 16) + carry;                                carry = z >> 16;                                Storeinc(xc, z, z2);                                z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry;                                carry = z2 >> 16;                                }                                while(x < xae);                        *xc = z2;                        }                }        for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ;        c->wds = wc;        return c;        }/* Returns b*(5**k).  b is modified. *//* Re-written by Per Bothner to not need a static list. */static Bigint *pow5mult#ifdef KR_headers        (b, k) Bigint *b; int k;#else        (Bigint *b, int k)#endif{  static int p05[6] = { 5, 25, 125, 625, 3125, 15625 };  for (; k > 6; k -= 6)    b = multadd(b, 15625, 0); /* b *= 5**6 */  if (k == 0)    return b;  else    return multadd(b, p05[k-1], 0);}/* Re-written by Per Bothner so shift can be in place. */static Bigint *lshift#ifdef KR_headers	(b, k) Bigint *b; int k;#else        (Bigint *b, int k)#endif{  int i;  unsigned32 *x, *x1, *xe;  int old_wds = b->wds;  int n = k >> 5;  int k1 = b->k;  int n1 = n + old_wds + 1;  if (k == 0)    return b;  for(i = b->maxwds; n1 > i; i <<= 1)    k1++;  b = Brealloc(b, k1);  xe = b->x; /* Source limit */  x = xe + old_wds; /* Source pointer */  x1 = x + n; /* Destination pointer */  if (k &= 0x1f) {    int k1 = 32 - k;    unsigned32 z = *--x;    if ((*x1 = (z >> k1)) != 0) {      ++n1;    }    while (x > xe) {      unsigned32 w = *--x;      *--x1 = (z << k) | (w >> k1);      z = w;    }    *--x1 = z << k;  }  else    do {      *--x1 = *--x;    } while(x > xe);  while (x1 > xe)    *--x1 = 0;  b->wds = n1 - 1;  return b;}static intcmp#ifdef KR_headers        (a, b) Bigint *a, *b;#else        (Bigint *a, Bigint *b)#endif{        unsigned32 *xa, *xa0, *xb, *xb0;        int i, j;        i = a->wds;        j = b->wds;#ifdef DEBUG        if (i > 1 && !a->x[i-1])                Bug("cmp called with a->x[a->wds-1] == 0");        if (j > 1 && !b->x[j-1])                Bug("cmp called with b->x[b->wds-1] == 0");#endif        if (i -= j)                return i;        xa0 = a->x;        xa = xa0 + j;        xb0 = b->x;        xb = xb0 + j;        for(;;) {                if (*--xa != *--xb)                        return *xa < *xb ? -1 : 1;                if (xa <= xa0)                        break;                }        return 0;        }/* Do: c = a-b. */static Bigint *diff#ifdef KR_headers        (c, a, b) Bigint *c, *a, *b;#else        (Bigint *c, Bigint *a, Bigint *b)#endif{        int i, wa, wb;        _G_int32_t borrow, y; /* We need signed shifts here. */        unsigned32 *xa, *xae, *xb, *xbe, *xc;        _G_int32_t z;        i = cmp(a,b);        if (!i) {                c = Brealloc(c, 0);                c->wds = 1;                c->x[0] = 0;                return c;                }        if (i < 0) {                Bigint *tmp = a;                a = b;                b = tmp;                i = 1;                }        else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -