/* logl.c
*
* Natural logarithm , long double precision
*
*
*
* SYNOPSIS :
*
* long double x , y , logl ( ) ;
*
* y = logl ( x ) ;
*
*
*
* DESCRIPTION :
*
* Returns the base e ( 2 . 718 . . . ) logarithm of x .
*
* The argument is separated into its exponent and fractional
* parts . If the exponent is between - 1 and + 1 , the logarithm
* of the fraction is approximated by
*
* log ( 1 + x ) = x - 0 . 5 x * * 2 + x * * 3 P ( x ) / Q ( x ) .
*
* Otherwise , setting z = 2 ( x - 1 ) / x + 1 ) ,
*
* log ( x ) = z + z * * 3 P ( z ) / Q ( z ) .
*
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* IEEE 0 . 5 , 2 . 0 150000 8 . 71 e - 20 2 . 75 e - 20
* IEEE exp ( + - 10000 ) 100000 5 . 39 e - 20 2 . 34 e - 20
*
* In the tests over the interval exp ( + - 10000 ) , the logarithms
* of the random arguments were uniformly distributed over
* [ - 10000 , + 10000 ] .
*
* ERROR MESSAGES :
*
* log singularity : x = 0 ; returns - INFINITYL
* log domain : x < 0 ; returns NANL
*/
/*
Cephes Math Library Release 2 . 7 : May , 1998
Copyright 1984 , 1990 , 1998 by Stephen L . Moshier
*/
#include "mconf.h"
/* Coefficients for log(1+x) = x - x**2/2 + x**3 P(x)/Q(x)
* 1 / sqrt ( 2 ) < = x < sqrt ( 2 )
* Theoretical peak relative error = 2 . 32 e - 20
*/
#ifdef UNK
static long double P[] = {
4 .5270000862445199635215 E-5 L,
4 .9854102823193375972212 E-1 L,
6 .5787325942061044846969 E0L,
2 .9911919328553073277375 E1L,
6 .0949667980987787057556 E1L,
5 .7112963590585538103336 E1L,
2 .0039553499201281259648 E1L,
};
static long double Q[] = {
/* 1.0000000000000000000000E0,*/
1 .5062909083469192043167 E1L,
8 .3047565967967209469434 E1L,
2 .2176239823732856465394 E2L,
3 .0909872225312059774938 E2L,
2 .1642788614495947685003 E2L,
6 .0118660497603843919306 E1L,
};
#endif
#ifdef IBMPC
static short P[] = {
0 x51b9,0 x9cae,0 x4b15,0 xbde0,0 x3ff0, XPD
0 x19cf,0 xf0d4,0 xc507,0 xff40,0 x3ffd, XPD
0 x9942,0 xa7d2,0 xfa37,0 xd284,0 x4001, XPD
0 x4add,0 x65ce,0 x9c5c,0 xef4b,0 x4003, XPD
0 x8445,0 x619a,0 x75c3,0 xf3cc,0 x4004, XPD
0 x81ab,0 x3cd0,0 xacba,0 xe473,0 x4004, XPD
0 x4cbf,0 xcc18,0 x016c,0 xa051,0 x4003, XPD
};
static short Q[] = {
/*0x0000,0x0000,0x0000,0x8000,0x3fff,*/
0 xb8b7,0 x81f1,0 xacf4,0 xf101,0 x4002, XPD
0 xbc31,0 x09a4,0 x5a91,0 xa618,0 x4005, XPD
0 xaeec,0 xe7da,0 x2c87,0 xddc3,0 x4006, XPD
0 x2bde,0 x4845,0 xa2ee,0 x9a8c,0 x4007, XPD
0 x3120,0 x4703,0 x89f2,0 xd86d,0 x4006, XPD
0 x7347,0 x3224,0 x8223,0 xf079,0 x4004, XPD
};
#endif
#ifdef MIEEE
static long P[] = {
0 x3ff00000,0 xbde04b15,0 x9cae51b9,
0 x3ffd0000,0 xff40c507,0 xf0d419cf,
0 x40010000,0 xd284fa37,0 xa7d29942,
0 x40030000,0 xef4b9c5c,0 x65ce4add,
0 x40040000,0 xf3cc75c3,0 x619a8445,
0 x40040000,0 xe473acba,0 x3cd081ab,
0 x40030000,0 xa051016c,0 xcc184cbf,
};
static long Q[] = {
/*0x3fff0000,0x80000000,0x00000000,*/
0 x40020000,0 xf101acf4,0 x81f1b8b7,
0 x40050000,0 xa6185a91,0 x09a4bc31,
0 x40060000,0 xddc32c87,0 xe7daaeec,
0 x40070000,0 x9a8ca2ee,0 x48452bde,
0 x40060000,0 xd86d89f2,0 x47033120,
0 x40040000,0 xf0798223,0 x32247347,
};
#endif
/* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2),
* where z = 2 ( x - 1 ) / ( x + 1 )
* 1 / sqrt ( 2 ) < = x < sqrt ( 2 )
* Theoretical peak relative error = 6 . 16 e - 22
*/
#ifdef UNK
static long double R[4 ] = {
1 .9757429581415468984296 E-3 L,
-7 .1990767473014147232598 E-1 L,
1 .0777257190312272158094 E1L,
-3 .5717684488096787370998 E1L,
};
static long double S[4 ] = {
/* 1.00000000000000000000E0L,*/
-2 .6201045551331104417768 E1L,
1 .9361891836232102174846 E2L,
-4 .2861221385716144629696 E2L,
};
static long double C1 = 6 .9314575195312500000000 E-1 L;
static long double C2 = 1 .4286068203094172321215 E-6 L;
#endif
#ifdef IBMPC
static short R[] = {
0 x6ef4,0 xf922,0 x7763,0 x817b,0 x3ff6, XPD
0 x15fd,0 x1af9,0 xde8f,0 xb84b,0 xbffe, XPD
0 x8b96,0 x4f8d,0 xa53c,0 xac6f,0 x4002, XPD
0 x8932,0 xb4e3,0 xe8ae,0 x8ede,0 xc004, XPD
};
static short S[] = {
/*0x0000,0x0000,0x0000,0x8000,0x3fff,*/
0 x7ce4,0 x1fc9,0 xbdc5,0 xd19b,0 xc003, XPD
0 x0af3,0 x0d10,0 x716f,0 xc19e,0 x4006, XPD
0 x4d7d,0 x0f55,0 x5d06,0 xd64e,0 xc007, XPD
};
static short sc1[] = {0 x0000,0 x0000,0 x0000,0 xb172,0 x3ffe, XPD};
#define C1 (*(long double *)sc1)
static short sc2[] = {0 x4f1e,0 xcd5e,0 x8e7b,0 xbfbe,0 x3feb, XPD};
#define C2 (*(long double *)sc2)
#endif
#ifdef MIEEE
static long R[12 ] = {
0 x3ff60000,0 x817b7763,0 xf9226ef4,
0 xbffe0000,0 xb84bde8f,0 x1af915fd,
0 x40020000,0 xac6fa53c,0 x4f8d8b96,
0 xc0040000,0 x8edee8ae,0 xb4e38932,
};
static long S[9 ] = {
/*0x3fff0000,0x80000000,0x00000000,*/
0 xc0030000,0 xd19bbdc5,0 x1fc97ce4,
0 x40060000,0 xc19e716f,0 x0d100af3,
0 xc0070000,0 xd64e5d06,0 x0f554d7d,
};
static long sc1[] = {0 x3ffe0000,0 xb1720000,0 x00000000};
#define C1 (*(long double *)sc1)
static long sc2[] = {0 x3feb0000,0 xbfbe8e7b,0 xcd5e4f1e};
#define C2 (*(long double *)sc2)
#endif
#define SQRTH 0 .70710678118654752440 L
extern long double MINLOGL;
#ifdef ANSIPROT
extern long double frexpl ( long double , int * );
extern long double ldexpl ( long double , int );
extern long double polevll ( long double , void *, int );
extern long double p1evll ( long double , void *, int );
extern int isnanl ( long double );
#else
long double frexpl(), ldexpl(), polevll(), p1evll(), isnanl();
#endif
#ifdef INFINITIES
extern long double INFINITYL;
#endif
#ifdef NANS
extern long double NANL;
#endif
long double logl(x)
long double x;
{
long double y, z;
int e;
#ifdef NANS
if ( isnanl(x) )
return (x);
#endif
#ifdef INFINITIES
if ( x == INFINITYL )
return (x);
#endif
/* Test for domain */
if ( x <= 0 .0 L )
{
if ( x == 0 .0 L )
{
#ifdef INFINITIES
return ( -INFINITYL );
#else
mtherr( "logl" , SING );
return ( MINLOGL );
#endif
}
else
{
#ifdef NANS
return ( NANL );
#else
mtherr( "logl" , DOMAIN );
return ( MINLOGL );
#endif
}
}
/* separate mantissa from exponent */
/* Note, frexp is used so that denormal numbers
* will be handled properly .
*/
x = frexpl( x, &e );
/* logarithm using log(x) = z + z**3 P(z)/Q(z),
* where z = 2 ( x - 1 ) / x + 1 )
*/
if ( (e > 2 ) || (e < -2 ) )
{
if ( x < SQRTH )
{ /* 2( 2x-1 )/( 2x+1 ) */
e -= 1 ;
z = x - 0 .5 L;
y = 0 .5 L * z + 0 .5 L;
}
else
{ /* 2 (x-1)/(x+1) */
z = x - 0 .5 L;
z -= 0 .5 L;
y = 0 .5 L * x + 0 .5 L;
}
x = z / y;
z = x*x;
z = x * ( z * polevll( z, R, 3 ) / p1evll( z, S, 3 ) );
z = z + e * C2;
z = z + x;
z = z + e * C1;
return ( z );
}
/* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */
if ( x < SQRTH )
{
e -= 1 ;
x = ldexpl( x, 1 ) - 1 .0 L; /* 2x - 1 */
}
else
{
x = x - 1 .0 L;
}
z = x*x;
y = x * ( z * polevll( x, P, 6 ) / p1evll( x, Q, 6 ) );
y = y + e * C2;
z = y - ldexpl( z, -1 ); /* y - 0.5 * z */
/* Note, the sum of above terms does not exceed x/4,
* so it contributes at most about 1 / 4 lsb to the error .
*/
z = z + x;
z = z + e * C1; /* This sum has an error of 1/2 lsb. */
return ( z );
}
Messung V0.5 in Prozent C=93 H=100 G=96
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-13)
¤
*© Formatika GbR, Deutschland