35 #ifndef Omit_Private_Memory 37 #define PRIVATE_MEM 2304 39 #define PRIVATE_mem ((PRIVATE_MEM + sizeof(double) - 1) / sizeof(double)) 60 #ifdef Omit_Private_Memory 63 #ifndef Omit_Private_Memory 66 len = (
sizeof(
Bigint) + ((
unsigned)x - 1) *
sizeof(
ULong) +
sizeof(double) - 1) /
112 register ULong x = *y;
189 carry = (
unsigned long long)a;
193 y = *x * (
ULLong)m + carry;
195 *x++ = y & 0xffffffff
UL;
199 y = (xi & 0xffff) * m + carry;
200 z = (xi >> 16) * m + (y >> 16);
202 *x++ = (z << 16) + (y & 0xffff);
219 b->
x[wds++] = (
ULong)carry;
227 (x)
register ULong x;
234 if(!(x & 0xffff0000))
239 if(!(x & 0xff000000))
244 if(!(x & 0xf0000000))
249 if(!(x & 0xc0000000))
254 if(!(x & 0x80000000))
257 if(!(x & 0x40000000))
292 ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0;
320 for(x = c->
x, xa = x + wc; x < xa; x++)
332 for(; xb < xbe; xc0++)
341 z = *x++ * (
ULLong)y + *xc + carry;
343 *xc++ = z & 0xffffffff
UL;
350 for(; xb < xbe; xb++, xc0++)
352 if((y = *xb & 0xffff) != 0)
359 z = (*x & 0xffff) * y + (*xc & 0xffff) + carry;
361 z2 = (*x++ >> 16) * y + (*xc >> 16) + carry;
367 if((y = *xb >> 16) != 0)
375 z = (*x & 0xffff) * y + (*xc >> 16) + carry;
378 z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry;
385 for(; xb < xbe; xc0++)
394 z = *x++ * y + *xc + carry;
403 for(xc0 = c->
x, xc = xc0 + wc; wc > 0 && !*--xc; --wc)
429 static int p05[3] = {5, 25, 125};
443 #ifdef MULTIPLE_THREADS 470 if((p51 = p5->
next) == 0)
472 #ifdef MULTIPLE_THREADS 474 if(!(p51 = p5->
next))
500 ULong *x, *x1, *xe, z;
505 for(i = b->
maxwds; n1 > i; i <<= 1)
513 for(i = 0; i < n; i++)
542 *x1++ = *x << k & 0xffff | z;
573 ULong *xa, *xa0, *xb, *xb0;
579 if(i > 1 && !a->
x[i - 1])
580 Bug(
"cmp called with a->x[a->wds-1] == 0");
581 if(j > 1 && !b->
x[j - 1])
582 Bug(
"cmp called with b->x[b->wds-1] == 0");
599 return *xa < *xb ? -1 : 1;
622 ULong *xa, *xae, *xb, *xbe, *xc;
666 y = (
ULLong)*xa++ - *xb++ - borrow;
667 borrow = y >> 32 & 1
UL;
668 *xc++ = y & 0xffffffff
UL;
673 borrow = y >> 32 & 1
UL;
674 *xc++ = y & 0xffffffff
UL;
680 y = (*xa & 0xffff) - (*xb & 0xffff) - borrow;
681 borrow = (y & 0x10000) >> 16;
682 z = (*xa++ >> 16) - (*xb++ >> 16) - borrow;
683 borrow = (z & 0x10000) >> 16;
688 y = (*xa & 0xffff) - borrow;
689 borrow = (y & 0x10000) >> 16;
690 z = (*xa++ >> 16) - borrow;
691 borrow = (z & 0x10000) >> 16;
697 y = *xa++ - *xb++ - borrow;
698 borrow = (y & 0x10000) >> 16;
704 borrow = (y & 0x10000) >> 16;
727 ULong *xa, *xa0, w, y, z;
742 Bug(
"zero y in b2d");
750 w = xa > xa0 ? *--xa : 0;
754 z = xa > xa0 ? *--xa : 0;
757 d0 =
Exp_1 | y << k | z >> (32 - k);
758 y = xa > xa0 ? *--xa : 0;
759 d1 = z << k | y >> (32 - k);
769 z = xa > xa0 ? *--xa : 0;
771 w = xa > xa0 ? *--xa : 0;
772 y = xa > xa0 ? *--xa : 0;
776 z = xa > xa0 ? *--xa : 0;
777 w = xa > xa0 ? *--xa : 0;
779 d0 =
Exp_1 | y << k + 16 | z << k | w >> 16 - k;
780 y = xa > xa0 ? *--xa : 0;
781 d1 = w << k + 16 | y << k;
795 (d, e, bits)
double d;
798 (
double d,
int* e,
int* bits)
802 #ifndef Sudden_Underflow 825 #ifdef Sudden_Underflow 843 x[0] = y | z << (32 - k);
852 #ifndef Sudden_Underflow 855 b->
wds = (x[1] = z) != 0 ? 2 : 1;
861 #ifndef Sudden_Underflow 873 x[0] = y | z << 32 - k & 0xffff;
874 x[1] = z >> k - 16 & 0xffff;
881 x[1] = y >> 16 | z << 16 - k & 0xffff;
882 x[2] = z >> k & 0xffff;
899 Bug(
"Zero passed to d2b");
919 #ifndef Sudden_Underflow 924 *e = (de -
Bias - (
P - 1) << 2) + k;
927 *e = de -
Bias - (
P - 1) + k;
930 #ifndef Sudden_Underflow 934 *e = de -
Bias - (
P - 1) + 1 + k;
936 *bits = 32 * i -
hi0bits(x[i - 1]);
938 *bits = (i + 2) * 16 -
hi0bits(x[i]);
949 bigtens[] = {1e16, 1e32, 1e64, 1e128, 1e256};
950 CONST double tinytens[] = {1e-16, 1e-32, 1e-64, 1e-128, 1e-256};
953 bigtens[] = {1e16, 1e32, 1e64};
1012 memcpy_D2A(a, b, len)
Char* a;
1016 memcpy_D2A(
void *a1,
void *b1,
size_t len)
1019 register char *a = (
char*)a1, *ae = a + len;
1020 register char *b = (
char*)b1, *a0 = a;
#define FREE_DTOA_LOCK(n)
Bigint * lshift(Bigint *b, int k)
double b2d(Bigint *a, int *e)
Bigint * diff(Bigint *a, Bigint *b)
char * strcp_D2A(char *a, CONST char *b)
Bigint * d2b(double d, int *e, int *bits)
#define Storeinc(a, b, c)
static double * pmem_next
Bigint * multadd(Bigint *b, int m, int a)
Bigint * pow5mult(Bigint *b, int k)
int cmp(Bigint *a, Bigint *b)
#define ACQUIRE_DTOA_LOCK(n)
static Bigint * freelist[Kmax+1]
Bigint * mult(Bigint *a, Bigint *b)
static double private_mem[PRIVATE_mem]
int hi0bits_D2A(register ULong x)