/* Please send bug reports to David M. Gay (dmg at acm dot org,
* with " at " changed at "@" and " dot " changed to "."). */
/* On a machine with IEEE extended-precision registers, it is *necessarytospecifydouble-precision(53-bit)roundingprecision *beforeinvokingstrtodordtoa.Ifthemachineuses(theequivalent *of)Intel80x87arithmetic,thecall *_control87(PC_53,MCW_PC); *doesthiswithmanycompilers.Whetherthisoranothercallis *appropriatedependsonthecompiler;forthistowork,itmaybe *necessaryto#include"float.h"oranothersystem-dependentheader *file.
*/
#ifdefined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1 #error"Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined." #endif
#ifdef RND_PRODQUOT #define rounded_product(a,b) a = rnd_prod(a, b) #define rounded_quotient(a,b) a = rnd_quot(a, b) #ifdef KR_headers externdouble rnd_prod(), rnd_quot(); #else externdouble rnd_prod(double, double), rnd_quot(double, double); #endif #else #define rounded_product(a,b) a *= b #define rounded_quotient(a,b) a /= b #endif
static Bigint *
multadd #ifdef KR_headers
(STATE_PARAM b, m, a) STATE_PARAM_DECL Bigint *b; int m, a; #else
(STATE_PARAM Bigint *b, int m, int a) /* multiply by m and add a */ #endif
{ int i, wds; #ifdef ULLong
ULong *x;
ULLong carry, y; #else
ULong carry, *x, y; #ifdef Pack_32
ULong xi, z; #endif #endif
Bigint *b1;
wds = b->wds;
x = b->x;
i = 0;
carry = a; do { #ifdef ULLong
y = *x * (ULLong)m + carry;
carry = y >> 32;
*x++ = (ULong) y & FFFFFFFF; #else #ifdef Pack_32
xi = *x;
y = (xi & 0xffff) * m + carry;
z = (xi >> 16) * m + (y >> 16);
carry = z >> 16;
*x++ = (z << 16) + (y & 0xffff); #else
y = *x * m + carry;
carry = y >> 16;
*x++ = y & 0xffff; #endif #endif
} while(++i < wds); if (carry) { if (wds >= b->maxwds) {
b1 = Balloc(PASS_STATE b->k+1);
Bcopy(b1, b);
Bfree(PASS_STATE b);
b = b1;
}
b->x[wds++] = (ULong) carry;
b->wds = wds;
} return b;
}
staticint
hi0bits #ifdef KR_headers
(x) ULong x; #else
(ULong x) #endif
{ 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)) return32;
} return k;
}
staticint
lo0bits #ifdef KR_headers
(y) ULong *y; #else
(ULong *y) #endif
{ int k;
ULong x = *y;
if (x & 7) { if (x & 1) return0; if (x & 2) {
*y = x >> 1; return1;
}
*y = x >> 2; return2;
}
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) return32;
}
*y = x; return k;
}
static Bigint *
i2b #ifdef KR_headers
(STATE_PARAM i) STATE_PARAM_DECL int i; #else
(STATE_PARAM int i) #endif
{
Bigint *b;
i = cmp(a,b); if (!i) {
c = Balloc(PASS_STATE 0);
c->wds = 1;
c->x[0] = 0; return c;
} if (i < 0) {
c = a;
a = b;
b = c;
i = 1;
} else
i = 0;
c = Balloc(PASS_STATE a->k);
c->sign = i;
wa = a->wds;
xa = a->x;
xae = xa + wa;
wb = b->wds;
xb = b->x;
xbe = xb + wb;
xc = c->x;
borrow = 0; #ifdef ULLong do {
y = (ULLong)*xa++ - *xb++ - borrow;
borrow = y >> 32 & (ULong)1;
*xc++ = (ULong) y & FFFFFFFF;
} while(xb < xbe); while(xa < xae) {
y = *xa++ - borrow;
borrow = y >> 32 & (ULong)1;
*xc++ = (ULong) y & FFFFFFFF;
} #else #ifdef Pack_32 do {
y = (*xa & 0xffff) - (*xb & 0xffff) - borrow;
borrow = (y & 0x10000) >> 16;
z = (*xa++ >> 16) - (*xb++ >> 16) - borrow;
borrow = (z & 0x10000) >> 16;
Storeinc(xc, z, y);
} while(xb < xbe); while(xa < xae) {
y = (*xa & 0xffff) - borrow;
borrow = (y & 0x10000) >> 16;
z = (*xa++ >> 16) - borrow;
borrow = (z & 0x10000) >> 16;
Storeinc(xc, z, y);
} #else do {
y = *xa++ - *xb++ - borrow;
borrow = (y & 0x10000) >> 16;
*xc++ = y & 0xffff;
} while(xb < xbe); while(xa < xae) {
y = *xa++ - borrow;
borrow = (y & 0x10000) >> 16;
*xc++ = y & 0xffff;
} #endif #endif while(!*--xc)
wa--;
c->wds = wa; return c;
}
static Bigint *
d2b #ifdef KR_headers
(STATE_PARAM d, e, bits) STATE_PARAM_DECL U d; int *e, *bits; #else
(STATE_PARAM U d, int *e, int *bits) #endif
{
Bigint *b; int de, k;
ULong *x, y, z; #ifndef Sudden_Underflow int i; #endif #ifdef VAX
ULong d0, d1;
d0 = word0(d) >> 16 | word0(d) << 16;
d1 = word1(d) >> 16 | word1(d) << 16; #else #define d0 word0(d) #define d1 word1(d) #endif
#ifdef Pack_32
b = Balloc(PASS_STATE 1); #else
b = Balloc(PASS_STATE 2); #endif
x = b->x;
z = d0 & Frac_mask;
d0 &= 0x7fffffff; /* clear sign bit, which we ignore */ #ifdef Sudden_Underflow
de = (int)(d0 >> Exp_shift); #ifndef IBM
z |= Exp_msk11; #endif #else if ((de = (int)(d0 >> Exp_shift)))
z |= Exp_msk1; #endif #ifdef Pack_32 if ((y = d1)) { if ((k = lo0bits(&y))) {
x[0] = y | z << (32 - k);
z >>= k;
} else
x[0] = y; #ifndef Sudden_Underflow
i = #endif
b->wds = (x[1] = z) ? 2 : 1;
} else {
k = lo0bits(&z);
x[0] = z; #ifndef Sudden_Underflow
i = #endif
b->wds = 1;
k += 32;
} #else if (y = d1) { if (k = lo0bits(&y)) if (k >= 16) {
x[0] = y | z << 32 - k & 0xffff;
x[1] = z >> k - 16 & 0xffff;
x[2] = z >> k;
i = 2;
} else {
x[0] = y & 0xffff;
x[1] = y >> 16 | z << 16 - k & 0xffff;
x[2] = z >> k & 0xffff;
x[3] = z >> k+16;
i = 3;
} else {
x[0] = y & 0xffff;
x[1] = y >> 16;
x[2] = z & 0xffff;
x[3] = z >> 16;
i = 3;
}
} else { #ifdef DEBUG if (!z)
Bug("Zero passed to d2b"); #endif
k = lo0bits(&z); if (k >= 16) {
x[0] = z;
i = 0;
} else {
x[0] = z & 0xffff;
x[1] = z >> 16;
i = 1;
}
k += 32;
} while(!x[i])
--i;
b->wds = i + 1; #endif #ifndef Sudden_Underflow if (de) { #endif #ifdef IBM
*e = (de - Bias - (P-1) << 2) + k;
*bits = 4*P + 8 - k - hi0bits(word0(d) & Frac_mask); #else
*e = de - Bias - (P-1) + k;
*bits = P - k; #endif #ifndef Sudden_Underflow
} else {
*e = de - Bias - (P-1) + 1 + k; #ifdef Pack_32
*bits = 32*i - hi0bits(x[i-1]); #else
*bits = (i+2)*16 - hi0bits(x[i]); #endif
} #endif return b;
} #undef d0 #undef d1
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.42Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-10-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.