/* clogl.c
*
* Complex natural logarithm
*
*
*
* SYNOPSIS :
*
* long double complex clogl ( ) ;
* long double complex z , w ;
*
* w = clogl ( z ) ;
*
*
*
* DESCRIPTION :
*
* Returns complex logarithm to the base e ( 2 . 718 . . . ) of
* the complex argument x .
*
* If z = x + iy , r = sqrt ( x * * 2 + y * * 2 ) ,
* then
* w = log ( r ) + i arctan ( y / x ) .
*
* The arctangent ranges from - PI to + PI .
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* DEC - 10 , + 10 7000 8 . 5 e - 17 1 . 9 e - 17
* IEEE - 10 , + 10 30000 5 . 0 e - 15 1 . 1 e - 16
*
* Larger relative error can be observed for z near 1 + i0 .
* In IEEE arithmetic the peak absolute error is 5 . 2 e - 16 , rms
* absolute error 1 . 0 e - 16 .
*/
#include "complex.h"
#include "mconf.h"
#ifdef ANSIPROT
static void cchshl ( long double x, long double *c, long double *s );
static long double redupil ( long double x );
static long double ctansl ( long double complex z );
long double fabsl (long double );
long double sqrtl (long double );
long double logl (long double );
long double expl (long double );
long double atan2l (long double , long double );
long double sinhl (long double );
long double coshl (long double );
long double sinl (long double );
long double cosl (long double );
long double asinl (long double );
long double powl (long double , long double );
long double cabsl (long double complex);
long double complex csqrtl (long double complex);
#else
static void cchshl();
static long double redupil();
static long double ctansl();
long double cabsl(), fabsl(), sqrtl();
lnog double logl(), expl(), atan2l(), coshl(), sinhl();
long double asinl(), sinl(), cosl();
long double complex csqrtl ();
long double powl();
#endif
extern long double MAXNUML, MACHEPL, PIL, PIO2L;
long double complex
clogl( long double complex z )
{
long double complex w;
long double p, rr;
/*rr = sqrt( z->r * z->r + z->i * z->i );*/
p = cabsl(z);
p = logl(p);
rr = atan2l( cimag(z), creal(z) );
w = p + rr * I;
return (w);
}
/* cexpl()
*
* Complex exponential function
*
*
*
* SYNOPSIS :
*
* long double complex cexpl ( ) ;
* long double complex z , w ;
*
* w = cexpl ( z ) ;
*
*
*
* DESCRIPTION :
*
* Returns the exponential of the complex argument z
* into the complex result w .
*
* If
* z = x + iy ,
* r = exp ( x ) ,
*
* then
*
* w = r cos y + i r sin y .
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* DEC - 10 , + 10 8700 3 . 7 e - 17 1 . 1 e - 17
* IEEE - 10 , + 10 30000 3 . 0 e - 16 8 . 7 e - 17
*
*/
long double complex
cexpl( long double complex z )
{
long double complex w;
long double r;
r = expl( creal(z) );
w = r * cosl( (long double ) cimag(z) ) + (r * sinl( (long double ) cimag(z) )) * I;
return (w);
}
/* csinl()
*
* Complex circular sine
*
*
*
* SYNOPSIS :
*
* long double complex csinl ( ) ;
* long double complex z , w ;
*
* w = csinl ( z ) ;
*
*
*
* DESCRIPTION :
*
* If
* z = x + iy ,
*
* then
*
* w = sin x cosh y + i cos x sinh y .
*
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* DEC - 10 , + 10 8400 5 . 3 e - 17 1 . 3 e - 17
* IEEE - 10 , + 10 30000 3 . 8 e - 16 1 . 0 e - 16
* Also tested by csin ( casin ( z ) ) = z .
*
*/
long double complex
csinl( long double complex z )
{
long double complex w;
long double ch, sh;
cchshl( cimag(z), &ch, &sh );
w = sinl( creal(z) ) * ch + (cosl( creal(z) ) * sh) * I;
return (w);
}
/* calculate cosh and sinh */
static void
cchshl( long double x, long double *c, long double *s )
{
long double e, ei;
if ( fabsl(x) <= 0 .5 L )
{
*c = coshl(x);
*s = sinhl(x);
}
else
{
e = expl(x);
ei = 0 .5 L/e;
e = 0 .5 L * e;
*s = e - ei;
*c = e + ei;
}
}
/* ccosl()
*
* Complex circular cosine
*
*
*
* SYNOPSIS :
*
* long double complex ccosl ( ) ;
* long double complex z , w ;
*
* w = ccosl ( z ) ;
*
*
*
* DESCRIPTION :
*
* If
* z = x + iy ,
*
* then
*
* w = cos x cosh y - i sin x sinh y .
*
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* DEC - 10 , + 10 8400 4 . 5 e - 17 1 . 3 e - 17
* IEEE - 10 , + 10 30000 3 . 8 e - 16 1 . 0 e - 16
*/
long double complex
ccosl( long double complex z )
{
long double complex w;
long double ch, sh;
cchshl( cimag(z), &ch, &sh );
w = cosl( creal(z) ) * ch + (-sinl( creal(z) ) * sh) * I;
return (w);
}
/* ctanl()
*
* Complex circular tangent
*
*
*
* SYNOPSIS :
*
* long double complex ctanl ( ) ;
* long double complex z , w ;
*
* w = ctanl ( z ) ;
*
*
*
* DESCRIPTION :
*
* If
* z = x + iy ,
*
* then
*
* sin 2 x + i sinh 2 y
* w = - - - - - - - - - - - - - - - - - - - - .
* cos 2 x + cosh 2 y
*
* On the real axis the denominator is zero at odd multiples
* of PI / 2 . The denominator is evaluated by its Taylor
* series near these points .
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* DEC - 10 , + 10 5200 7 . 1 e - 17 1 . 6 e - 17
* IEEE - 10 , + 10 30000 7 . 2 e - 16 1 . 2 e - 16
* Also tested by ctan * ccot = 1 and catan ( ctan ( z ) ) = z .
*/
long double complex
ctanl( long double complex z )
{
long double complex w;
long double d, x, y;
x = creal(z);
y = cimag(z);
d = cosl( 2 .0 L * x ) + coshl( 2 .0 L * y );
if ( fabsl(d) < 0 .25 L )
{
d = fabsl(d);
d = ctansl(z);
}
if ( d == 0 .0 L )
{
mtherr( "ctan" , OVERFLOW );
w = MAXNUML + MAXNUML * I;
return (w);
}
w = sinl( 2 .0 L * x ) / d + (sinhl( 2 .0 L * y ) / d) * I;
return (w);
}
/* ccotl()
*
* Complex circular cotangent
*
*
*
* SYNOPSIS :
*
* long double complex ccotl ( ) ;
* long double complex z , w ;
*
* w = ccotl ( z ) ;
*
*
*
* DESCRIPTION :
*
* If
* z = x + iy ,
*
* then
*
* sin 2 x - i sinh 2 y
* w = - - - - - - - - - - - - - - - - - - - - .
* cosh 2 y - cos 2 x
*
* On the real axis , the denominator has zeros at even
* multiples of PI / 2 . Near these points it is evaluated
* by a Taylor series .
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* DEC - 10 , + 10 3000 6 . 5 e - 17 1 . 6 e - 17
* IEEE - 10 , + 10 30000 9 . 2 e - 16 1 . 2 e - 16
* Also tested by ctan * ccot = 1 + i0 .
*/
long double complex
ccotl( long double complex z )
{
long double complex w;
long double d;
d = coshl(2 .0 L * cimag(z)) - cosl(2 .0 L * creal(z));
if ( fabsl(d) < 0 .25 L )
d = ctansl(z);
if ( d == 0 .0 L )
{
mtherr( "ccot" , OVERFLOW );
w = MAXNUML + MAXNUML * I;
return (w);
}
w = sinl( 2 .0 L * creal(z) ) / d + (-sinhl( 2 .0 L * cimag(z) ) / d) * I;
return (w);
}
/* Program to subtract nearest integer multiple of PI */
/* extended precision value of PI: */
#ifdef UNK
static long double DP1 = 3 .14159265358979323829596852490908531763125 L;
static long double DP2 = 1 .6667485837041756656403424829301998703007 e-19 L;
static long double DP3 = 1 .8830410776607851167459095484560349402753 e-39 L;
#endif
#ifdef DEC
DEC not supported
#endif
#ifdef IBMPC
static unsigned short P1[] = {0 xc234,0 x2168,0 xdaa2,0 xc90f,0 x4000,XPD};
static unsigned short P2[] = {0 x1cd1,0 x80dc,0 x628b,0 xc4c6,0 x3fc0,XPD};
static unsigned short P3[] = {0 x31d0,0 x299f,0 x3822,0 xa409,0 x3f7e,XPD};
#define DP1 *(long double *)P1
#define DP2 *(long double *)P2
#define DP3 *(long double *)P3
#endif
#ifdef MIEEE
static unsigned short P1[] = {
0 x4000,0 x0000,0 xc90f,0 xdaa2,0 x2168,0 xc234
};
static unsigned short P2[] = {
0 x3fc0,0 x0000,0 xc4c60,0 x628b,0 x80dc,0 x1cd1
};
static unsigned short P3[] = {
0 x3f7e,0 x0000,0 xa409,0 x3822,0 x299f,0 x31d0
};
#define DP1 *(long double *)P1
#define DP2 *(long double *)P2
#define DP3 *(long double *)P3
#endif
static long double
redupil(x)
long double x;
{
long double t;
long i;
t = x/PIL;
if ( t >= 0 .0 L )
t += 0 .5 L;
else
t -= 0 .5 L;
i = t; /* the multiple */
t = i;
t = ((x - t * DP1) - t * DP2) - t * DP3;
return (t);
}
/* Taylor series expansion for cosh(2y) - cos(2x) */
static long double
ctansl(long double complex z)
{
long double f, x, x2, y, y2, rn, t;
long double d;
x = fabsl( 2 .0 L * creal(z) );
y = fabsl( 2 .0 L * cimag(z) );
x = redupil(x);
x = x * x;
y = y * y;
x2 = 1 .0 L;
y2 = 1 .0 L;
f = 1 .0 L;
rn = 0 .0 L;
d = 0 .0 L;
do
{
rn += 1 .0 L;
f *= rn;
rn += 1 .0 L;
f *= rn;
x2 *= x;
y2 *= y;
t = y2 + x2;
t /= f;
d += t;
rn += 1 .0 L;
f *= rn;
rn += 1 .0 L;
f *= rn;
x2 *= x;
y2 *= y;
t = y2 - x2;
t /= f;
d += t;
}
while ( fabsl(t/d) > MACHEPL );
return (d);
}
/* casinl()
*
* Complex circular arc sine
*
*
*
* SYNOPSIS :
*
* long double complex casinl ( ) ;
* long double complex z , w ;
*
* w = casinl ( z ) ;
*
*
*
* DESCRIPTION :
*
* Inverse complex sine :
*
* 2
* w = - i clog ( iz + csqrt ( 1 - z ) ) .
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* DEC - 10 , + 10 10100 2 . 1 e - 15 3 . 4 e - 16
* IEEE - 10 , + 10 30000 2 . 2 e - 14 2 . 7 e - 15
* Larger relative error can be observed for z near zero .
* Also tested by csin ( casin ( z ) ) = z .
*/
long double complex
casinl( long double complex z )
{
long double complex w;
long double x, y, b;
static long double complex ca, ct, zz, z2;
x = creal(z);
y = cimag(z);
if ( y == 0 .0 L )
{
if ( fabsl(x) > 1 .0 L )
{
w = PIO2L + 0 .0 L * I;
mtherr( "casinl" , DOMAIN );
}
else
{
w = asinl(x) + 0 .0 L * I;
}
return (w);
}
/* Power series expansion */
b = cabsl(z);
if ( b < 0 .125 L )
{
long double complex sum;
long double n, cn;
z2 = (x - y) * (x + y) + (2 .0 L * x * y) * I;
cn = 1 .0 L;
n = 1 .0 L;
ca = x + y * I;
sum = x + y * I;
do
{
ct = z2 * ca;
ca = ct;
cn *= n;
n += 1 .0 L;
cn /= n;
n += 1 .0 L;
b = cn/n;
ct *= b;
sum += ct;
b = cabsl(ct);
}
while ( b > MACHEPL );
w = sum;
return w;
}
ca = x + y * I;
ct = ca * I; /* iz */
/* sqrt( 1 - z*z) */
/* cmul( &ca, &ca, &zz ) */
/*x * x - y * y */
zz = (x - y) * (x + y) + (2 .0 L * x * y) * I;
zz = 1 .0 L - creal(zz) - cimag(zz) * I;
z2 = csqrtl (zz);
zz = ct + z2;
zz = clogl (zz);
/* multiply by 1/i = -i */
w = zz * (-1 .0 L * I);
return (w);
}
/* cacosl()
*
* Complex circular arc cosine
*
*
*
* SYNOPSIS :
*
* long double complex cacosl ( ) ;
* long double complex z , w ;
*
* w = cacosl ( z ) ;
*
*
*
* DESCRIPTION :
*
*
* w = arccos z = PI / 2 - arcsin z .
*
*
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* DEC - 10 , + 10 5200 1 . 6 e - 15 2 . 8 e - 16
* IEEE - 10 , + 10 30000 1 . 8 e - 14 2 . 2 e - 15
*/
long double complex
cacosl( long double complex z )
{
long double complex w;
w = casinl( z );
w = (PIO2L - creal(w)) - cimag(w) * I;
return (w);
}
/* catanl()
*
* Complex circular arc tangent
*
*
*
* SYNOPSIS :
*
* long double complex catanl ( ) ;
* long double complex z , w ;
*
* w = catanl ( z ) ;
*
*
*
* DESCRIPTION :
*
* If
* z = x + iy ,
*
* then
* 1 ( 2 x )
* Re w = - arctan ( - - - - - - - - - - - ) + k PI
* 2 ( 2 2 )
* ( 1 - x - y )
*
* ( 2 2 )
* 1 ( x + ( y + 1 ) )
* Im w = - log ( - - - - - - - - - - - - )
* 4 ( 2 2 )
* ( x + ( y - 1 ) )
*
* Where k is an arbitrary integer .
*
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* DEC - 10 , + 10 5900 1 . 3 e - 16 7 . 8 e - 18
* IEEE - 10 , + 10 30000 2 . 3 e - 15 8 . 5 e - 17
* The check catan ( ctan ( z ) ) = z , with | x | and | y | < PI / 2 ,
* had peak relative error 1 . 5 e - 16 , rms relative error
* 2 . 9 e - 17 . See also clog ( ) .
*/
long double complex
catanl( long double complex z )
{
long double complex w;
long double a, t, x, x2, y;
x = creal(z);
y = cimag(z);
if ( (x == 0 .0 L) && (y > 1 .0 L) )
goto ovrf;
x2 = x * x;
a = 1 .0 L - x2 - (y * y);
if ( a == 0 .0 L )
goto ovrf;
t = atan2l( 2 .0 L * x, a ) * 0 .5 L;
w = redupil( t );
t = y - 1 .0 L;
a = x2 + (t * t);
if ( a == 0 .0 L )
goto ovrf;
t = y + 1 .0 L;
a = (x2 + (t * t))/a;
w = w + (0 .25 L * logl(a)) * I;
return (w);
ovrf:
mtherr( "catanl" , OVERFLOW );
w = MAXNUML + MAXNUML * I;
return (w);
}
/* csinhl
*
* Complex hyperbolic sine
*
*
*
* SYNOPSIS :
*
* long double complex csinhl ( ) ;
* long double complex z , w ;
*
* w = csinhl ( z ) ;
*
* DESCRIPTION :
*
* csinh z = ( cexp ( z ) - cexp ( - z ) ) / 2
* = sinh x * cos y + i cosh x * sin y .
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* IEEE - 10 , + 10 30000 3 . 1 e - 16 8 . 2 e - 17
*
*/
long double complex
csinhl (long double complex z)
{
long double complex w;
long double x, y;
x = creal(z);
y = cimag(z);
w = sinhl (x) * cosl (y) + (coshl (x) * sinl (y)) * I;
return (w);
}
/* casinhl
*
* Complex inverse hyperbolic sine
*
*
*
* SYNOPSIS :
*
* long double complex casinhf ( ) ;
* long double complex z , w ;
*
* w = casinhl ( z ) ;
*
*
*
* DESCRIPTION :
*
* casinh z = - i casin iz .
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* IEEE - 10 , + 10 30000 1 . 8 e - 14 2 . 6 e - 15
*
*/
long double complex
casinhl (long double complex z)
{
long double complex w;
w = -1 .0 L * I * casinl (z * I);
return (w);
}
/* ccoshl
*
* Complex hyperbolic cosine
*
*
*
* SYNOPSIS :
*
* long double complex ccoshl ( ) ;
* long double complex z , w ;
*
* w = ccoshl ( z ) ;
*
*
*
* DESCRIPTION :
*
* ccosh ( z ) = cosh x cos y + i sinh x sin y .
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* IEEE - 10 , + 10 30000 2 . 9 e - 16 8 . 1 e - 17
*
*/
long double complex
ccoshl (long double complex z)
{
long double complex w;
long double x, y;
x = creal(z);
y = cimag(z);
w = coshl (x) * cosl (y) + (sinhl (x) * sinl (y)) * I;
return (w);
}
/* cacoshl
*
* Complex inverse hyperbolic cosine
*
*
*
* SYNOPSIS :
*
* long double complex cacoshl ( ) ;
* long double complex z , w ;
*
* w = cacoshl ( z ) ;
*
*
*
* DESCRIPTION :
*
* acosh z = i acos z .
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* IEEE - 10 , + 10 30000 1 . 6 e - 14 2 . 1 e - 15
*
*/
long double complex
cacoshl (long double complex z)
{
long double complex w;
w = I * cacosl (z);
return (w);
}
/* ctanhl
*
* Complex hyperbolic tangent
*
*
*
* SYNOPSIS :
*
* long double complex ctanhl ( ) ;
* long double complex z , w ;
*
* w = ctanhl ( z ) ;
*
*
*
* DESCRIPTION :
*
* tanh z = ( sinh 2 x + i sin 2 y ) / ( cosh 2 x + cos 2 y ) .
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* IEEE - 10 , + 10 30000 1 . 7 e - 14 2 . 4 e - 16
*
*/
long double complex
ctanhl (long double complex z)
{
long double complex w;
long double x, y, d;
x = creal(z);
y = cimag(z);
d = coshl (2 .0 L * x) + cosl (2 .0 L * y);
w = sinhl (2 .0 L * x) / d + (sinl (2 .0 L * y) / d) * I;
return (w);
}
/* catanhl
*
* Complex inverse hyperbolic tangent
*
*
*
* SYNOPSIS :
*
* long double complex catanhl ( ) ;
* long double complex z , w ;
*
* w = catanhl ( z ) ;
*
*
*
* DESCRIPTION :
*
* Inverse tanh , equal to - i catan ( iz ) ;
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* IEEE - 10 , + 10 30000 2 . 3 e - 16 6 . 2 e - 17
*
*/
long double complex
catanhl (long double complex z)
{
long double complex w;
w = -1 .0 L * I * catanl (z * I);
return (w);
}
/* cpowl
*
* Complex power function
*
*
*
* SYNOPSIS :
*
* long double complex cpowl ( ) ;
* long double complex a , z , w ;
*
* w = cpowl ( a , z ) ;
*
*
*
* DESCRIPTION :
*
* Raises complex A to the complex Zth power .
* Definition is per AMS55 # 4 . 2 . 8 ,
* analytically equivalent to cpow ( a , z ) = cexp ( z clog ( a ) ) .
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* IEEE - 10 , + 10 30000 9 . 4 e - 15 1 . 5 e - 15
*
*/
long double complex
cpowl (long double complex a, long double complex z)
{
long double complex w;
long double x, y, r, theta, absa, arga;
x = creal (z);
y = cimag (z);
absa = cabsl (a);
if (absa == 0 .0 L)
{
return (0 .0 L + 0 .0 L * I);
}
arga = cargl (a);
r = powl (absa, x);
theta = x * arga;
if (y != 0 .0 L)
{
r = r * expl (-y * arga);
theta = theta + y * logl (absa);
}
w = r * cosl (theta) + (r * sinl (theta)) * I;
return (w);
}
Messung V0.5 in Prozent C=98 H=96 G=96
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-06-18)
¤
*© Formatika GbR, Deutschland