double log2(x) double x;
{ int e; double y; VOLATILEdouble z; #ifdef DEC short *q; #endif
#ifdef NANS if (isnan(x)) return (x); #endif #ifdef INFINITIES if (x == INFINITY) return (x); #endif /* Test for domain */ if (x <= 0.0) { if (x == 0.0) {
mtherr(fname, SING); return (-INFINITY);
} else {
mtherr(fname, DOMAIN); return (NAN);
}
}
/* separate mantissa from exponent */
#ifdef DEC
q = (short *)&x;
e = *q; /* short containing exponent */
e = ((e >> 7) & 0377) - 0200; /* the exponent */
*q &= 0177; /* strip exponent from x */
*q |= 040000; /* x now between 0.5 and 1 */ #endif
/* Note, frexp is used so that denormal numbers *willbehandledproperly.
*/ #ifdef IBMPC
x = frexp(x, &e); /* q=(short*)&x; q+=3; e=*q; e=((e>>4)&0x0fff)-0x3fe; *q&=0x0f; *q|=0x3fe0;
*/ #endif
/* Equivalent C language standard library function: */ #ifdef UNK
x = frexp(x, &e); #endif
#ifdef MIEEE
x = frexp(x, &e); #endif
/* logarithm using log(x) = z + z**3 P(z)/Q(z), *wherez=2(x-1)/x+1)
*/
if ((e > 2) || (e < -2)) { if (x < SQRTH) { /* 2( 2x-1 )/( 2x+1 ) */
e -= 1;
z = x - 0.5;
y = 0.5 * z + 0.5;
} else { /* 2 (x-1)/(x+1) */
z = x - 0.5;
z -= 0.5;
y = 0.5 * x + 0.5;
}
x = z / y;
z = x * x;
y = x * (z * polevl(z, R, 2) / p1evl(z, S, 3)); goto ldone;
}
/* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */
if (x < SQRTH) {
e -= 1;
x = ldexp(x, 1) - 1.0; /* 2x - 1 */
} else {
x = x - 1.0;
}
z = x * x; #if DEC
y = x * (z * polevl(x, P, 5) / p1evl(x, Q, 6)) - ldexp(z, -1); #else
y = x * (z * polevl(x, P, 5) / p1evl(x, Q, 5)) - ldexp(z, -1); #endif
ldone:
/* Multiply log of fraction by log2(e) *andbase2exponentby1 * ****CAUTION*** * *Thissequenceofoperationsiscriticalanditmay *behorriblydefeatedbysomecompileroptimizers.
*/
z = y * LOG2EA;
z += x * LOG2EA;
z += y;
z += x;
z += e; return (z);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-10)
¤
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.