/* qlog.c
*
* Natural logarithm
*
*
*
* SYNOPSIS :
*
* int qlog ( x , y ) ;
* QELT * x , * y ;
*
* qlog ( x , y ) ;
*
*
*
* DESCRIPTION :
*
* Returns the base e ( 2 . 718 . . . ) logarithm of x .
*
* After reducing the argument into the interval [ 1 / sqrt ( 2 ) , sqrt ( 2 ) ] ,
* the logarithm is calculated by
*
* x - 1
* w = - - -
* x + 1
* 3 5
* w w
* ln ( x ) / 2 = w + - - - + - - - + . . .
* 3 5
*/
/*
Cephes Math Library Release 2 . 3 : March , 1995
Copyright 1984 , 1995 by Stephen L . Moshier
*/
#include "qhead.h"
extern QELT qone[], qtwo[], qlog2[], qsqrt2[];
/* C1 + C2 = ln 2 */
#if WORDSIZE == 16
static QELT C1[NQ] = {0 ,EXPONE-1 ,0 ,0 xb172, 0 x17f7};
#if NQ > 12
static QELT C2[NQ] = {
0 x0000,EXPONE-33 ,0 x0000,0 xd1cf,0 x79ab,0 xc9e3,0 xb398,0 x03f2,
0 xf6af,0 x40f3,0 x4326,0 x7298,0 xb62d,0 x8a0d,0 x175b,0 x8baa,
0 xfa2b,0 xe7b8,0 x7620,0 x6deb,0 xac98,0 x5595,0 x52fb,0 x4afa};
#else /* not NQ > 12 */
static QELT C2[NQ] = {
0 x0000,EXPONE-33 ,0 x0000,0 xd1cf,0 x79ab,0 xc9e3,0 xb398,0 x03f2,
0 xf6af,0 x40f3,0 x4326,0 x7299};
#endif /* not NQ > 12 */
#else /* WORDSIZE 32 */
#if NQ < 15
/* NQ of 14. */
static QELT C1[NQ] = {0 ,EXPONE-1 ,0 ,0 xb17217f7};
static QELT C2[NQ] = {
0 x0000,EXPONE-33 ,0 x0000,0 xd1cf79ab,0 xc9e3b398,0 x03f2f6af,0 x40f34326,0 x7298b62d,
0 x8a0d175b,0 x8baafa2b,0 xe7b87620,0 x6debac98,0 x559552fb,0 x4afa1b11};
#else
/* NQ of 28. */
static QELT C1[NQ] = {0 ,EXPONE-1 ,0 ,0 xb17217f7};
static QELT C2[NQ] = {
0 x00000000,EXPONE-33 ,0 x00000000,0 xd1cf79ab,0 xc9e3b398,0 x03f2f6af,0 x40f34326,
0 x7298b62d,0 x8a0d175b,0 x8baafa2b,0 xe7b87620,0 x6debac98,0 x559552fb,0 x4afa1b11,
0 x12d151ca,0 x3ec7debb,0 xd8a8c4d6,0 xee9647da,0 xc16935e9,0 xddb5173a,0 xe53425ee,
0 xce83c781,0 x4615643c,0 x4ec99fc4,0 xda905f13,0 x89a808b4,0 x8d317857,0 x00000000,};
#endif
#endif /* WORDSIZE 32 */
int qlog( x, y )
QELT *x, *y;
{
QELT xx[NQ], z[NQ], a[NQ], b[NQ], t[NQ], qj[NQ];
long ex;
if ( x[0 ] != 0 )
{
qclear(y);
mtherr( "qlog" , DOMAIN );
return 0 ;
}
if ( x[1 ] == 0 )
{
qinfin( y );
y[0 ] = -1 ;
mtherr( "qlog" , SING );
return 0 ;
}
/* range reduction: log x = log( 2**ex * m ) = ex * log2 + log m */
qmov(x, xx );
ex = *(xx+1 );
if ( ex == EXPONE )
{ /* log 1 = 0 */
if ( qcmp(x, qone) == 0 )
{
qclear(y);
return 0 ;
}
}
ex -= (EXPONE-1 );
xx[1 ] = (EXPONE-1 );
/* Adjust range to 1/sqrt(2), sqrt(2) */
qsqrt2[1 ] -= 1 ;
if ( qcmp( xx, qsqrt2 ) < 0 )
{
ex -= 1 ;
xx[1 ] += 1 ;
}
qsqrt2[1 ] += 1 ;
qadd( qone, xx, b );
qsub( qone, xx, a );
if ( a[1 ] == 0 )
{
qclear(y);
goto bdone;
}
qdiv( b, a, y ); /* store (x-1)/(x+1) in y */
qmul( y, y, z );
qmov( qone, a );
qmov( qone, b );
qmov( qone, qj );
do
{
qadd( qtwo, qj, qj ); /* 2 * i + 1 */
qmul( z, a, a );
qdiv( qj, a, t );
qadd( t, b, b );
}
while ( ((int ) b[1 ] - (int ) t[1 ]) < NBITS );
qmul( b, y, y );
y[1 ] += 1 ;
bdone:
/* now add log of 2**ex */
if ( ex != 0 )
{
ltoq( &ex, b );
qmul( C2, b, t );
qadd( t, y, y );
qmul( C1, b, t );
qadd( t, y, y );
}
return 0 ;
}
Messung V0.5 in Prozent C=91 H=83 G=86
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-25)
¤
*© Formatika GbR, Deutschland