/* powl.c
*
* Power function , long double precision
*
*
*
* SYNOPSIS :
*
* long double x , y , z , powl ( ) ;
*
* z = powl ( x , y ) ;
*
*
*
* DESCRIPTION :
*
* Computes x raised to the yth power . Analytically ,
*
* x * * y = exp ( y log ( x ) ) .
*
* Following Cody and Waite , this program uses a lookup table
* of 2 * * - i / 32 and pseudo extended precision arithmetic to
* obtain several extra bits of accuracy in both the logarithm
* and the exponential .
*
*
*
* ACCURACY :
*
* The relative error of pow ( x , y ) can be estimated
* by y dl ln ( 2 ) , where dl is the absolute error of
* the internally computed base 2 logarithm . At the ends
* of the approximation interval the logarithm equal 1 / 32
* and its relative error is about 1 lsb = 1 . 1 e - 19 . Hence
* the predicted relative error in the result is 2 . 3 e - 21 y .
*
* Relative error :
* arithmetic domain # trials peak rms
*
* IEEE + - 1000 40000 2 . 8 e - 18 3 . 7 e - 19
* . 001 < x < 1000 , with log ( x ) uniformly distributed .
* - 1000 < y < 1000 , y uniformly distributed .
*
* IEEE 0 , 8700 60000 6 . 5 e - 18 1 . 0 e - 18
* 0 . 99 < x < 1 . 01 , 0 < y < 8700 , uniformly distributed .
*
*
* ERROR MESSAGES :
*
* message condition value returned
* pow overflow x * * y > MAXNUM MAXNUM
* pow underflow x * * y < 1 / MAXNUM 0 . 0
* pow domain x < 0 and y noninteger 0 . 0
*
*/
/*
Cephes Math Library Release 2 . 2 : January , 1991
Copyright 1984 , 1991 by Stephen L . Moshier
Direct inquiries to 30 Frost Street , Cambridge , MA 02140
*/
#include "mconf.h"
static char fname[] = {"powl" };
/* Table size */
#define NXT 32
/* log2(Table size) */
#define LNXT 5
#ifdef UNK
/* log(1+x) = x - .5x^2 + x^3 * P(z)/Q(z)
* on the domain 2 ^ ( - 1 / 32 ) - 1 < = x < = 2 ^ ( 1 / 32 ) - 1
*/
static long double P[] = {
8 .3319510773868690346226 E-4 L,
4 .9000050881978028599627 E-1 L,
1 .7500123722550302671919 E0L,
1 .4000100839971580279335 E0L,
};
static long double Q[] = {
/* 1.0000000000000000000000E0L,*/
5 .2500282295834889175431 E0L,
8 .4000598057587009834666 E0L,
4 .2000302519914740834728 E0L,
};
/* A[i] = 2^(-i/32), rounded to IEEE long double precision.
* If i is even , A [ i ] + B [ i / 2 ] gives additional accuracy .
*/
static long double A[33 ] = {
1 .0000000000000000000000 E0L,
9 .7857206208770013448287 E-1 L,
9 .5760328069857364691013 E-1 L,
9 .3708381705514995065011 E-1 L,
9 .1700404320467123175367 E-1 L,
8 .9735453750155359320742 E-1 L,
8 .7812608018664974155474 E-1 L,
8 .5930964906123895780165 E-1 L,
8 .4089641525371454301892 E-1 L,
8 .2287773907698242225554 E-1 L,
8 .0524516597462715409607 E-1 L,
7 .8799042255394324325455 E-1 L,
7 .7110541270397041179298 E-1 L,
7 .5458221379671136985669 E-1 L,
7 .3841307296974965571198 E-1 L,
7 .2259040348852331001267 E-1 L,
7 .0710678118654752438189 E-1 L,
6 .9195494098191597746178 E-1 L,
6 .7712777346844636413344 E-1 L,
6 .6261832157987064729696 E-1 L,
6 .4841977732550483296079 E-1 L,
6 .3452547859586661129850 E-1 L,
6 .2092890603674202431705 E-1 L,
6 .0762367999023443907803 E-1 L,
5 .9460355750136053334378 E-1 L,
5 .8186242938878875689693 E-1 L,
5 .6939431737834582684856 E-1 L,
5 .5719337129794626814472 E-1 L,
5 .4525386633262882960438 E-1 L,
5 .3357020033841180906486 E-1 L,
5 .2213689121370692017331 E-1 L,
5 .1094857432705833910408 E-1 L,
5 .0000000000000000000000 E-1 L,
};
static long double B[17 ] = {
0 .0000000000000000000000 E0L,
2 .6176170809902549338711 E-20 L,
-1 .0126791927256478897086 E-20 L,
1 .3438228172316276937655 E-21 L,
1 .2207982955417546912101 E-20 L,
-6 .3084814358060867200133 E-21 L,
1 .3164426894366316434230 E-20 L,
-1 .8527916071632873716786 E-20 L,
1 .8950325588932570796551 E-20 L,
1 .5564775779538780478155 E-20 L,
6 .0859793637556860974380 E-21 L,
-2 .0208749253662532228949 E-20 L,
1 .4966292219224761844552 E-20 L,
3 .3540909728056476875639 E-21 L,
-8 .6987564101742849540743 E-22 L,
-1 .2327176863327626135542 E-20 L,
0 .0000000000000000000000 E0L,
};
/* 2^x = 1 + x P(x),
* on the interval - 1 / 32 < = x < = 0
*/
static long double R[] = {
1 .5089970579127659901157 E-5 L,
1 .5402715328927013076125 E-4 L,
1 .3333556028915671091390 E-3 L,
9 .6181291046036762031786 E-3 L,
5 .5504108664798463044015 E-2 L,
2 .4022650695910062854352 E-1 L,
6 .9314718055994530931447 E-1 L,
};
#define douba(k) A[k]
#define doubb(k) B[k]
#define MEXP (NXT*16384 .0 L)
/* The following if denormal numbers are supported, else -MEXP: */
#define MNEXP (-NXT*(16384 .0 L-64 .0 L))
/* log2(e) - 1 */
#define LOG2EA 0 .44269504088896340735992 L
#endif
#ifdef IBMPC
static short P[] = {
0 xb804,0 xa8b7,0 xc6f4,0 xda6a,0 x3ff4, XPD
0 x7de9,0 xcf02,0 x58c0,0 xfae1,0 x3ffd, XPD
0 x405a,0 x3722,0 x67c9,0 xe000,0 x3fff, XPD
0 xcd99,0 x6b43,0 x87ca,0 xb333,0 x3fff, XPD
};
static short Q[] = {
/* 0x0000,0x0000,0x0000,0x8000,0x3fff, */
0 x6307,0 xa469,0 x3b33,0 xa800,0 x4001, XPD
0 xfec2,0 x62d7,0 xa51c,0 x8666,0 x4002, XPD
0 xda32,0 xd072,0 xa5d7,0 x8666,0 x4001, XPD
};
static short A[] = {
0 x0000,0 x0000,0 x0000,0 x8000,0 x3fff, XPD
0 x033a,0 x722a,0 xb2db,0 xfa83,0 x3ffe, XPD
0 xcc2c,0 x2486,0 x7d15,0 xf525,0 x3ffe, XPD
0 xf5cb,0 xdcda,0 xb99b,0 xefe4,0 x3ffe, XPD
0 x392f,0 xdd24,0 xc6e7,0 xeac0,0 x3ffe, XPD
0 x48a8,0 x7c83,0 x06e7,0 xe5b9,0 x3ffe, XPD
0 xe111,0 x2a94,0 xdeec,0 xe0cc,0 x3ffe, XPD
0 x3755,0 xdaf2,0 xb797,0 xdbfb,0 x3ffe, XPD
0 x6af4,0 xd69d,0 xfcca,0 xd744,0 x3ffe, XPD
0 xe45a,0 xf12a,0 x1d91,0 xd2a8,0 x3ffe, XPD
0 x80e4,0 x1f84,0 x8c15,0 xce24,0 x3ffe, XPD
0 x27a3,0 x6e2f,0 xbd86,0 xc9b9,0 x3ffe, XPD
0 xdadd,0 x5506,0 x2a11,0 xc567,0 x3ffe, XPD
0 x9456,0 x6670,0 x4cca,0 xc12c,0 x3ffe, XPD
0 x36bf,0 x580c,0 xa39f,0 xbd08,0 x3ffe, XPD
0 x9ee9,0 x62fb,0 xaf47,0 xb8fb,0 x3ffe, XPD
0 x6484,0 xf9de,0 xf333,0 xb504,0 x3ffe, XPD
0 x2590,0 xd2ac,0 xf581,0 xb123,0 x3ffe, XPD
0 x4ac6,0 x42a1,0 x3eea,0 xad58,0 x3ffe, XPD
0 x0ef8,0 xea7c,0 x5ab4,0 xa9a1,0 x3ffe, XPD
0 x38ea,0 xb151,0 xd6a9,0 xa5fe,0 x3ffe, XPD
0 x6819,0 x0c49,0 x4303,0 xa270,0 x3ffe, XPD
0 x11ae,0 x91a1,0 x3260,0 x9ef5,0 x3ffe, XPD
0 x5539,0 xd54e,0 x39b9,0 x9b8d,0 x3ffe, XPD
0 xa96f,0 x8db8,0 xf051,0 x9837,0 x3ffe, XPD
0 x0961,0 xfef7,0 xefa8,0 x94f4,0 x3ffe, XPD
0 xc336,0 xab11,0 xd373,0 x91c3,0 x3ffe, XPD
0 x53c0,0 x45cd,0 x398b,0 x8ea4,0 x3ffe, XPD
0 xd6e7,0 xea8b,0 xc1e3,0 x8b95,0 x3ffe, XPD
0 x8527,0 x92da,0 x0e80,0 x8898,0 x3ffe, XPD
0 x7b15,0 xcc48,0 xc367,0 x85aa,0 x3ffe, XPD
0 xa1d7,0 xac2b,0 x8698,0 x82cd,0 x3ffe, XPD
0 x0000,0 x0000,0 x0000,0 x8000,0 x3ffe, XPD
};
static short B[] = {
0 x0000,0 x0000,0 x0000,0 x0000,0 x0000, XPD
0 x1f87,0 xdb30,0 x18f5,0 xf73a,0 x3fbd, XPD
0 xac15,0 x3e46,0 x2932,0 xbf4a,0 xbfbc, XPD
0 x7944,0 xba66,0 xa091,0 xcb12,0 x3fb9, XPD
0 xff78,0 x40b4,0 x2ee6,0 xe69a,0 x3fbc, XPD
0 xc895,0 x5069,0 xe383,0 xee53,0 xbfbb, XPD
0 x7cde,0 x9376,0 x4325,0 xf8ab,0 x3fbc, XPD
0 xa10c,0 x25e0,0 xc093,0 xaefd,0 xbfbd, XPD
0 x7d3e,0 xea95,0 x1366,0 xb2fb,0 x3fbd, XPD
0 x5d89,0 xeb34,0 x5191,0 x9301,0 x3fbd, XPD
0 x80d9,0 xb883,0 xfb10,0 xe5eb,0 x3fbb, XPD
0 x045d,0 x288c,0 xc1ec,0 xbedd,0 xbfbd, XPD
0 xeded,0 x5c85,0 x4630,0 x8d5a,0 x3fbd, XPD
0 x9d82,0 xe5ac,0 x8e0a,0 xfd6d,0 x3fba, XPD
0 x6dfd,0 xeb58,0 xaf14,0 x8373,0 xbfb9, XPD
0 xf938,0 x7aac,0 x91cf,0 xe8da,0 xbfbc, XPD
0 x0000,0 x0000,0 x0000,0 x0000,0 x0000, XPD
};
static short R[] = {
0 xa69b,0 x530e,0 xee1d,0 xfd2a,0 x3fee, XPD
0 xc746,0 x8e7e,0 x5960,0 xa182,0 x3ff2, XPD
0 x63b6,0 xadda,0 xfd6a,0 xaec3,0 x3ff5, XPD
0 xc104,0 xfd99,0 x5b7c,0 x9d95,0 x3ff8, XPD
0 xe05e,0 x249d,0 x46b8,0 xe358,0 x3ffa, XPD
0 x5d1d,0 x162c,0 xeffc,0 xf5fd,0 x3ffc, XPD
0 x79aa,0 xd1cf,0 x17f7,0 xb172,0 x3ffe, XPD
};
/* 10 byte sizes versus 12 byte */
#define douba(k) (*(long double *)(&A[(sizeof ( long double )/2 )*(k)]))
#define doubb(k) (*(long double *)(&B[(sizeof ( long double )/2 )*(k)]))
#define MEXP (NXT*16384 .0 L)
#define MNEXP (-NXT*16384 .0 L)
static short L[] = {0 xc2ef,0 x705f,0 xeca5,0 xe2a8,0 x3ffd, XPD};
#define LOG2EA (*(long double *)(&L[0 ]))
#endif
#ifdef MIEEE
static long P[] = {
0 x3ff40000,0 xda6ac6f4,0 xa8b7b804,
0 x3ffd0000,0 xfae158c0,0 xcf027de9,
0 x3fff0000,0 xe00067c9,0 x3722405a,
0 x3fff0000,0 xb33387ca,0 x6b43cd99,
};
static long Q[] = {
/* 0x3fff0000,0x80000000,0x00000000, */
0 x40010000,0 xa8003b33,0 xa4696307,
0 x40020000,0 x8666a51c,0 x62d7fec2,
0 x40010000,0 x8666a5d7,0 xd072da32,
};
static long A[] = {
0 x3fff0000,0 x80000000,0 x00000000,
0 x3ffe0000,0 xfa83b2db,0 x722a033a,
0 x3ffe0000,0 xf5257d15,0 x2486cc2c,
0 x3ffe0000,0 xefe4b99b,0 xdcdaf5cb,
0 x3ffe0000,0 xeac0c6e7,0 xdd24392f,
0 x3ffe0000,0 xe5b906e7,0 x7c8348a8,
0 x3ffe0000,0 xe0ccdeec,0 x2a94e111,
0 x3ffe0000,0 xdbfbb797,0 xdaf23755,
0 x3ffe0000,0 xd744fcca,0 xd69d6af4,
0 x3ffe0000,0 xd2a81d91,0 xf12ae45a,
0 x3ffe0000,0 xce248c15,0 x1f8480e4,
0 x3ffe0000,0 xc9b9bd86,0 x6e2f27a3,
0 x3ffe0000,0 xc5672a11,0 x5506dadd,
0 x3ffe0000,0 xc12c4cca,0 x66709456,
0 x3ffe0000,0 xbd08a39f,0 x580c36bf,
0 x3ffe0000,0 xb8fbaf47,0 x62fb9ee9,
0 x3ffe0000,0 xb504f333,0 xf9de6484,
0 x3ffe0000,0 xb123f581,0 xd2ac2590,
0 x3ffe0000,0 xad583eea,0 x42a14ac6,
0 x3ffe0000,0 xa9a15ab4,0 xea7c0ef8,
0 x3ffe0000,0 xa5fed6a9,0 xb15138ea,
0 x3ffe0000,0 xa2704303,0 x0c496819,
0 x3ffe0000,0 x9ef53260,0 x91a111ae,
0 x3ffe0000,0 x9b8d39b9,0 xd54e5539,
0 x3ffe0000,0 x9837f051,0 x8db8a96f,
0 x3ffe0000,0 x94f4efa8,0 xfef70961,
0 x3ffe0000,0 x91c3d373,0 xab11c336,
0 x3ffe0000,0 x8ea4398b,0 x45cd53c0,
0 x3ffe0000,0 x8b95c1e3,0 xea8bd6e7,
0 x3ffe0000,0 x88980e80,0 x92da8527,
0 x3ffe0000,0 x85aac367,0 xcc487b15,
0 x3ffe0000,0 x82cd8698,0 xac2ba1d7,
0 x3ffe0000,0 x80000000,0 x00000000,
};
static long B[51 ] = {
0 x00000000,0 x00000000,0 x00000000,
0 x3fbd0000,0 xf73a18f5,0 xdb301f87,
0 xbfbc0000,0 xbf4a2932,0 x3e46ac15,
0 x3fb90000,0 xcb12a091,0 xba667944,
0 x3fbc0000,0 xe69a2ee6,0 x40b4ff78,
0 xbfbb0000,0 xee53e383,0 x5069c895,
0 x3fbc0000,0 xf8ab4325,0 x93767cde,
0 xbfbd0000,0 xaefdc093,0 x25e0a10c,
0 x3fbd0000,0 xb2fb1366,0 xea957d3e,
0 x3fbd0000,0 x93015191,0 xeb345d89,
0 x3fbb0000,0 xe5ebfb10,0 xb88380d9,
0 xbfbd0000,0 xbeddc1ec,0 x288c045d,
0 x3fbd0000,0 x8d5a4630,0 x5c85eded,
0 x3fba0000,0 xfd6d8e0a,0 xe5ac9d82,
0 xbfb90000,0 x8373af14,0 xeb586dfd,
0 xbfbc0000,0 xe8da91cf,0 x7aacf938,
0 x00000000,0 x00000000,0 x00000000,
};
static long R[] = {
0 x3fee0000,0 xfd2aee1d,0 x530ea69b,
0 x3ff20000,0 xa1825960,0 x8e7ec746,
0 x3ff50000,0 xaec3fd6a,0 xadda63b6,
0 x3ff80000,0 x9d955b7c,0 xfd99c104,
0 x3ffa0000,0 xe35846b8,0 x249de05e,
0 x3ffc0000,0 xf5fdeffc,0 x162c5d1d,
0 x3ffe0000,0 xb17217f7,0 xd1cf79aa,
};
#define douba(k) (*(long double *)&A[3 *(k)])
#define doubb(k) (*(long double *)&B[3 *(k)])
#define MEXP (NXT*16384 .0 L)
#define MNEXP (-NXT*16382 .0 L)
static long L[3 ] = {0 x3ffd0000,0 xe2a8eca5,0 x705fc2ef};
#define LOG2EA (*(long double *)(&L[0 ]))
#endif
#define F W
#define Fa Wa
#define Fb Wb
#define G W
#define Ga Wa
#define Gb u
#define H W
#define Ha Wb
#define Hb Wb
extern long double MAXNUML;
static VOLATILE long double z;
static long double w, W, Wa, Wb, ya, yb, u;
long double floorl(), fabsl(), frexpl(), ldexpl();
long double polevll(), p1evll(), powil();
static long double reducl();
long double powl( x, y )
long double x, y;
{
/* double F, Fa, Fb, G, Ga, Gb, H, Ha, Hb */
int i, nflg;
long e;
nflg = 0 ; /* flag = 1 if x<0 raised to integer power */
w = floorl(y);
if ( (w == y) && (fabsl(w) < 32768 .0 L) )
{
i = w;
w = powil( x, i );
return ( w );
}
if ( x <= 0 .0 L )
{
if ( x == 0 .0 L )
{
if ( y == 0 .0 L )
return ( 1 .0 L ); /* 0**0 */
else
return ( 0 .0 L ); /* 0**y */
}
else
{
if ( w != y )
{ /* noninteger power of negative number */
mtherr( fname, DOMAIN );
return (0 .0 L);
}
nflg = 1 ;
x = fabsl(x);
}
}
/* separate significand from exponent */
x = frexpl( x, &i );
e = i;
/* find significand in antilog table A[] */
i = 1 ;
if ( x <= douba(17 ) )
i = 17 ;
if ( x <= douba(i+8 ) )
i += 8 ;
if ( x <= douba(i+4 ) )
i += 4 ;
if ( x <= douba(i+2 ) )
i += 2 ;
if ( x >= douba(1 ) )
i = -1 ;
i += 1 ;
/* Find (x - A[i])/A[i]
* in order to compute log ( x / A [ i ] ) :
*
* log ( x ) = log ( a x / a ) = log ( a ) + log ( x / a )
*
* log ( x / a ) = log ( 1 + v ) , v = x / a - 1 = ( x - a ) / a
*/
x -= douba(i);
x -= doubb(i/2 );
x /= douba(i);
/* rational approximation for log(1+v):
*
* log ( 1 + v ) = v - v * * 2 / 2 + v * * 3 P ( v ) / Q ( v )
*/
z = x*x;
w = x * ( z * polevll( x, P, 3 ) / p1evll( x, Q, 3 ) );
/*w = (x * z * polevll( x, P, 3 )) / p1evll( x, Q, 4 );*/
w = w - ldexpl( z, -1 ); /* w - 0.5 * z */
/* Convert to base 2 logarithm:
* multiply by log2 ( e ) = 1 + LOG2EA
*/
z = LOG2EA * w;
z += w;
z += LOG2EA * x;
z += x;
/* Compute exponent term of the base 2 logarithm. */
w = -i;
w = ldexpl( w, -LNXT ); /* divide by NXT */
w += e;
/* Now base 2 log of x is w + z. */
/* Multiply base 2 log by y, in extended precision. */
/* separate y into large part ya
* and small part yb less than 1 / NXT
*/
ya = reducl(y);
yb = y - ya;
/* (w+z)(ya+yb)
* = w * ya + w * yb + z * y
*/
F = z * y + w * yb;
Fa = reducl(F);
Fb = F - Fa;
G = Fa + w * ya;
Ga = reducl(G);
Gb = G - Ga;
H = Fb + Gb;
Ha = reducl(H);
w = ldexpl( Ga+Ha, LNXT );
/* Test the power of 2 for overflow */
if ( w > MEXP )
{
/* printf( "w = %.4Le ", w ); */
mtherr( fname, OVERFLOW );
return ( MAXNUML );
}
if ( w < MNEXP )
{
/* printf( "w = %.4Le ", w ); */
mtherr( fname, UNDERFLOW );
return ( 0 .0 L );
}
e = w;
Hb = H - Ha;
if ( Hb > 0 .0 L )
{
e += 1 ;
Hb -= (1 .0 L/NXT); /*0.0625L;*/
}
/* Now the product y * log2(x) = Hb + e/NXT.
*
* Compute base 2 exponential of Hb ,
* where - 0 . 0625 < = Hb < = 0 .
*/
z = Hb * polevll( Hb, R, 6 ); /* z = 2**Hb - 1 */
/* Express e/NXT as an integer plus a negative number of (1/NXT)ths.
* Find lookup table entry for the fractional power of 2 .
*/
if ( e < 0 )
i = 0 ;
else
i = 1 ;
i = e/NXT + i;
e = NXT*i - e;
w = douba( e );
z = w * z; /* 2**-e * ( 1 + (2**Hb-1) ) */
z = z + w;
z = ldexpl( z, i ); /* multiply by integer power of 2 */
if ( nflg )
{
/* For negative x,
* find out if the integer exponent
* is odd or even .
*/
w = ldexpl( y, -1 );
w = floorl(w);
w = ldexpl( w, 1 );
if ( w != y )
z = -z; /* odd exponent */
}
return ( z );
}
/* Find a multiple of 1/NXT that is within 1/NXT of x. */
static long double reducl(x)
long double x;
{
long double t;
t = ldexpl( x, LNXT );
t = floorl( t );
t = ldexpl( t, -LNXT );
return (t);
}
Messung V0.5 in Prozent C=93 H=100 G=96
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-14)
¤
*© Formatika GbR, Deutschland