NAME
Math::Cephes - perl interface to the cephes math library
SYNOPSIS
use Math::Cephes qw(:all);
DESCRIPTION
This module provides an interface to over 150 functions of thecephes math library of Stephen Moshier. No functions are exportedby default, but rather must be imported explicitly, as inuse Math::Cephes qw(sin cos);There are a number of export tags defined which allowimporting groups of functions:
- use Math::Cephes qw(:constants);
-
imports the variables$PI : 3.14159265358979323846 # pi$PIO2 : 1.57079632679489661923 # pi/2$PIO4 : 0.785398163397448309616 # pi/4$SQRT2 : 1.41421356237309504880 # sqrt(2)$SQRTH : 0.707106781186547524401 # sqrt(2)/2$LOG2E : 1.4426950408889634073599 # 1/log(2)$SQ2OPI : 0.79788456080286535587989 # sqrt( 2/pi )$LOGE2 : 0.693147180559945309417 # log(2)$LOGSQ2 : 0.346573590279972654709 # log(2)/2$THPIO4 : 2.35619449019234492885 # 3*pi/4$TWOOPI : 0.636619772367581343075535 # 2/piAs well, there are 4 machine-specific numbers available:$MACHEP : machine roundoff error$MAXLOG : maximum log on the machine$MINLOG : minimum log on the machine$MAXNUM : largest number represented
- use Math::Cephes qw(:trigs);
-
importsacos: Inverse circular cosineasin: Inverse circular sineatan: Inverse circular tangent (arctangent)atan2: Quadrant correct inverse circular tangentcos: Circular cosinecosdg: Circular cosine of angle in degreescot: Circular cotangentcotdg: Circular cotangent of argument in degreeshypot: hypotenuse associated with the sides of a right triangleradian: Degrees, minutes, seconds to radianssin: Circular sinesindg: Circular sine of angle in degreestan: Circular tangenttandg: Circular tangent of argument in degreescosm1: Relative error approximations for function arguments near unity
- use Math::Cephes qw(:hypers);
-
importsacosh: Inverse hyperbolic cosineasinh: Inverse hyperbolic sineatanh: Inverse hyperbolic tangentcosh: Hyperbolic cosinesinh: Hyperbolic sinetanh: Hyperbolic tangent
- use Math::Cephes qw(:explog);
-
importsexp: Exponential functionexpxx: exp(x*x)exp10: Base 10 exponential function (Common antilogarithm)exp2: Base 2 exponential functionlog: Natural logarithmlog10: Common logarithmlog2: Base 2 logarithmlog1p,expm1: Relative error approximations for function arguments near unity.
- use Math::Cephes qw(:cmplx);
-
importsnew_cmplx: create a new complex number objectcabs: Complex absolute valuecacos: Complex circular arc cosinecacosh: Complex inverse hyperbolic cosinecasin: Complex circular arc sinecasinh: Complex inverse hyperbolic sinecatan: Complex circular arc tangentcatanh: Complex inverse hyperbolic tangentccos: Complex circular cosineccosh: Complex hyperbolic cosineccot: Complex circular cotangentcexp: Complex exponential functionclog: Complex natural logarithmcadd: add two complex numberscsub: subtract two complex numberscmul: multiply two complex numberscdiv: divide two complex numberscmov: copy one complex number to anothercneg: negate a complex numbercpow: Complex power functioncsin: Complex circular sinecsinh: Complex hyperbolic sinecsqrt: Complex square rootctan: Complex circular tangentctanh: Complex hyperbolic tangent
- use Math::Cephes qw(:utils);
-
importscbrt: Cube rootceil: ceildrand: Pseudorandom number generatorfabs: Absolute valuefac: Factorial functionfloor: floorfrexp: frexpldexp: multiplies x by 2**n.lrand: Pseudorandom number generatorlsqrt: Integer square rootpow: Power functionpowi: Real raised to integer powerround: Round double to nearest or even integer valued doublesqrt: Square root
- use Math::Cephes qw(:bessels);
-
importsi0: Modified Bessel function of order zeroi0e: Modified Bessel function of order zero, exponentially scaledi1: Modified Bessel function of order onei1e: Modified Bessel function of order one, exponentially scalediv: Modified Bessel function of noninteger orderj0: Bessel function of order zeroj1: Bessel function of order onejn: Bessel function of integer orderjv: Bessel function of noninteger orderk0: Modified Bessel function, third kind, order zerok0e: Modified Bessel function, third kind, order zero, exponentially scaledk1: Modified Bessel function, third kind, order onek1e: Modified Bessel function, third kind, order one, exponentially scaledkn: Modified Bessel function, third kind, integer ordery0: Bessel function of the second kind, order zeroy1: Bessel function of second kind of order oneyn: Bessel function of second kind of integer orderyv: Bessel function Yv with noninteger v
- use Math::Cephes qw(:dists);
-
importsbdtr: Binomial distributionbdtrc: Complemented binomial distributionbdtri: Inverse binomial distributionbtdtr: Beta distributionchdtr: Chi-square distributionchdtrc: Complemented Chi-square distributionchdtri: Inverse of complemented Chi-square distributionfdtr: F distributionfdtrc: Complemented F distributionfdtri: Inverse of complemented F distributiongdtr: Gamma distribution functiongdtrc: Complemented gamma distribution functionnbdtr: Negative binomial distributionnbdtrc: Complemented negative binomial distributionnbdtri: Functional inverse of negative binomial distributionndtr: Normal distribution functionndtri: Inverse of Normal distribution functionpdtr: Poisson distributionpdtrc: Complemented poisson distributionpdtri: Inverse Poisson distributionstdtr: Student's t distributionstdtri: Functional inverse of Student's t distribution
- use Math::Cephes qw(:gammas);
-
importsfac: Factorial functiongamma: Gamma functionigam: Incomplete gamma integraligamc: Complemented incomplete gamma integraligami: Inverse of complemented imcomplete gamma integralpsi: Psi (digamma) functionrgamma: Reciprocal gamma function
- use Math::Cephes qw(:betas);
-
importsbeta: Beta functionincbet: Incomplete beta integralincbi: Inverse of imcomplete beta integrallbeta: Natural logarithm of |beta|
- use Math::Cephes qw(:elliptics);
-
importsellie: Incomplete elliptic integral of the second kindellik: Incomplete elliptic integral of the first kindellpe: Complete elliptic integral of the second kindellpj: Jacobian Elliptic Functionsellpk: Complete elliptic integral of the first kind
- use Math::Cephes qw(:hypergeometrics);
-
importshyp2f0: Gauss hypergeometric function Fhyp2f1: Gauss hypergeometric function Fhyperg: Confluent hypergeometric functiononef2: Hypergeometric function 1F2threef0: Hypergeometric function 3F0
- use Math::Cephes qw(:misc);
-
importsairy: Airy functionbernum: Bernoulli numbersdawsn: Dawson's Integralei: Exponential integralerf: Error functionerfc: Complementary error functionexpn: Exponential integral Enfresnl: Fresnel integralplancki: Integral of Planck's black body radiation formulapolylog: Polylogarithm functionshichi: Hyperbolic sine and cosine integralssici: Sine and cosine integralssimpson: Simpson's rule to find an integralspence: Dilogarithmstruve: Struve functionvecang: angle between two vectorszeta: Riemann zeta function of two argumentszetac: Riemann zeta function
- use Math::Cephes qw(:fract);
-
importsnew_fract: create a new fraction objectradd: add two fractionsrmul: multiply two fractionsrsub: subtracttwo fractionsrdiv: divide two fractionseuclid: finds the greatest common divisor
FUNCTIONS
A description of the various functions available follows.
- acosh: Inverse hyperbolic cosine
-
SYNOPSIS:# double x, y, acosh();$y = acosh( $x );DESCRIPTION:Returns inverse hyperbolic cosine of argument.If 1 <= x < 1.5, a rational approximationsqrt(z) * P(z)/Q(z)where z = x-1, is used. Otherwise,acosh(x) = log( x + sqrt( (x-1)(x+1) ).ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC 1,3 30000 4.2e-17 1.1e-17IEEE 1,3 30000 4.6e-16 8.7e-17ERROR MESSAGES:message condition value returnedacosh domain |x| < 1 NAN
- airy: Airy function
-
SYNOPSIS:# double x, ai, aiprime, bi, biprime;# int airy();($flag, $ai, $aiprime, $bi, $biprime) = airy( $x );DESCRIPTION:Solution of the differential equationy"(x) = xy.The function returns the two independent solutions Ai, Biand their first derivatives Ai'(x), Bi'(x).Evaluation is by power series summation for small x,by rational minimax approximations for large x.ACCURACY:Error criterion is absolute when function <= 1, relativewhen function > 1, except * denotes relative error criterion.For large negative x, the absolute error increases as x^1.5.For large positive x, the relative error increases as x^1.5.Arithmetic domain function # trials peak rmsIEEE -10, 0 Ai 10000 1.6e-15 2.7e-16IEEE 0, 10 Ai 10000 2.3e-14* 1.8e-15*IEEE -10, 0 Ai' 10000 4.6e-15 7.6e-16IEEE 0, 10 Ai' 10000 1.8e-14* 1.5e-15*IEEE -10, 10 Bi 30000 4.2e-15 5.3e-16IEEE -10, 10 Bi' 30000 4.9e-15 7.3e-16DEC -10, 0 Ai 5000 1.7e-16 2.8e-17DEC 0, 10 Ai 5000 2.1e-15* 1.7e-16*DEC -10, 0 Ai' 5000 4.7e-16 7.8e-17DEC 0, 10 Ai' 12000 1.8e-15* 1.5e-16*DEC -10, 10 Bi 10000 5.5e-16 6.8e-17DEC -10, 10 Bi' 7000 5.3e-16 8.7e-17
- radian: Degrees, minutes, seconds to radians
-
SYNOPSIS:# double d, m, s, radian();$r = radian( $d, $m, $s );DESCRIPTION:Converts an angle of degrees, minutes, seconds to radians.
- hypot: returns the hypotenuse associated with the sides of a right triangle
-
SYNOPSIS:# double a, b, c, hypot();$c = hypot( $a, $b );DESCRIPTION:Calculates the hypotenuse associated with the sides of aright triangle, according toc = sqrt( a**2 + b**2)
- asin: Inverse circular sine
-
SYNOPSIS:# double x, y, asin();$y = asin( $x );DESCRIPTION:Returns radian angle between -pi/2 and +pi/2 whose sine is x.A rational function of the form x + x**3 P(x**2)/Q(x**2)is used for |x| in the interval [0, 0.5]. If |x| > 0.5 it istransformed by the identityasin(x) = pi/2 - 2 asin( sqrt( (1-x)/2 ) ).ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -1, 1 40000 2.6e-17 7.1e-18IEEE -1, 1 10^6 1.9e-16 5.4e-17ERROR MESSAGES:message condition value returnedasin domain |x| > 1 NAN
- acos: Inverse circular cosine
-
SYNOPSIS:# double x, y, acos();$y = acos( $x );DESCRIPTION:Returns radian angle between 0 and pi whose cosineis x.Analytically, acos(x) = pi/2 - asin(x). However if |x| isnear 1, there is cancellation error in subtracting asin(x)from pi/2. Hence if x < -0.5,acos(x) = pi - 2.0 * asin( sqrt((1+x)/2) );or if x > +0.5,acos(x) = 2.0 * asin( sqrt((1-x)/2) ).ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -1, 1 50000 3.3e-17 8.2e-18IEEE -1, 1 10^6 2.2e-16 6.5e-17ERROR MESSAGES:message condition value returnedasin domain |x| > 1 NAN
- asinh: Inverse hyperbolic sine
-
SYNOPSIS:# double x, y, asinh();$y = asinh( $x );DESCRIPTION:Returns inverse hyperbolic sine of argument.If |x| < 0.5, the function is approximated by a rationalform x + x**3 P(x)/Q(x). Otherwise,asinh(x) = log( x + sqrt(1 + x*x) ).ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -3,3 75000 4.6e-17 1.1e-17IEEE -1,1 30000 3.7e-16 7.8e-17IEEE 1,3 30000 2.5e-16 6.7e-17
- atan: Inverse circular tangent (arctangent)
-
SYNOPSIS:# double x, y, atan();$y = atan( $x );DESCRIPTION:Returns radian angle between -pi/2 and +pi/2 whose tangentis x.Range reduction is from three intervals into the intervalfrom zero to 0.66. The approximant uses a rationalfunction of degree 4/5 of the form x + x**3 P(x)/Q(x).ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -10, 10 50000 2.4e-17 8.3e-18IEEE -10, 10 10^6 1.8e-16 5.0e-17
- atan2: Quadrant correct inverse circular tangent
-
SYNOPSIS:# double x, y, z, atan2();$z = atan2( $y, $x );DESCRIPTION:Returns radian angle whose tangent is y/x.Define compile time symbol ANSIC = 1 for ANSI standard,range -PI < z <= +PI, args (y,x); else ANSIC = 0 for range0 to 2PI, args (x,y).ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE -10, 10 10^6 2.5e-16 6.9e-17See atan.c.
- atanh: Inverse hyperbolic tangent
-
SYNOPSIS:# double x, y, atanh();$y = atanh( $x );DESCRIPTION:Returns inverse hyperbolic tangent of argument in the rangeMINLOG to MAXLOG.If |x| < 0.5, the rational form x + x**3 P(x)/Q(x) isemployed. Otherwise,atanh(x) = 0.5 * log( (1+x)/(1-x) ).ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -1,1 50000 2.4e-17 6.4e-18IEEE -1,1 30000 1.9e-16 5.2e-17
- bdtr: Binomial distribution
-
SYNOPSIS:# int k, n;# double p, y, bdtr();$y = bdtr( $k, $n, $p );DESCRIPTION:Returns the sum of the terms 0 through k of the Binomialprobability density:k-- ( n ) j n-j> ( ) p (1-p)-- ( j )j=0The terms are not summed directly; instead the incompletebeta integral is employed, according to the formulay = bdtr( k, n, p ) = incbet( n-k, k+1, 1-p ).The arguments must be positive, with p ranging from 0 to 1.ACCURACY:Tested at random points (a,b,p), with p between 0 and 1.a,b Relative error:arithmetic domain # trials peak rmsFor p between 0.001 and 1:IEEE 0,100 100000 4.3e-15 2.6e-16See also incbet.c.ERROR MESSAGES:message condition value returnedbdtr domain k < 0 0.0n < kx < 0, x > 1
- bdtrc: Complemented binomial distribution
-
SYNOPSIS:# int k, n;# double p, y, bdtrc();$y = bdtrc( $k, $n, $p );DESCRIPTION:Returns the sum of the terms k+1 through n of the Binomialprobability density:n-- ( n ) j n-j> ( ) p (1-p)-- ( j )j=k+1The terms are not summed directly; instead the incompletebeta integral is employed, according to the formulay = bdtrc( k, n, p ) = incbet( k+1, n-k, p ).The arguments must be positive, with p ranging from 0 to 1.ACCURACY:Tested at random points (a,b,p).a,b Relative error:arithmetic domain # trials peak rmsFor p between 0.001 and 1:IEEE 0,100 100000 6.7e-15 8.2e-16For p between 0 and .001:IEEE 0,100 100000 1.5e-13 2.7e-15ERROR MESSAGES:message condition value returnedbdtrc domain x<0, x>1, n<k 0.0
- bdtri: Inverse binomial distribution
-
SYNOPSIS:# int k, n;# double p, y, bdtri();$p = bdtr( $k, $n, $y );DESCRIPTION:Finds the event probability p such that the sum of theterms 0 through k of the Binomial probability densityis equal to the given cumulative probability y.This is accomplished using the inverse beta integralfunction and the relation1 - p = incbi( n-k, k+1, y ).ACCURACY:Tested at random points (a,b,p).a,b Relative error:arithmetic domain # trials peak rmsFor p between 0.001 and 1:IEEE 0,100 100000 2.3e-14 6.4e-16IEEE 0,10000 100000 6.6e-12 1.2e-13For p between 10^-6 and 0.001:IEEE 0,100 100000 2.0e-12 1.3e-14IEEE 0,10000 100000 1.5e-12 3.2e-14See also incbi.c.ERROR MESSAGES:message condition value returnedbdtri domain k < 0, n <= k 0.0x < 0, x > 1
- beta: Beta function
-
SYNOPSIS:# double a, b, y, beta();$y = beta( $a, $b );DESCRIPTION:- -| (a) | (b)beta( a, b ) = -----------.-| (a+b)For large arguments the logarithm of the function isevaluated using lgam(), then exponentiated.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC 0,30 1700 7.7e-15 1.5e-15IEEE 0,30 30000 8.1e-14 1.1e-14ERROR MESSAGES:message condition value returnedbeta overflow log(beta) > MAXLOG 0.0a or b <0 integer 0.0
- lbeta: Natural logarithm of |beta|
-
SYNOPSIS:# double a, b;# double lbeta( a, b );$y = lbeta( $a, $b);
- btdtr: Beta distribution
-
SYNOPSIS:# double a, b, x, y, btdtr();$y = btdtr( $a, $b, $x );DESCRIPTION:Returns the area from zero to x under the beta densityfunction:x- -| (a+b) | | a-1 b-1P(x) = ---------- | t (1-t) dt- - | || (a) | (b) -0This function is identical to the incomplete betaintegral function incbet(a, b, x).The complemented function is1 - P(1-x) = incbet( b, a, x );ACCURACY:See incbet.c.
- cbrt: Cube root
-
SYNOPSIS:# double x, y, cbrt();$y = cbrt( $x );DESCRIPTION:Returns the cube root of the argument, which may be negative.Range reduction involves determining the power of 2 ofthe argument. A polynomial of degree 2 applied to themantissa, and multiplication by the cube root of 1, 2, or 4approximates the root to within about 0.1%. Then Newton'siteration is used three times to converge to an accurateresult.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -10,10 200000 1.8e-17 6.2e-18IEEE 0,1e308 30000 1.5e-16 5.0e-17
- chdtr: Chi-square distribution
-
SYNOPSIS:# double v, x, y, chdtr();$y = chdtr( $v, $x );DESCRIPTION:Returns the area under the left hand tail (from 0 to x)of the Chi square probability density function withv degrees of freedom.inf.-1 | | v/2-1 -t/2P( x | v ) = ----------- | t e dtv/2 - | |2 | (v/2) -xwhere x is the Chi-square variable.The incomplete gamma integral is used, according to theformulay = chdtr( v, x ) = igam( v/2.0, x/2.0 ).The arguments must both be positive.ACCURACY:See igam().ERROR MESSAGES:message condition value returnedchdtr domain x < 0 or v < 1 0.0
- chdtrc: Complemented Chi-square distribution
-
SYNOPSIS:# double v, x, y, chdtrc();$y = chdtrc( $v, $x );DESCRIPTION:Returns the area under the right hand tail (from x toinfinity) of the Chi square probability density functionwith v degrees of freedom:inf.-1 | | v/2-1 -t/2P( x | v ) = ----------- | t e dtv/2 - | |2 | (v/2) -xwhere x is the Chi-square variable.The incomplete gamma integral is used, according to theformulay = chdtrc( v, x ) = igamc( v/2.0, x/2.0 ).The arguments must both be positive.ACCURACY:See igamc().ERROR MESSAGES:message condition value returnedchdtrc domain x < 0 or v < 1 0.0
- chdtri: Inverse of complemented Chi-square distribution
-
SYNOPSIS:# double df, x, y, chdtri();$x = chdtri( $df, $y );DESCRIPTION:Finds the Chi-square argument x such that the integralfrom x to infinity of the Chi-square density is equalto the given cumulative probability y.This is accomplished using the inverse gamma integralfunction and the relationx/2 = igami( df/2, y );ACCURACY:See igami.c.ERROR MESSAGES:message condition value returnedchdtri domain y < 0 or y > 1 0.0v < 1
- clog: Complex natural logarithm
-
SYNOPSIS:# void clog();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();clog($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION:Returns complex logarithm to the base e (2.718...) ofthe complex argument x.If z = x + iy, r = sqrt( x**2 + y**2 ),thenw = log(r) + i arctan(y/x).The arctangent ranges from -PI to +PI.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -10,+10 7000 8.5e-17 1.9e-17IEEE -10,+10 30000 5.0e-15 1.1e-16Larger relative error can be observed for z near 1 +i0.In IEEE arithmetic the peak absolute error is 5.2e-16, rmsabsolute error 1.0e-16.
- cexp: Complex exponential function
-
SYNOPSIS:# void cexp();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();cexp($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION:Returns the exponential of the complex argument zinto the complex result w.Ifz = x + iy,r = exp(x),thenw = r cos y + i r sin y.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -10,+10 8700 3.7e-17 1.1e-17IEEE -10,+10 30000 3.0e-16 8.7e-17
- csin: Complex circular sine
-
SYNOPSIS:# void csin();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();csin($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION:Ifz = x + iy,thenw = sin x cosh y + i cos x sinh y.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -10,+10 8400 5.3e-17 1.3e-17IEEE -10,+10 30000 3.8e-16 1.0e-16Also tested by csin(casin(z)) = z.
- ccos: Complex circular cosine
-
SYNOPSIS:# void ccos();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();ccos($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION:Ifz = x + iy,thenw = cos x cosh y - i sin x sinh y.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -10,+10 8400 4.5e-17 1.3e-17IEEE -10,+10 30000 3.8e-16 1.0e-16
- ctan: Complex circular tangent
-
SYNOPSIS:# void ctan();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();ctan($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION:Ifz = x + iy,thensin 2x + i sinh 2yw = --------------------.cos 2x + cosh 2yOn the real axis the denominator is zero at odd multiplesof PI/2. The denominator is evaluated by its Taylorseries near these points.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -10,+10 5200 7.1e-17 1.6e-17IEEE -10,+10 30000 7.2e-16 1.2e-16Also tested by ctan * ccot = 1 and catan(ctan(z)) = z.
- ccot: Complex circular cotangent
-
SYNOPSIS:# void ccot();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();ccot($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION:Ifz = x + iy,thensin 2x - i sinh 2yw = --------------------.cosh 2y - cos 2xOn the real axis, the denominator has zeros at evenmultiples of PI/2. Near these points it is evaluatedby a Taylor series.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -10,+10 3000 6.5e-17 1.6e-17IEEE -10,+10 30000 9.2e-16 1.2e-16Also tested by ctan * ccot = 1 + i0.
- casin: Complex circular arc sine
-
SYNOPSIS:# void casin();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();casin($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION:Inverse complex sine:2w = -i clog( iz + csqrt( 1 - z ) ).ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -10,+10 10100 2.1e-15 3.4e-16IEEE -10,+10 30000 2.2e-14 2.7e-15Larger relative error can be observed for z near zero.Also tested by csin(casin(z)) = z.
- cacos: Complex circular arc cosine
-
SYNOPSIS:# void cacos();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();cacos($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION:w = arccos z = PI/2 - arcsin z.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -10,+10 5200 1.6e-15 2.8e-16IEEE -10,+10 30000 1.8e-14 2.2e-15
- catan: Complex circular arc tangent
-
SYNOPSIS:# void catan();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();catan($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION:Ifz = x + iy,then1 ( 2x )Re w = - arctan(-----------) + k PI2 ( 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 rmsDEC -10,+10 5900 1.3e-16 7.8e-18IEEE -10,+10 30000 2.3e-15 8.5e-17The check catan( ctan(z) ) = z, with |x| and |y| < PI/2,had peak relative error 1.5e-16, rms relative error2.9e-17. See also clog().
- csinh: Complex hyperbolic sine
-
SYNOPSIS:# void csinh();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();csinh($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION:csinh z = (cexp(z) - cexp(-z))/2= sinh x * cos y + i cosh x * sin y .ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE -10,+10 30000 3.1e-16 8.2e-17
- casinh: Complex inverse hyperbolic sine
-
SYNOPSIS:# void casinh();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();casinh($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wprint_new_cmplx($w); # prints $w as Re($w) + i Im($w)DESCRIPTION:casinh z = -i casin iz .ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE -10,+10 30000 1.8e-14 2.6e-15
- ccosh: Complex hyperbolic cosine
-
SYNOPSIS:# void ccosh();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();ccosh($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION:ccosh(z) = cosh x cos y + i sinh x sin y .ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE -10,+10 30000 2.9e-16 8.1e-17
- cacosh: Complex inverse hyperbolic cosine
-
SYNOPSIS:# void cacosh();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();cacosh($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION:acosh z = i acos z .ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE -10,+10 30000 1.6e-14 2.1e-15
- ctanh: Complex hyperbolic tangent
-
SYNOPSIS:# void ctanh();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();ctanh($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION:tanh z = (sinh 2x + i sin 2y) / (cosh 2x + cos 2y) .ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE -10,+10 30000 1.7e-14 2.4e-16
- catanh: Complex inverse hyperbolic tangent
-
SYNOPSIS:# void catanh();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();catanh($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION:Inverse tanh, equal to -i catan (iz);ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE -10,+10 30000 2.3e-16 6.2e-17
- cpow: Complex power function
-
SYNOPSIS:# void cpow();# cmplx a, z, w;$a = new_cmplx(5, 6); # $z = 5 + 6 i$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();cpow($a, $z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION: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 rmsIEEE -10,+10 30000 9.4e-15 1.5e-15
- cmplx: Complex number arithmetic
-
SYNOPSIS:# typedef struct {# double r; real part# double i; imaginary part# }cmplx;# cmplx *a, *b, *c;$a = new_cmplx(3, 5); # $a = 3 + 5 i$b = new_cmplx(2, 3); # $b = 2 + 3 i$c = new_cmplx();cadd( $a, $b, $c ); # c = b + acsub( $a, $b, $c ); # c = b - acmul( $a, $b, $c ); # c = b * acdiv( $a, $b, $c ); # c = b / acneg( $c ); # c = -ccmov( $b, $c ); # c = bprint $c->{r}, ' ', $c->{i}; # prints real and imaginary parts of $cDESCRIPTION:Addition:c.r = b.r + a.rc.i = b.i + a.iSubtraction:c.r = b.r - a.rc.i = b.i - a.iMultiplication:c.r = b.r * a.r - b.i * a.ic.i = b.r * a.i + b.i * a.rDivision:d = a.r * a.r + a.i * a.ic.r = (b.r * a.r + b.i * a.i)/dc.i = (b.i * a.r - b.r * a.i)/dACCURACY:In DEC arithmetic, the test (1/z) * z = 1 had peak relativeerror 3.1e-17, rms 1.2e-17. The test (y/z) * (z/y) = 1 hadpeak relative error 8.3e-17, rms 2.1e-17.Tests in the rectangle {-10,+10}:Relative error:arithmetic function # trials peak rmsDEC cadd 10000 1.4e-17 3.4e-18IEEE cadd 100000 1.1e-16 2.7e-17DEC csub 10000 1.4e-17 4.5e-18IEEE csub 100000 1.1e-16 3.4e-17DEC cmul 3000 2.3e-17 8.7e-18IEEE cmul 100000 2.1e-16 6.9e-17DEC cdiv 18000 4.9e-17 1.3e-17IEEE cdiv 100000 3.7e-16 1.1e-16
- cabs: Complex absolute value
-
SYNOPSIS:# double a, cabs();# cmplx z;$z = new_cmplx(2, 3); # $z = 2 + 3 i$a = cabs( $z );DESCRIPTION:If z = x + iythena = sqrt( x**2 + y**2 ).Overflow and underflow are avoided by testing the magnitudesof x and y before squaring. If either is outside half ofthe floating point full scale range, both are rescaled.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -30,+30 30000 3.2e-17 9.2e-18IEEE -10,+10 100000 2.7e-16 6.9e-17
- csqrt: Complex square root
-
SYNOPSIS:# void csqrt();# cmplx z, w;$z = new_cmplx(2, 3); # $z = 2 + 3 i$w = new_cmplx();csqrt($z, $w );print $w->{r}, ' ', $w->{i}; # prints real and imaginary parts of $wDESCRIPTION:If z = x + iy, r = |z|, then1/2Im w = [ (r - x)/2 ] ,Re w = y / 2 Im w.Note that -w is also a square root of z. The root chosenis always in the upper half plane.Because of the potential for cancellation error in r - x,the result is sharpened by doing a Heron iteration(see sqrt.c) in complex arithmetic.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -10,+10 25000 3.2e-17 9.6e-18IEEE -10,+10 100000 3.2e-16 7.7e-172Also tested by csqrt( z ) = z, and tested by argumentsclose to the real axis.
- machconst: Globally declared constants
-
SYNOPSIS:extern double nameofconstant;DESCRIPTION:This file contains a number of mathematical constants andalso some needed size parameters of the computer arithmetic.The values are supplied as arrays of hexadecimal integersfor IEEE arithmetic; arrays of octal constants for DECarithmetic; and in a normal decimal scientific notation forother machines. The particular notation used is determinedby a symbol (DEC, IBMPC, or UNK) defined in the include filemconf.h.The default size parameters are as follows.For DEC and UNK modes:MACHEP = 1.38777878078144567553E-17 2**-56MAXLOG = 8.8029691931113054295988E1 log(2**127)MINLOG = -8.872283911167299960540E1 log(2**-128)MAXNUM = 1.701411834604692317316873e38 2**127For IEEE arithmetic (IBMPC):MACHEP = 1.11022302462515654042E-16 2**-53MAXLOG = 7.09782712893383996843E2 log(2**1024)MINLOG = -7.08396418532264106224E2 log(2**-1022)MAXNUM = 1.7976931348623158E308 2**1024These lists are subject to change.
- cosh: Hyperbolic cosine
-
SYNOPSIS:# double x, y, cosh();$y = cosh( $x );DESCRIPTION:Returns hyperbolic cosine of argument in the range MINLOG toMAXLOG.cosh(x) = ( exp(x) + exp(-x) )/2.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC +- 88 50000 4.0e-17 7.7e-18IEEE +-MAXLOG 30000 2.6e-16 5.7e-17ERROR MESSAGES:message condition value returnedcosh overflow |x| > MAXLOG MAXNUM
- dawsn: Dawson's Integral
-
SYNOPSIS:# double x, y, dawsn();$y = dawsn( $x );DESCRIPTION:Approximates the integralx-2 | | 2dawsn(x) = exp( -x ) | exp( t ) dt| |-0Three different rational approximations are employed, forthe intervals 0 to 3.25; 3.25 to 6.25; and 6.25 up.ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE 0,10 10000 6.9e-16 1.0e-16DEC 0,10 6000 7.4e-17 1.4e-17
- drand: Pseudorandom number generator
-
SYNOPSIS:# double y, drand();($flag, $y) = drand( );DESCRIPTION:Yields a random number 1.0 <= y < 2.0.The three-generator congruential algorithm by BrianWichmann and David Hill (BYTE magazine, March, 1987,pp 127-8) is used. The period, given by them, is6953607871644.Versions invoked by the different arithmetic compiletime options DEC, IBMPC, and MIEEE, produceapproximately the same sequences, differing only in theleast significant bits of the numbers. The UNK optionimplements the algorithm as recommended in the BYTEarticle. It may be used on all computers. However,the low order bits of a double precision number maynot be adequately random, and may vary due to arithmeticimplementation details on different computers.The other compile options generate an additional randominteger that overwrites the low order bits of the doubleprecision number. This reduces the period by a factor oftwo but tends to overcome the problems mentioned.
- ellie: Incomplete elliptic integral of the second kind
-
SYNOPSIS:# double phi, m, y, ellie();$y = ellie( $phi, $m );DESCRIPTION:Approximates the integralphi-| || 2E(phi_\m) = | sqrt( 1 - m sin t ) dt|| |-0of amplitude phi and modulus m, using the arithmetic -geometric mean algorithm.ACCURACY:Tested at random arguments with phi in [-10, 10] and m in[0, 1].Relative error:arithmetic domain # trials peak rmsDEC 0,2 2000 1.9e-16 3.4e-17IEEE -10,10 150000 3.3e-15 1.4e-16
- ellik: Incomplete elliptic integral of the first kind
-
SYNOPSIS:# double phi, m, y, ellik();$y = ellik( $phi, $m );DESCRIPTION:Approximates the integralphi-| || dtF(phi_\m) = | ------------------| 2| | sqrt( 1 - m sin t )-0of amplitude phi and modulus m, using the arithmetic -geometric mean algorithm.ACCURACY:Tested at random points with m in [0, 1] and phi as indicated.Relative error:arithmetic domain # trials peak rmsIEEE -10,10 200000 7.4e-16 1.0e-16
- ellpe: Complete elliptic integral of the second kind
-
SYNOPSIS:# double m1, y, ellpe();$y = ellpe( $m1 );DESCRIPTION:Approximates the integralpi/2-| | 2E(m) = | sqrt( 1 - m sin t ) dt| |-0Where m = 1 - m1, using the approximationP(x) - x log x Q(x).Though there are no singularities, the argument m1 is usedrather than m for compatibility with ellpk().E(1) = 1; E(0) = pi/2.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC 0, 1 13000 3.1e-17 9.4e-18IEEE 0, 1 10000 2.1e-16 7.3e-17ERROR MESSAGES:message condition value returnedellpe domain x<0, x>1 0.0
- ellpj: Jacobian Elliptic Functions
-
SYNOPSIS:# double u, m, sn, cn, dn, phi;# int ellpj();($flag, $sn, $cn, $dn, $phi) = ellpj( $u, $m );DESCRIPTION:Evaluates the Jacobian elliptic functions sn(u|m), cn(u|m),and dn(u|m) of parameter m between 0 and 1, and realargument u.These functions are periodic, with quarter-period on thereal axis equal to the complete elliptic integralellpk(1.0-m).Relation to incomplete elliptic integral:If u = ellik(phi,m), then sn(u|m) = sin(phi),and cn(u|m) = cos(phi). Phi is called the amplitude of u.Computation is by means of the arithmetic-geometric meanalgorithm, except when m is within 1e-9 of 0 or 1. In thelatter case with m close to 1, the approximation appliesonly for phi < pi/2.ACCURACY:Tested at random points with u between 0 and 10, m between0 and 1.Absolute error (* = relative error):arithmetic function # trials peak rmsDEC sn 1800 4.5e-16 8.7e-17IEEE phi 10000 9.2e-16* 1.4e-16*IEEE sn 50000 4.1e-15 4.6e-16IEEE cn 40000 3.6e-15 4.4e-16IEEE dn 10000 1.3e-12 1.8e-14Peak error observed in consistency check using additiontheorem for sn(u+v) was 4e-16 (absolute). Also tested bythe above relation to the incomplete elliptic integral.Accuracy deteriorates when u is large.
- ellpk: Complete elliptic integral of the first kind
-
SYNOPSIS:# double m1, y, ellpk();$y = ellpk( $m1 );DESCRIPTION:Approximates the integralpi/2-| || dtK(m) = | ------------------| 2| | sqrt( 1 - m sin t )-0where m = 1 - m1, using the approximationP(x) - log x Q(x).The argument m1 is used rather than m so that the logarithmicsingularity at m = 1 will be shifted to the origin; thispreserves maximum accuracy.K(0) = pi/2.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC 0,1 16000 3.5e-17 1.1e-17IEEE 0,1 30000 2.5e-16 6.8e-17ERROR MESSAGES:message condition value returnedellpk domain x<0, x>1 0.0
- euclid: Rational arithmetic routines
-
SYNOPSIS:# typedef struct# {# double n; numerator# double d; denominator# }fract;$a = new_fract(3, 4); # a = 3 / 4$b = new_fract(2, 3); # b = 2 / 3$c = new_fract();radd( $a, $b, $c ); # c = b + arsub( $a, $b, $c ); # c = b - armul( $a, $b, $c ); # c = b * ardiv( $a, $b, $c ); # c = b / aprint $c->{n}, ' ', $c->{d}; # prints numerator and denominator of $c($gcd, $m_reduced, $n_reduced) = euclid($m, $n);# returns the greatest common divisor of $m and $n, as well as# the result of reducing $m and $n by $gcdArguments of the routines are pointers to the structures.The double precision numbers are assumed, without checking,to be integer valued. Overflow conditions are reported.
- exp: Exponential function
-
SYNOPSIS:# double x, y, exp();$y = exp( $x );DESCRIPTION:Returns e (2.71828...) raised to the x power.Range reduction is accomplished by separating the argumentinto an integer k and fraction f such thatx k fe = 2 e.A Pade' form 1 + 2x P(x**2)/( Q(x**2) - P(x**2) )of degree 2/3 is used to approximate exp(f) in the basicinterval [-0.5, 0.5].ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC +- 88 50000 2.8e-17 7.0e-18IEEE +- 708 40000 2.0e-16 5.6e-17Error amplification in the exponential function can bea serious matter. The error propagation involvesexp( X(1+delta) ) = exp(X) ( 1 + X*delta + ... ),which shows that a 1 lsb error in representing X producesa relative error of X times 1 lsb in the function.While the routine gives an accurate result for argumentsthat are exactly represented by a double precisioncomputer number, the result contains amplified roundofferror for large arguments not exactly represented.ERROR MESSAGES:message condition value returnedexp underflow x < MINLOG 0.0exp overflow x > MAXLOG INFINITY
- expxx: exp(x*x)
-
# double x, y, expxx();# int sign;$y = expxx( $x, $sign );DESCRIPTION:Computes y = exp(x*x) while suppressing error amplificationthat would ordinarily arise from the inexactness of theexponential argument x*x.If sign < 0, exp(-x*x) is returned.If sign > 0, or omitted, exp(x*x) is returned.ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE -26.6, 26.6 10^7 3.9e-16 8.9e-17
- exp10: Base 10 exponential function (Common antilogarithm)
-
SYNOPSIS:# double x, y, exp10();$y = exp10( $x );DESCRIPTION:Returns 10 raised to the x power.Range reduction is accomplished by expressing the argumentas 10**x = 2**n 10**f, with |f| < 0.5 log10(2).The Pade' form1 + 2x P(x**2)/( Q(x**2) - P(x**2) )is used to approximate 10**f.ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE -307,+307 30000 2.2e-16 5.5e-17Test result from an earlier version (2.1):DEC -38,+38 70000 3.1e-17 7.0e-18ERROR MESSAGES:message condition value returnedexp10 underflow x < -MAXL10 0.0exp10 overflow x > MAXL10 MAXNUMDEC arithmetic: MAXL10 = 38.230809449325611792.IEEE arithmetic: MAXL10 = 308.2547155599167.
- exp2: Base 2 exponential function
-
SYNOPSIS:# double x, y, exp2();$y = exp2( $x );DESCRIPTION:Returns 2 raised to the x power.Range reduction is accomplished by separating the argumentinto an integer k and fraction f such thatx k f2 = 2 2.A Pade' form1 + 2x P(x**2) / (Q(x**2) - x P(x**2) )approximates 2**x in the basic range [-0.5, 0.5].ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE -1022,+1024 30000 1.8e-16 5.4e-17See exp.c for comments on error amplification.ERROR MESSAGES:message condition value returnedexp underflow x < -MAXL2 0.0exp overflow x > MAXL2 MAXNUMFor DEC arithmetic, MAXL2 = 127.For IEEE arithmetic, MAXL2 = 1024.
- ei: Exponential integral
-
SYNOPSIS:#double x, y, ei();$y = ei( $x );DESCRIPTION:x- t| | eEi(x) = -|- --- dt .| | t--infNot defined for x <= 0.See also expn.c.ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE 0,100 50000 8.6e-16 1.3e-16
- expn: Exponential integral En
-
SYNOPSIS:# int n;# double x, y, expn();$y = expn( $n, $x );DESCRIPTION:Evaluates the exponential integralinf.-| | -xt| eE (x) = | ---- dt.n | n| | t-1Both n and x must be nonnegative.The routine employs either a power series, a continuedfraction, or an asymptotic formula depending on therelative values of n and x.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC 0, 30 5000 2.0e-16 4.6e-17IEEE 0, 30 10000 1.7e-15 3.6e-16
- fabs: Absolute value
-
SYNOPSIS:# double x, y;$y = fabs( $x );DESCRIPTION:Returns the absolute value of the argument.
- fac: Factorial function
-
SYNOPSIS:# double y, fac();# int i;$y = fac( $i );DESCRIPTION:Returns factorial of i = 1 * 2 * 3 * ... * i.fac(0) = 1.0.Due to machine arithmetic bounds the largest value ofi accepted is 33 in DEC arithmetic or 170 in IEEEarithmetic. Greater values, or negative ones,produce an error message and return MAXNUM.ACCURACY:For i < 34 the values are simply tabulated, and havefull machine accuracy. If i > 55, fac(i) = gamma(i+1);see gamma.c.Relative error:arithmetic domain peakIEEE 0, 170 1.4e-15DEC 0, 33 1.4e-17
- fdtr: F distribution
-
SYNOPSIS:# int df1, df2;# double x, y, fdtr();$y = fdtr( $df1, $df2, $x );DESCRIPTION:Returns the area from zero to x under the F densityfunction (also known as Snedcor's density or thevariance ratio density). This is the densityof x = (u1/df1)/(u2/df2), where u1 and u2 are randomvariables having Chi square distributions with df1and df2 degrees of freedom, respectively.The incomplete beta integral is used, according to theformulaP(x) = incbet( df1/2, df2/2, df1*x/(df2 + df1*x) ).The arguments a and b are greater than zero, and x isnonnegative.ACCURACY:Tested at random points (a,b,x).x a,b Relative error:arithmetic domain domain # trials peak rmsIEEE 0,1 0,100 100000 9.8e-15 1.7e-15IEEE 1,5 0,100 100000 6.5e-15 3.5e-16IEEE 0,1 1,10000 100000 2.2e-11 3.3e-12IEEE 1,5 1,10000 100000 1.1e-11 1.7e-13See also incbet.c.ERROR MESSAGES:message condition value returnedfdtr domain a<0, b<0, x<0 0.0
- fdtrc: Complemented F distribution
-
SYNOPSIS:# int df1, df2;# double x, y, fdtrc();$y = fdtrc( $df1, $df2, $x );DESCRIPTION:Returns the area from x to infinity under the F densityfunction (also known as Snedcor's density or thevariance ratio density).inf.-1 | | a-1 b-11-P(x) = ------ | t (1-t) dtB(a,b) | |-xThe incomplete beta integral is used, according to theformulaP(x) = incbet( df2/2, df1/2, df2/(df2 + df1*x) ).ACCURACY:Tested at random points (a,b,x) in the indicated intervals.x a,b Relative error:arithmetic domain domain # trials peak rmsIEEE 0,1 1,100 100000 3.7e-14 5.9e-16IEEE 1,5 1,100 100000 8.0e-15 1.6e-15IEEE 0,1 1,10000 100000 1.8e-11 3.5e-13IEEE 1,5 1,10000 100000 2.0e-11 3.0e-12See also incbet.c.ERROR MESSAGES:message condition value returnedfdtrc domain a<0, b<0, x<0 0.0
- fdtri: Inverse of complemented F distribution
-
SYNOPSIS:# int df1, df2;# double x, p, fdtri();$x = fdtri( $df1, $df2, $p );DESCRIPTION:Finds the F density argument x such that the integralfrom x to infinity of the F density is equal to thegiven probability p.This is accomplished using the inverse beta integralfunction and the relationsz = incbi( df2/2, df1/2, p )x = df2 (1-z) / (df1 z).Note: the following relations hold for the inverse ofthe uncomplemented F distribution:z = incbi( df1/2, df2/2, p )x = df2 z / (df1 (1-z)).ACCURACY:Tested at random points (a,b,p).a,b Relative error:arithmetic domain # trials peak rmsFor p between .001 and 1:IEEE 1,100 100000 8.3e-15 4.7e-16IEEE 1,10000 100000 2.1e-11 1.4e-13For p between 10^-6 and 10^-3:IEEE 1,100 50000 1.3e-12 8.4e-15IEEE 1,10000 50000 3.0e-12 4.8e-14See also fdtrc.c.ERROR MESSAGES:message condition value returnedfdtri domain p <= 0 or p > 1 0.0v < 1
- ceil: ceil
-
ceil() returns the smallest integer greater than or equalto x. It truncates toward plus infinity.SYNOPSIS:# double x, y, ceil();$y = ceil( $x );
- floor: floor
-
floor() returns the largest integer less than or equal to x.It truncates toward minus infinity.SYNOPSIS:# double x, y, floor();$y = floor( $x );
- frexp: frexp
-
frexp() extracts the exponent from x. It returns an integerpower of two to expnt and the significand between 0.5 and 1to y. Thus x = y * 2**expn.SYNOPSIS:# double x, y, frexp();# int expnt;($y, $expnt) = frexp( $x );
- ldexp: multiplies x by 2**n.
-
SYNOPSIS:# double x, y, ldexp();# int n;$y = ldexp( $x, $n );
- fresnl: Fresnel integral
-
SYNOPSIS:# double x, S, C;# void fresnl();($flag, $S, $C) = fresnl( $x );DESCRIPTION:Evaluates the Fresnel integralsx-| |C(x) = | cos(pi/2 t**2) dt,| |-0x-| |S(x) = | sin(pi/2 t**2) dt.| |-0The integrals are evaluated by a power series for x < 1.For x >= 1 auxiliary functions f(x) and g(x) are employedsuch thatC(x) = 0.5 + f(x) sin( pi/2 x**2 ) - g(x) cos( pi/2 x**2 )S(x) = 0.5 - f(x) cos( pi/2 x**2 ) - g(x) sin( pi/2 x**2 )ACCURACY:Relative error.Arithmetic function domain # trials peak rmsIEEE S(x) 0, 10 10000 2.0e-15 3.2e-16IEEE C(x) 0, 10 10000 1.8e-15 3.3e-16DEC S(x) 0, 10 6000 2.2e-16 3.9e-17DEC C(x) 0, 10 5000 2.3e-16 3.9e-17
- gamma: Gamma function
-
SYNOPSIS:# double x, y, gamma();# extern int sgngam;$y = gamma( $x );DESCRIPTION:Returns gamma function of the argument. The result iscorrectly signed, and the sign (+1 or -1) is alsoreturned in a global (extern) variable named sgngam.This variable is also filled in by the logarithmic gammafunction lgam().Arguments |x| <= 34 are reduced by recurrence and the functionapproximated by a rational function of degree 6/7 in theinterval (2,3). Large arguments are handled by Stirling'sformula. Large negative arguments are made positive usinga reflection formula.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -34, 34 10000 1.3e-16 2.5e-17IEEE -170,-33 20000 2.3e-15 3.3e-16IEEE -33, 33 20000 9.4e-16 2.2e-16IEEE 33, 171.6 20000 2.3e-15 3.2e-16Error for arguments outside the test range will be largerowing to error amplification by the exponential function.
- lgam: Natural logarithm of gamma function
-
SYNOPSIS:# double x, y, lgam();# extern int sgngam;$y = lgam( $x );DESCRIPTION:Returns the base e (2.718...) logarithm of the absolutevalue of the gamma function of the argument.The sign (+1 or -1) of the gamma function is returned in aglobal (extern) variable named sgngam.For arguments greater than 13, the logarithm of the gammafunction is approximated by the logarithmic version ofStirling's formula using a polynomial approximation ofdegree 4. Arguments between -33 and +33 are reduced byrecurrence to the interval [2,3] of a rational approximation.The cosecant reflection formula is employed for argumentsless than -33.Arguments greater than MAXLGM return MAXNUM and an errormessage. MAXLGM = 2.035093e36 for DECarithmetic or 2.556348e305 for IEEE arithmetic.ACCURACY:arithmetic domain # trials peak rmsDEC 0, 3 7000 5.2e-17 1.3e-17DEC 2.718, 2.035e36 5000 3.9e-17 9.9e-18IEEE 0, 3 28000 5.4e-16 1.1e-16IEEE 2.718, 2.556e305 40000 3.5e-16 8.3e-17The error criterion was relative when the function magnitudewas greater than one but absolute when it was less than one.The following test used the relative error criterion, thoughat certain points the relative error could be much higher thanindicated.IEEE -200, -4 10000 4.8e-16 1.3e-16
- gdtr: Gamma distribution function
-
SYNOPSIS:# double a, b, x, y, gdtr();$y = gdtr( $a, $b, $x );DESCRIPTION:Returns the integral from zero to x of the gamma probabilitydensity function:xb -a | | b-1 -aty = ----- | t e dt- | || (b) -0The incomplete gamma integral is used, according to therelationy = igam( b, ax ).ACCURACY:See igam().ERROR MESSAGES:message condition value returnedgdtr domain x < 0 0.0
- gdtrc: Complemented gamma distribution function
-
SYNOPSIS:# double a, b, x, y, gdtrc();$y = gdtrc( $a, $b, $x );DESCRIPTION:Returns the integral from x to infinity of the gammaprobability density function:inf.b -a | | b-1 -aty = ----- | t e dt- | || (b) -xThe incomplete gamma integral is used, according to therelationy = igamc( b, ax ).ACCURACY:See igamc().ERROR MESSAGES:message condition value returnedgdtrc domain x < 0 0.0
- hyp2f0: Gauss hypergeometric function 2F0
-
SYNOPSIS:# double a, b, x, value, *err;# int type; /* determines what converging factor to use */($value, $err) = hyp2f0( $a, $b, $x, $type )
- hyp2f1: Gauss hypergeometric function 2F1
-
SYNOPSIS:# double a, b, c, x, y, hyp2f1();$y = hyp2f1( $a, $b, $c, $x );DESCRIPTION:hyp2f1( a, b, c, x ) = F ( a, b; c; x )2 1inf.- a(a+1)...(a+k) b(b+1)...(b+k) k+1= 1 + > ----------------------------- x .- c(c+1)...(c+k) (k+1)!k = 0Cases addressed areTests and escapes for negative integer a, b, or cLinear transformation if c - a or c - b negative integerSpecial case c = a or c = bLinear transformation for x near +1Transformation for x < -0.5Psi function expansion if x > 0.5 and c - a - b integerConditionally, a recurrence on c to make c-a-b > 0|x| > 1 is rejected.The parameters a, b, c are considered to be integervalued if they are within 1.0e-14 of the nearest integer(1.0e-13 for IEEE arithmetic).ACCURACY:Relative error (-1 < x < 1):arithmetic domain # trials peak rmsIEEE -1,7 230000 1.2e-11 5.2e-14Several special cases also tested with a, b, c inthe range -7 to 7.ERROR MESSAGES:A "partial loss of precision" message is printed ifthe internally estimated relative error exceeds 1^-12.A "singularity" message is printed on overflow orin cases not addressed (such as x < -1).
- hyperg: Confluent hypergeometric function
-
SYNOPSIS:# double a, b, x, y, hyperg();$y = hyperg( $a, $b, $x );DESCRIPTION:Computes the confluent hypergeometric function1 2a x a(a+1) xF ( a,b;x ) = 1 + ---- + --------- + ...1 1 b 1! b(b+1) 2!Many higher transcendental functions are special cases ofthis power series.As is evident from the formula, b must not be a negativeinteger or zero unless a is an integer with 0 >= a > b.The routine attempts both a direct summation of the seriesand an asymptotic expansion. In each case error due toroundoff, cancellation, and nonconvergence is estimated.The result with smaller estimated error is returned.ACCURACY:Tested at random points (a, b, x), all three variablesranging from 0 to 30.Relative error:arithmetic domain # trials peak rmsDEC 0,30 2000 1.2e-15 1.3e-16IEEE 0,30 30000 1.8e-14 1.1e-15Larger errors can be observed when b is near a negativeinteger or zero. Certain combinations of arguments yieldserious cancellation error in the power series summationand also are not in the region of near convergence of theasymptotic series. An error message is printed if theself-estimated relative error is greater than 1.0e-12.
- i0: Modified Bessel function of order zero
-
SYNOPSIS:# double x, y, i0();$y = i0( $x );DESCRIPTION:Returns modified Bessel function of order zero of theargument.The function is defined as i0(x) = j0( ix ).The range is partitioned into the two intervals [0,8] and(8, infinity). Chebyshev polynomial expansions are employedin each interval.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC 0,30 6000 8.2e-17 1.9e-17IEEE 0,30 30000 5.8e-16 1.4e-16
- i0e: Modified Bessel function of order zero, exponentially scaled
-
SYNOPSIS:# double x, y, i0e();$y = i0e( $x );DESCRIPTION:Returns exponentially scaled modified Bessel functionof order zero of the argument.The function is defined as i0e(x) = exp(-|x|) j0( ix ).ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE 0,30 30000 5.4e-16 1.2e-16See i0().
- i1: Modified Bessel function of order one
-
SYNOPSIS:# double x, y, i1();$y = i1( $x );DESCRIPTION:Returns modified Bessel function of order one of theargument.The function is defined as i1(x) = -i j1( ix ).The range is partitioned into the two intervals [0,8] and(8, infinity). Chebyshev polynomial expansions are employedin each interval.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC 0, 30 3400 1.2e-16 2.3e-17IEEE 0, 30 30000 1.9e-15 2.1e-16
- i1e: Modified Bessel function of order one, exponentially scaled
-
SYNOPSIS:# double x, y, i1e();$y = i1e( $x );DESCRIPTION:Returns exponentially scaled modified Bessel functionof order one of the argument.The function is defined as i1(x) = -i exp(-|x|) j1( ix ).ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE 0, 30 30000 2.0e-15 2.0e-16See i1().
- igam: Incomplete gamma integral
-
SYNOPSIS:# double a, x, y, igam();$y = igam( $a, $x );DESCRIPTION:The function is defined byx-1 | | -t a-1igam(a,x) = ----- | e t dt.- | || (a) -0In this implementation both arguments must be positive.The integral is evaluated by either a power series orcontinued fraction expansion, depending on the relativevalues of a and x.ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE 0,30 200000 3.6e-14 2.9e-15IEEE 0,100 300000 9.9e-14 1.5e-14
- igamc: Complemented incomplete gamma integral
-
SYNOPSIS:# double a, x, y, igamc();$y = igamc( $a, $x );DESCRIPTION:The function is defined byigamc(a,x) = 1 - igam(a,x)inf.-1 | | -t a-1= ----- | e t dt.- | || (a) -xIn this implementation both arguments must be positive.The integral is evaluated by either a power series orcontinued fraction expansion, depending on the relativevalues of a and x.ACCURACY:Tested at random a, x.a x Relative error:arithmetic domain domain # trials peak rmsIEEE 0.5,100 0,100 200000 1.9e-14 1.7e-15IEEE 0.01,0.5 0,100 200000 1.4e-13 1.6e-15
- igami: Inverse of complemented imcomplete gamma integral
-
SYNOPSIS:# double a, x, p, igami();$x = igami( $a, $p );DESCRIPTION:Given p, the function finds x such thatigamc( a, x ) = p.It is valid in the right-hand tail of the distribution, p < 0.5.Starting with the approximate value3x = a twheret = 1 - d - ndtri(p) sqrt(d)andd = 1/9a,the routine performs up to 10 Newton iterations to find theroot of igamc(a,x) - p = 0.ACCURACY:Tested at random a, p in the intervals indicated.a p Relative error:arithmetic domain domain # trials peak rmsIEEE 0.5,100 0,0.5 100000 1.0e-14 1.7e-15IEEE 0.01,0.5 0,0.5 100000 9.0e-14 3.4e-15IEEE 0.5,10000 0,0.5 20000 2.3e-13 3.8e-14
- incbet: Incomplete beta integral
-
SYNOPSIS:# double a, b, x, y, incbet();$y = incbet( $a, $b, $x );DESCRIPTION:Returns incomplete beta integral of the arguments, evaluatedfrom zero to x. The function is defined asx- -| (a+b) | | a-1 b-1----------- | t (1-t) dt.- - | || (a) | (b) -0The domain of definition is 0 <= x <= 1. In thisimplementation a and b are restricted to positive values.The integral from x to 1 may be obtained by the symmetryrelation1 - incbet( a, b, x ) = incbet( b, a, 1-x ).The integral is evaluated by a continued fraction expansionor, when b*x is small, by a power series.ACCURACY:Tested at uniformly distributed random points (a,b,x) with a and bin "domain" and x between 0 and 1.Relative errorarithmetic domain # trials peak rmsIEEE 0,5 10000 6.9e-15 4.5e-16IEEE 0,85 250000 2.2e-13 1.7e-14IEEE 0,1000 30000 5.3e-12 6.3e-13IEEE 0,10000 250000 9.3e-11 7.1e-12IEEE 0,100000 10000 8.7e-10 4.8e-11Outputs smaller than the IEEE gradual underflow thresholdwere excluded from these statistics.ERROR MESSAGES:message condition value returnedincbet domain x<0, x>1 0.0incbet underflow 0.0
- incbi: Inverse of imcomplete beta integral
-
SYNOPSIS:# double a, b, x, y, incbi();$x = incbi( $a, $b, $y );DESCRIPTION:Given y, the function finds x such thatincbet( a, b, x ) = y .The routine performs interval halving or Newton iterations to find theroot of incbet(a,b,x) - y = 0.ACCURACY:Relative error:x a,barithmetic domain domain # trials peak rmsIEEE 0,1 .5,10000 50000 5.8e-12 1.3e-13IEEE 0,1 .25,100 100000 1.8e-13 3.9e-15IEEE 0,1 0,5 50000 1.1e-12 5.5e-15VAX 0,1 .5,100 25000 3.5e-14 1.1e-15With a and b constrained to half-integer or integer values:IEEE 0,1 .5,10000 50000 5.8e-12 1.1e-13IEEE 0,1 .5,100 100000 1.7e-14 7.9e-16With a = .5, b constrained to half-integer or integer values:IEEE 0,1 .5,10000 10000 8.3e-11 1.0e-11
- iv: Modified Bessel function of noninteger order
-
SYNOPSIS:# double v, x, y, iv();$y = iv( $v, $x );DESCRIPTION:Returns modified Bessel function of order v of theargument. If x is negative, v must be integer valued.The function is defined as Iv(x) = Jv( ix ). It ishere computed in terms of the confluent hypergeometricfunction, according to the formulav -xIv(x) = (x/2) e hyperg( v+0.5, 2v+1, 2x ) / gamma(v+1)If v is a negative integer, then v is replaced by -v.ACCURACY:Tested at random points (v, x), with v between 0 and30, x between 0 and 28.Relative error:arithmetic domain # trials peak rmsDEC 0,30 2000 3.1e-15 5.4e-16IEEE 0,30 10000 1.7e-14 2.7e-15Accuracy is diminished if v is near a negative integer.See also hyperg.c.
- j0: Bessel function of order zero
-
SYNOPSIS:# double x, y, j0();$y = j0( $x );DESCRIPTION:Returns Bessel function of order zero of the argument.The domain is divided into the intervals [0, 5] and(5, infinity). In the first interval the following rationalapproximation is used:2 2(w - r ) (w - r ) P (w) / Q (w)1 2 3 82where w = x and the two r's are zeros of the function.In the second interval, the Hankel asymptotic expansionis employed with two rational functions of degree 6/6and 7/7.ACCURACY:Absolute error:arithmetic domain # trials peak rmsDEC 0, 30 10000 4.4e-17 6.3e-18IEEE 0, 30 60000 4.2e-16 1.1e-16
- y0: Bessel function of the second kind, order zero
-
SYNOPSIS:# double x, y, y0();$y = y0( $x );DESCRIPTION:Returns Bessel function of the second kind, of orderzero, of the argument.The domain is divided into the intervals [0, 5] and(5, infinity). In the first interval a rational approximationR(x) is employed to computey0(x) = R(x) + 2 * log(x) * j0(x) / PI.Thus a call to j0() is required.In the second interval, the Hankel asymptotic expansionis employed with two rational functions of degree 6/6and 7/7.ACCURACY:Absolute error, when y0(x) < 1; else relative error:arithmetic domain # trials peak rmsDEC 0, 30 9400 7.0e-17 7.9e-18IEEE 0, 30 30000 1.3e-15 1.6e-16
- j1: Bessel function of order one
-
SYNOPSIS:# double x, y, j1();$y = j1( $x );DESCRIPTION:Returns Bessel function of order one of the argument.The domain is divided into the intervals [0, 8] and(8, infinity). In the first interval a 24 term Chebyshevexpansion is used. In the second, the asymptotictrigonometric representation is employed using tworational functions of degree 5/5.ACCURACY:Absolute error:arithmetic domain # trials peak rmsDEC 0, 30 10000 4.0e-17 1.1e-17IEEE 0, 30 30000 2.6e-16 1.1e-16
- y1: Bessel function of second kind of order one
-
SYNOPSIS:# double x, y, y1();$y = y1( $x );DESCRIPTION:Returns Bessel function of the second kind of order oneof the argument.The domain is divided into the intervals [0, 8] and(8, infinity). In the first interval a 25 term Chebyshevexpansion is used, and a call to j1() is required.In the second, the asymptotic trigonometric representationis employed using two rational functions of degree 5/5.ACCURACY:Absolute error:arithmetic domain # trials peak rmsDEC 0, 30 10000 8.6e-17 1.3e-17IEEE 0, 30 30000 1.0e-15 1.3e-16(error criterion relative when |y1| > 1).
- jn: Bessel function of integer order
-
SYNOPSIS:# int n;# double x, y, jn();$y = jn( $n, $x );DESCRIPTION:Returns Bessel function of order n, where n is a(possibly negative) integer.The ratio of jn(x) to j0(x) is computed by backwardrecurrence. First the ratio jn/jn-1 is found by acontinued fraction expansion. Then the recurrencerelating successive orders is applied until j0 or j1 isreached.If n = 0 or 1 the routine for j0 or j1 is calleddirectly.ACCURACY:Absolute error:arithmetic range # trials peak rmsDEC 0, 30 5500 6.9e-17 9.3e-18IEEE 0, 30 5000 4.4e-16 7.9e-17Not suitable for large n or x. Use jv() instead.
- jv: Bessel function of noninteger order
-
SYNOPSIS:# double v, x, y, jv();$y = jv( $v, $x );DESCRIPTION:Returns Bessel function of order v of the argument,where v is real. Negative x is allowed if v is an integer.Several expansions are included: the ascending powerseries, the Hankel expansion, and two transitionalexpansions for large v. If v is not too large, itis reduced by recurrence to a region of best accuracy.The transitional expansions give 12D accuracy for v > 500.ACCURACY:Results for integer v are indicated by *, where x and vboth vary from -125 to +125. Otherwise,x ranges from 0 to 125, v ranges as indicated by "domain."Error criterion is absolute, except relative when |jv()| > 1.arithmetic v domain x domain # trials peak rmsIEEE 0,125 0,125 100000 4.6e-15 2.2e-16IEEE -125,0 0,125 40000 5.4e-11 3.7e-13IEEE 0,500 0,500 20000 4.4e-15 4.0e-16Integer v:IEEE -125,125 -125,125 50000 3.5e-15* 1.9e-16*
- k0: Modified Bessel function, third kind, order zero
-
SYNOPSIS:# double x, y, k0();$y = k0( $x );DESCRIPTION:Returns modified Bessel function of the third kindof order zero of the argument.The range is partitioned into the two intervals [0,8] and(8, infinity). Chebyshev polynomial expansions are employedin each interval.ACCURACY:Tested at 2000 random points between 0 and 8. Peak absoluteerror (relative when K0 > 1) was 1.46e-14; rms, 4.26e-15.Relative error:arithmetic domain # trials peak rmsDEC 0, 30 3100 1.3e-16 2.1e-17IEEE 0, 30 30000 1.2e-15 1.6e-16ERROR MESSAGES:message condition value returnedK0 domain x <= 0 MAXNUM
- k0e: Modified Bessel function, third kind, order zero, exponentially scaled
-
SYNOPSIS:# double x, y, k0e();$y = k0e( $x );DESCRIPTION:Returns exponentially scaled modified Bessel functionof the third kind of order zero of the argument.k0e(x) = exp(x) * k0(x).ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE 0, 30 30000 1.4e-15 1.4e-16See k0().
- k1: Modified Bessel function, third kind, order one
-
SYNOPSIS:# double x, y, k1();$y = k1( $x );DESCRIPTION:Computes the modified Bessel function of the third kindof order one of the argument.The range is partitioned into the two intervals [0,2] and(2, infinity). Chebyshev polynomial expansions are employedin each interval.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC 0, 30 3300 8.9e-17 2.2e-17IEEE 0, 30 30000 1.2e-15 1.6e-16ERROR MESSAGES:message condition value returnedk1 domain x <= 0 MAXNUM
- k1e: Modified Bessel function, third kind, order one, exponentially scaled
-
SYNOPSIS:# double x, y, k1e();$y = k1e( $x );DESCRIPTION:Returns exponentially scaled modified Bessel functionof the third kind of order one of the argument:k1e(x) = exp(x) * k1(x).ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE 0, 30 30000 7.8e-16 1.2e-16See k1().
- kn: Modified Bessel function, third kind, integer order
-
SYNOPSIS:# double x, y, kn();# int n;$y = kn( $n, $x );DESCRIPTION:Returns modified Bessel function of the third kindof order n of the argument.The range is partitioned into the two intervals [0,9.55] and(9.55, infinity). An ascending power series is used in thelow range, and an asymptotic expansion in the high range.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC 0,30 3000 1.3e-9 5.8e-11IEEE 0,30 90000 1.8e-8 3.0e-10Error is high only near the crossover point x = 9.55between the two expansions used.
- log: Natural logarithm
-
SYNOPSIS:# double x, y, log();$y = log( $x );DESCRIPTION:Returns the base e (2.718...) logarithm of x.The argument is separated into its exponent and fractionalparts. If the exponent is between -1 and +1, the logarithmof the fraction is approximated bylog(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 rmsIEEE 0.5, 2.0 150000 1.44e-16 5.06e-17IEEE +-MAXNUM 30000 1.20e-16 4.78e-17DEC 0, 10 170000 1.8e-17 6.3e-18In the tests over the interval [+-MAXNUM], the logarithmsof the random arguments were uniformly distributed over[0, MAXLOG].ERROR MESSAGES:log singularity: x = 0; returns -INFINITYlog domain: x < 0; returns NAN
- log10: Common logarithm
-
SYNOPSIS:# double x, y, log10();$y = log10( $x );DESCRIPTION:Returns logarithm to the base 10 of x.The argument is separated into its exponent and fractionalparts. The logarithm of the fraction is approximated bylog(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x).ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE 0.5, 2.0 30000 1.5e-16 5.0e-17IEEE 0, MAXNUM 30000 1.4e-16 4.8e-17DEC 1, MAXNUM 50000 2.5e-17 6.0e-18In the tests over the interval [1, MAXNUM], the logarithmsof the random arguments were uniformly distributed over[0, MAXLOG].ERROR MESSAGES:log10 singularity: x = 0; returns -INFINITYlog10 domain: x < 0; returns NAN
- log2: Base 2 logarithm
-
SYNOPSIS:# double x, y, log2();$y = log2( $x );DESCRIPTION:Returns the base 2 logarithm of x.The argument is separated into its exponent and fractionalparts. If the exponent is between -1 and +1, the base elogarithm of the fraction is approximated bylog(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 rmsIEEE 0.5, 2.0 30000 2.0e-16 5.5e-17IEEE exp(+-700) 40000 1.3e-16 4.6e-17In the tests over the interval [exp(+-700)], the logarithmsof the random arguments were uniformly distributed.ERROR MESSAGES:log2 singularity: x = 0; returns -INFINITYlog2 domain: x < 0; returns NAN
- lrand: Pseudorandom number generator
-
SYNOPSIS:long y, lrand();$y = lrand( );DESCRIPTION:Yields a long integer random number.The three-generator congruential algorithm by BrianWichmann and David Hill (BYTE magazine, March, 1987,pp 127-8) is used. The period, given by them, is6953607871644.
- lsqrt: Integer square root
-
SYNOPSIS:long x, y;long lsqrt();$y = lsqrt( $x );DESCRIPTION:Returns a long integer square root of the long integerargument. The computation is by binary long division.The largest possible result is lsqrt(2,147,483,647)= 46341.If x < 0, the square root of |x| is returned, and anerror message is printed.ACCURACY:An extra, roundoff, bit is computed; hence the resultis the nearest integer to the actual square root.NOTE: only DEC arithmetic is currently supported.
- mtherr: Library common error handling routine
-
SYNOPSIS:char *fctnam;# int code;# int mtherr();mtherr( $fctnam, $code );DESCRIPTION:This routine may be called to report one of the followingerror conditions (in the include file mconf.h).Mnemonic Value SignificanceDOMAIN 1 argument domain errorSING 2 function singularityOVERFLOW 3 overflow range errorUNDERFLOW 4 underflow range errorTLOSS 5 total loss of precisionPLOSS 6 partial loss of precisionEDOM 33 Unix domain error codeERANGE 34 Unix range error codeThe default version of the file prints the function name,passed to it by the pointer fctnam, followed by theerror condition. The display is directed to the standardoutput device. The routine then returns to the callingprogram. Users may wish to modify the program to abort bycalling exit() under severe error conditions such as domainerrors.Since all error conditions pass control to this function,the display may be easily changed, eliminated, or directedto an error logging device.SEE ALSO: mconf.h
- nbdtr: Negative binomial distribution
-
SYNOPSIS:# int k, n;# double p, y, nbdtr();$y = nbdtr( $k, $n, $p );DESCRIPTION:Returns the sum of the terms 0 through k of the negativebinomial distribution:k-- ( n+j-1 ) n j> ( ) p (1-p)-- ( j )j=0In a sequence of Bernoulli trials, this is the probabilitythat k or fewer failures precede the nth success.The terms are not computed individually; instead the incompletebeta integral is employed, according to the formulay = nbdtr( k, n, p ) = incbet( n, k+1, p ).The arguments must be positive, with p ranging from 0 to 1.ACCURACY:Tested at random points (a,b,p), with p between 0 and 1.a,b Relative error:arithmetic domain # trials peak rmsIEEE 0,100 100000 1.7e-13 8.8e-15See also incbet.c.
- nbdtrc: Complemented negative binomial distribution
-
SYNOPSIS:# int k, n;# double p, y, nbdtrc();$y = nbdtrc( $k, $n, $p );DESCRIPTION:Returns the sum of the terms k+1 to infinity of the negativebinomial distribution:inf-- ( n+j-1 ) n j> ( ) p (1-p)-- ( j )j=k+1The terms are not computed individually; instead the incompletebeta integral is employed, according to the formulay = nbdtrc( k, n, p ) = incbet( k+1, n, 1-p ).The arguments must be positive, with p ranging from 0 to 1.ACCURACY:Tested at random points (a,b,p), with p between 0 and 1.a,b Relative error:arithmetic domain # trials peak rmsIEEE 0,100 100000 1.7e-13 8.8e-15See also incbet.c.
- nbdtrc: Complemented negative binomial distribution
-
SYNOPSIS:# int k, n;# double p, y, nbdtrc();$y = nbdtrc( $k, $n, $p );DESCRIPTION:Returns the sum of the terms k+1 to infinity of the negativebinomial distribution:inf-- ( n+j-1 ) n j> ( ) p (1-p)-- ( j )j=k+1The terms are not computed individually; instead the incompletebeta integral is employed, according to the formulay = nbdtrc( k, n, p ) = incbet( k+1, n, 1-p ).The arguments must be positive, with p ranging from 0 to 1.ACCURACY:See incbet.c.
- nbdtri: Functional inverse of negative binomial distribution
-
SYNOPSIS:# int k, n;# double p, y, nbdtri();$p = nbdtri( $k, $n, $y );DESCRIPTION:Finds the argument p such that nbdtr(k,n,p) is equal to y.ACCURACY:Tested at random points (a,b,y), with y between 0 and 1.a,b Relative error:arithmetic domain # trials peak rmsIEEE 0,100 100000 1.5e-14 8.5e-16See also incbi.c.
- ndtr: Normal distribution function
-
SYNOPSIS:# double x, y, ndtr();$y = ndtr( $x );DESCRIPTION:Returns the area under the Gaussian probability densityfunction, integrated from minus infinity to x:x-1 | | 2ndtr(x) = --------- | exp( - t /2 ) dtsqrt(2pi) | |--inf.= ( 1 + erf(z) ) / 2where z = x/sqrt(2). Computation is via the functionserf and erfc.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -13,0 8000 2.1e-15 4.8e-16IEEE -13,0 30000 3.4e-14 6.7e-15ERROR MESSAGES:message condition value returnederfc underflow x > 37.519379347 0.0
- erf: Error function
-
SYNOPSIS:# double x, y, erf();$y = erf( $x );DESCRIPTION:The integral isx-2 | | 2erf(x) = -------- | exp( - t ) dt.sqrt(pi) | |-0The magnitude of x is limited to 9.231948545 for DECarithmetic; 1 or -1 is returned outside this range.For 0 <= |x| < 1, erf(x) = x * P4(x**2)/Q5(x**2); otherwiseerf(x) = 1 - erfc(x).ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC 0,1 14000 4.7e-17 1.5e-17IEEE 0,1 30000 3.7e-16 1.0e-16
- erfc: Complementary error function
-
SYNOPSIS:# double x, y, erfc();$y = erfc( $x );DESCRIPTION:1 - erf(x) =inf.-2 | | 2erfc(x) = -------- | exp( - t ) dtsqrt(pi) | |-xFor small x, erfc(x) = 1 - erf(x); otherwise rationalapproximations are computed.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC 0, 9.2319 12000 5.1e-16 1.2e-16IEEE 0,26.6417 30000 5.7e-14 1.5e-14ERROR MESSAGES:message condition value returnederfc underflow x > 9.231948545 (DEC) 0.0
- ndtri: Inverse of Normal distribution function
-
SYNOPSIS:# double x, y, ndtri();$x = ndtri( $y );DESCRIPTION:Returns the argument, x, for which the area under theGaussian probability density function (integrated fromminus infinity to x) is equal to y.For small arguments 0 < y < exp(-2), the program computesz = sqrt( -2.0 * log(y) ); then the approximation isx = z - log(z)/z - (1/z) P(1/z) / Q(1/z).There are two rational functions P/Q, one for 0 < y < exp(-32)and the other for y up to exp(-2). For larger arguments,w = y - 0.5, and x/sqrt(2pi) = w + w**3 R(w**2)/S(w**2)).ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC 0.125, 1 5500 9.5e-17 2.1e-17DEC 6e-39, 0.135 3500 5.7e-17 1.3e-17IEEE 0.125, 1 20000 7.2e-16 1.3e-16IEEE 3e-308, 0.135 50000 4.6e-16 9.8e-17ERROR MESSAGES:message condition value returnedndtri domain x <= 0 -MAXNUMndtri domain x >= 1 MAXNUM
- pdtr: Poisson distribution
-
SYNOPSIS:# int k;# double m, y, pdtr();$y = pdtr( $k, $m );DESCRIPTION:Returns the sum of the first k terms of the Poissondistribution:k j-- -m m> e ---- j!j=0The terms are not summed directly; instead the incompletegamma integral is employed, according to the relationy = pdtr( k, m ) = igamc( k+1, m ).The arguments must both be positive.ACCURACY:See igamc().
- pdtrc: Complemented poisson distribution
-
SYNOPSIS:# int k;# double m, y, pdtrc();$y = pdtrc( $k, $m );DESCRIPTION:Returns the sum of the terms k+1 to infinity of the Poissondistribution:inf. j-- -m m> e ---- j!j=k+1The terms are not summed directly; instead the incompletegamma integral is employed, according to the formulay = pdtrc( k, m ) = igam( k+1, m ).The arguments must both be positive.ACCURACY:See igam.c.
- pdtri: Inverse Poisson distribution
-
SYNOPSIS:# int k;# double m, y, pdtr();$m = pdtri( $k, $y );DESCRIPTION:Finds the Poisson variable x such that the integralfrom 0 to x of the Poisson density is equal to thegiven probability y.This is accomplished using the inverse gamma integralfunction and the relationm = igami( k+1, y ).ACCURACY:See igami.c.ERROR MESSAGES:message condition value returnedpdtri domain y < 0 or y >= 1 0.0k < 0
- pow: Power function
-
SYNOPSIS:# double x, y, z, pow();$z = pow( $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 tableof 2**-i/16 and pseudo extended precision arithmetic toobtain an extra three bits of accuracy in both the logarithmand the exponential.ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE -26,26 30000 4.2e-16 7.7e-17DEC -26,26 60000 4.8e-17 9.1e-181/26 < x < 26, with log(x) uniformly distributed.-26 < y < 26, y uniformly distributed.IEEE 0,8700 30000 1.5e-14 2.1e-150.99 < x < 1.01, 0 < y < 8700, uniformly distributed.ERROR MESSAGES:message condition value returnedpow overflow x**y > MAXNUM INFINITYpow underflow x**y < 1/MAXNUM 0.0pow domain x<0 and y noninteger 0.0
- powi: Real raised to integer power
-
SYNOPSIS:# double x, y, powi();# int n;$y = powi( $x, $n );DESCRIPTION:Returns argument x raised to the nth power.The routine efficiently decomposes n as a sum of powers oftwo. The desired power is a product of two-to-the-kthpowers of x. Thus to compute the 32767 power of x requires28 multiplications instead of 32767 multiplications.ACCURACY:Relative error:arithmetic x domain n domain # trials peak rmsDEC .04,26 -26,26 100000 2.7e-16 4.3e-17IEEE .04,26 -26,26 50000 2.0e-15 3.8e-16IEEE 1,2 -1022,1023 50000 8.6e-14 1.6e-14Returns MAXNUM on overflow, zero on underflow.
- psi: Psi (digamma) function
-
SYNOPSIS:# double x, y, psi();$y = psi( $x );DESCRIPTION:d -psi(x) = -- ln | (x)dxis the logarithmic derivative of the gamma function.For integer x,n-1-psi(n) = -EUL + > 1/k.-k=1This formula is used for 0 < n <= 10. If x is negative, itis transformed to a positive argument by the reflectionformula psi(1-x) = psi(x) + pi cot(pi x).For general positive x, the argument is made greater than 10using the recurrence psi(x+1) = psi(x) + 1/x.Then the following asymptotic expansion is applied:inf. B- 2kpsi(x) = log(x) - 1/2x - > -------- 2kk=1 2k xwhere the B2k are Bernoulli numbers.ACCURACY:Relative error (except absolute when |psi| < 1):arithmetic domain # trials peak rmsDEC 0,30 2500 1.7e-16 2.0e-17IEEE 0,30 30000 1.3e-15 1.4e-16IEEE -30,0 40000 1.5e-15 2.2e-16ERROR MESSAGES:message condition value returnedpsi singularity x integer <=0 MAXNUM
- rgamma: Reciprocal gamma function
-
SYNOPSIS:# double x, y, rgamma();$y = rgamma( $x );DESCRIPTION:Returns one divided by the gamma function of the argument.The function is approximated by a Chebyshev expansion inthe interval [0,1]. Range reduction is by recurrencefor arguments between -34.034 and +34.84425627277176174.1/MAXNUM is returned for positive arguments outside thisrange. For arguments less than -34.034 the cosecantreflection formula is applied; lograrithms are employedto avoid unnecessary overflow.The reciprocal gamma function has no singularities,but overflow and underflow may occur for large arguments.These conditions return either MAXNUM or 1/MAXNUM withappropriate sign.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -30,+30 4000 1.2e-16 1.8e-17IEEE -30,+30 30000 1.1e-15 2.0e-16For arguments less than -34.034 the peak error is on theorder of 5e-15 (DEC), excepting overflow or underflow.
- round: Round double to nearest or even integer valued double
-
SYNOPSIS:# double x, y, round();$y = round( $x );DESCRIPTION:Returns the nearest integer to x as a double precisionfloating point result. If x ends in 0.5 exactly, thenearest even integer is chosen.ACCURACY:If x is greater than 1/(2*MACHEP), its closest machinerepresentation is already an integer, so rounding doesnot change it.
- shichi: Hyperbolic sine and cosine integrals
-
SYNOPSIS:# double x, Chi, Shi, shichi();($flag, $Shi, $Chi) = shichi( $x );DESCRIPTION:Approximates the integralsx-| | cosh t - 1Chi(x) = eul + ln x + | ----------- dt,| | t-0x-| | sinh tShi(x) = | ------ dt| | t-0where eul = 0.57721566490153286061 is Euler's constant.The integrals are evaluated by power series for x < 8and by Chebyshev expansions for x between 8 and 88.For large x, both functions approach exp(x)/2x.Arguments greater than 88 in magnitude return MAXNUM.ACCURACY:Test interval 0 to 88.Relative error:arithmetic function # trials peak rmsDEC Shi 3000 9.1e-17IEEE Shi 30000 6.9e-16 1.6e-16Absolute error, except relative when |Chi| > 1:DEC Chi 2500 9.3e-17IEEE Chi 30000 8.4e-16 1.4e-16
- sici: Sine and cosine integrals
-
SYNOPSIS:# double x, Ci, Si, sici();($flag, $Si, $Ci) = sici( $x );DESCRIPTION:Evaluates the integralsx-| cos t - 1Ci(x) = eul + ln x + | --------- dt,| t-0x-| sin tSi(x) = | ----- dt| t-0where eul = 0.57721566490153286061 is Euler's constant.The integrals are approximated by rational functions.For x > 8 auxiliary functions f(x) and g(x) are employedsuch thatCi(x) = f(x) sin(x) - g(x) cos(x)Si(x) = pi/2 - f(x) cos(x) - g(x) sin(x)ACCURACY:Test interval = [0,50].Absolute error, except relative when > 1:arithmetic function # trials peak rmsIEEE Si 30000 4.4e-16 7.3e-17IEEE Ci 30000 6.9e-16 5.1e-17DEC Si 5000 4.4e-17 9.0e-18DEC Ci 5300 7.9e-17 5.2e-18
- sin: Circular sine
-
SYNOPSIS:# double x, y, sin();$y = sin( $x );DESCRIPTION:Range reduction is into intervals of pi/4. The reductionerror is nearly eliminated by contriving an extended precisionmodular arithmetic.Two polynomial approximating functions are employed.Between 0 and pi/4 the sine is approximated byx + x**3 P(x**2).Between pi/4 and pi/2 the cosine is represented as1 - x**2 Q(x**2).ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC 0, 10 150000 3.0e-17 7.8e-18IEEE -1.07e9,+1.07e9 130000 2.1e-16 5.4e-17ERROR MESSAGES:message condition value returnedsin total loss x > 1.073741824e9 0.0Partial loss of accuracy begins to occur at x = 2**30= 1.074e9. The loss is not gradual, but jumps suddenly toabout 1 part in 10e7. Results may be meaningless forx > 2**49 = 5.6e14. The routine as implemented flags aTLOSS error for x > 2**30 and returns 0.0.
- cos: Circular cosine
-
SYNOPSIS:# double x, y, cos();$y = cos( $x );DESCRIPTION:Range reduction is into intervals of pi/4. The reductionerror is nearly eliminated by contriving an extended precisionmodular arithmetic.Two polynomial approximating functions are employed.Between 0 and pi/4 the cosine is approximated by1 - x**2 Q(x**2).Between pi/4 and pi/2 the sine is represented asx + x**3 P(x**2).ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE -1.07e9,+1.07e9 130000 2.1e-16 5.4e-17DEC 0,+1.07e9 17000 3.0e-17 7.2e-18
- sindg: Circular sine of angle in degrees
-
SYNOPSIS:# double x, y, sindg();$y = sindg( $x );DESCRIPTION:Range reduction is into intervals of 45 degrees.Two polynomial approximating functions are employed.Between 0 and pi/4 the sine is approximated byx + x**3 P(x**2).Between pi/4 and pi/2 the cosine is represented as1 - x**2 P(x**2).ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC +-1000 3100 3.3e-17 9.0e-18IEEE +-1000 30000 2.3e-16 5.6e-17ERROR MESSAGES:message condition value returnedsindg total loss x > 8.0e14 (DEC) 0.0x > 1.0e14 (IEEE)
- cosdg: Circular cosine of angle in degrees
-
SYNOPSIS:# double x, y, cosdg();$y = cosdg( $x );DESCRIPTION:Range reduction is into intervals of 45 degrees.Two polynomial approximating functions are employed.Between 0 and pi/4 the cosine is approximated by1 - x**2 P(x**2).Between pi/4 and pi/2 the sine is represented asx + x**3 P(x**2).ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC +-1000 3400 3.5e-17 9.1e-18IEEE +-1000 30000 2.1e-16 5.7e-17See also sin().
- sinh: Hyperbolic sine
-
SYNOPSIS:# double x, y, sinh();$y = sinh( $x );DESCRIPTION:Returns hyperbolic sine of argument in the range MINLOG toMAXLOG.The range is partitioned into two segments. If |x| <= 1, arational function of the form x + x**3 P(x)/Q(x) is employed.Otherwise the calculation is sinh(x) = ( exp(x) - exp(-x) )/2.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC +- 88 50000 4.0e-17 7.7e-18IEEE +-MAXLOG 30000 2.6e-16 5.7e-17
- spence: Dilogarithm
-
SYNOPSIS:# double x, y, spence();$y = spence( $x );DESCRIPTION:Computes the integralx-| | log tspence(x) = - | ----- dt| | t - 1-1for x >= 0. A rational approximation gives the integral inthe interval (0.5, 1.5). Transformation formulas for 1/xand 1-x are employed outside the basic expansion range.ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE 0,4 30000 3.9e-15 5.4e-16DEC 0,4 3000 2.5e-16 4.5e-17
- sqrt: Square root
-
SYNOPSIS:# double x, y, sqrt();$y = sqrt( $x );DESCRIPTION:Returns the square root of x.Range reduction involves isolating the power of two of theargument and using a polynomial approximation to obtaina rough value for the square root. Then Heron's iterationis used three times to converge to an accurate value.ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC 0, 10 60000 2.1e-17 7.9e-18IEEE 0,1.7e308 30000 1.7e-16 6.3e-17ERROR MESSAGES:message condition value returnedsqrt domain x < 0 0.0
- stdtr: Student's t distribution
-
SYNOPSIS:# double t, stdtr();short k;$y = stdtr( $k, $t );DESCRIPTION:Computes the integral from minus infinity to t of the Studentt distribution with integer k > 0 degrees of freedom:t-| |- | 2 -(k+1)/2| ( (k+1)/2 ) | ( x )---------------------- | ( 1 + --- ) dx- | ( k )sqrt( k pi ) | ( k/2 ) || |--inf.Relation to incomplete beta integral:1 - stdtr(k,t) = 0.5 * incbet( k/2, 1/2, z )wherez = k/(k + t**2).For t < -2, this is the method of computation. For higher t,a direct method is derived from integration by parts.Since the function is symmetric about t=0, the area under theright tail of the density is found by calling the functionwith -t instead of t.ACCURACY:Tested at random 1 <= k <= 25. The "domain" refers to t.Relative error:arithmetic domain # trials peak rmsIEEE -100,-2 50000 5.9e-15 1.4e-15IEEE -2,100 500000 2.7e-15 4.9e-17
- stdtri: Functional inverse of Student's t distribution
-
SYNOPSIS:# double p, t, stdtri();# int k;$t = stdtri( $k, $p );DESCRIPTION:Given probability p, finds the argument t such that stdtr(k,t)is equal to p.ACCURACY:Tested at random 1 <= k <= 100. The "domain" refers to p:Relative error:arithmetic domain # trials peak rmsIEEE .001,.999 25000 5.7e-15 8.0e-16IEEE 10^-6,.001 25000 2.0e-12 2.9e-14
- struve: Struve function
-
SYNOPSIS:# double v, x, y, struve();$y = struve( $v, $x );DESCRIPTION:Computes the Struve function Hv(x) of order v, argument x.Negative x is rejected unless v is an integer.ACCURACY:Not accurately characterized, but spot checked against tables.
- plancki: Integral of Planck's black body radiation formula
-
SYNOPSIS:# double lambda, T, y, plancki()$y = plancki( $lambda, $T );DESCRIPTION:Evaluates the definite integral, from wavelength 0 to lambda,of Planck's radiation formula-5c1 lambdaE = ------------------c2/(lambda T)e - 1Physical constants c1 = 3.7417749e-16 and c2 = 0.01438769 are built into the function program. They are scaled to provide a resultin watts per square meter. Argument T represents temperature in degreesKelvin; lambda is wavelength in meters.The integral is expressed in closed form, in terms of polylogarithms(see polylog.c).The total area under the curve is(-1/8) (42 zeta(4) - 12 pi^2 zeta(2) + pi^4 ) c1 (T/c2)^4= (pi^4 / 15) c1 (T/c2)^4= 5.6705032e-8 T^4where sigma = 5.6705032e-8 W m^2 K^-4 is the Stefan-Boltzmann constant.ACCURACY:The left tail of the function experiences some relative erroramplification in computing the dominant term exp(-c2/(lambda T)).For the right-hand tail see planckc, below.Relative error.The domain refers to lambda T / c2.arithmetic domain # trials peak rmsIEEE 0.1, 10 50000 7.1e-15 5.4e-16
- polylog: polylogarithm function SYNOPSIS:
-
# double x, y, polylog();# int n;$y = polylog( $n, $x );The polylogarithm of order n is defined by the seriesinf k- xLi (x) = > --- .n - nk=1 kFor x = 1,inf- 1Li (1) = > --- = Riemann zeta function (n) .n - nk=1 kWhen n = 2, the function is the dilogarithm, related to Spence's integral:x 1-x- -| | -ln(1-t) | | ln tLi (x) = | -------- dt = | ------ dt = spence(1-x) .2 | | t | | 1 - t- -0 1ACCURACY:Relative error:arithmetic domain n # trials peak rmsIEEE 0, 1 2 50000 6.2e-16 8.0e-17IEEE 0, 1 3 100000 2.5e-16 6.6e-17IEEE 0, 1 4 30000 1.7e-16 4.9e-17IEEE 0, 1 5 30000 5.1e-16 7.8e-17
- bernum: Bernoulli numbers
-
SYNOPSIS:($num, $den) = bernum( $n);($num_array, $den_array) = bernum();DESCRIPTION:This calculates the Bernoulli numbers, up to 30th order.If called with an integer argument, the numerator and denominatorof that Bernoulli number is returned; if called with no argument,two array references representing the numerator and denominatorsof the first 30 Bernoulli numbers are returned.
- simpson: Simpson's rule to find an integral
-
SYNOPSIS:$result = simpson(\&fun, $a, $b, $abs_err, $rel_err, $nmax);sub fun {my $x = shift;return cos($x)*exp($x);}DESCRIPTION:This evaluates the area under the graph of a function,represented in a subroutine, from $a to $b, using an 8-pointNewton-Cotes formula. The routine divides up the interval intoequal segments, evaluates the integral, then compares thatto the result with double the number of segments. If the tworesults agree, to within an absolute error $abs_err or arelative error $rel_err, the result is returned; otherwise,the number of segments is doubled again, and the resultscompared. This continues until the desired accuracy is attained,or until the maximum number of iterations $nmax is reached.
- vecang: angle between two vectors
-
SYNOPSIS:# double p[3], q[3], vecang();$y = vecang( $p, $q );DESCRIPTION:For two vectors p, q, the angle A between them is given byp.q / (|p| |q|) = cos A .where "." represents inner product, "|x|" the length of vector x.If the angle is small, an expression in sin A is preferred.Set r = q - p. Thenp.q = p.p + p.r ,|p|^2 = p.p ,|q|^2 = p.p + 2 p.r + r.r ,p.p^2 + 2 p.p p.r + p.r^2cos^2 A = ----------------------------p.p (p.p + 2 p.r + r.r)p.p + 2 p.r + p.r^2 / p.p= --------------------------- ,p.p + 2 p.r + r.rsin^2 A = 1 - cos^2 Ar.r - p.r^2 / p.p= --------------------p.p + 2 p.r + r.r= (r.r - p.r^2 / p.p) / q.q .ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE -1, 1 10^6 1.7e-16 4.2e-17
- onef2: Hypergeometric function 1F2
-
SYNOPSIS:# double a, b, c, x, value;# double *err;($value, $err) = onef2( $a, $b, $c, $x)ACCURACY:Not accurately characterized, but spot checked against tables.
- threef0: Hypergeometric function 3F0
-
SYNOPSIS:# double a, b, c, x, value;# double *err;($value, $err) = threef0( $a, $b, $c, $x )ACCURACY:Not accurately characterized, but spot checked against tables.
- yv: Bessel function Yv with noninteger v
-
SYNOPSIS:# double v, x;# double yv( v, x );$y = yv( $v, $x );ACCURACY:Not accurately characterized, but spot checked against tables.
- tan: Circular tangent
-
SYNOPSIS:# double x, y, tan();$y = tan( $x );DESCRIPTION:Returns the circular tangent of the radian argument x.Range reduction is modulo pi/4. A rational functionx + x**3 P(x**2)/Q(x**2)is employed in the basic interval [0, pi/4].ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC +-1.07e9 44000 4.1e-17 1.0e-17IEEE +-1.07e9 30000 2.9e-16 8.1e-17ERROR MESSAGES:message condition value returnedtan total loss x > 1.073741824e9 0.0
- cot: Circular cotangent
-
SYNOPSIS:# double x, y, cot();$y = cot( $x );DESCRIPTION:Returns the circular cotangent of the radian argument x.Range reduction is modulo pi/4. A rational functionx + x**3 P(x**2)/Q(x**2)is employed in the basic interval [0, pi/4].ACCURACY:Relative error:arithmetic domain # trials peak rmsIEEE +-1.07e9 30000 2.9e-16 8.2e-17ERROR MESSAGES:message condition value returnedcot total loss x > 1.073741824e9 0.0cot singularity x = 0 INFINITY
- tandg: Circular tangent of argument in degrees
-
SYNOPSIS:# double x, y, tandg();$y = tandg( $x );DESCRIPTION:Returns the circular tangent of the argument x in degrees.Range reduction is modulo pi/4. A rational functionx + x**3 P(x**2)/Q(x**2)is employed in the basic interval [0, pi/4].ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC 0,10 8000 3.4e-17 1.2e-17IEEE 0,10 30000 3.2e-16 8.4e-17ERROR MESSAGES:message condition value returnedtandg total loss x > 8.0e14 (DEC) 0.0x > 1.0e14 (IEEE)tandg singularity x = 180 k + 90 MAXNUM
- cotdg: Circular cotangent of argument in degrees
-
SYNOPSIS:# double x, y, cotdg();$y = cotdg( $x );DESCRIPTION:Returns the circular cotangent of the argument x in degrees.Range reduction is modulo pi/4. A rational functionx + x**3 P(x**2)/Q(x**2)is employed in the basic interval [0, pi/4].ERROR MESSAGES:message condition value returnedcotdg total loss x > 8.0e14 (DEC) 0.0x > 1.0e14 (IEEE)cotdg singularity x = 180 k MAXNUM
- tanh: Hyperbolic tangent
-
SYNOPSIS:# double x, y, tanh();$y = tanh( $x );DESCRIPTION:Returns hyperbolic tangent of argument in the range MINLOG toMAXLOG.A rational function is used for |x| < 0.625. The formx + x**3 P(x)/Q(x) of Cody _& Waite is employed.Otherwise,tanh(x) = sinh(x)/cosh(x) = 1 - 2/(exp(2x) + 1).ACCURACY:Relative error:arithmetic domain # trials peak rmsDEC -2,2 50000 3.3e-17 6.4e-18IEEE -2,2 30000 2.5e-16 5.8e-17
- unity: Relative error approximations for function arguments near unity.
-
SYNOPSIS:# log1p(x) = log(1+x)
$y = log1p( $x );# expm1(x) = exp(x) - 1
$y = expm1( $x );# cosm1(x) = cos(x) - 1
$y = cosm1( $x );
- yn: Bessel function of second kind of integer order
-
SYNOPSIS:# double x, y, yn();# int n;$y = yn( $n, $x );DESCRIPTION:Returns Bessel function of order n, where n is a(possibly negative) integer.The function is evaluated by forward recurrence onn, starting with values computed by the routinesy0() and y1().If n = 0 or 1 the routine for y0 or y1 is calleddirectly.ACCURACY:Absolute error, except relativewhen y > 1:arithmetic domain # trials peak rmsDEC 0, 30 2200 2.9e-16 5.3e-17IEEE 0, 30 30000 3.4e-15 4.3e-16ERROR MESSAGES:message condition value returnedyn singularity x = 0 MAXNUMyn overflow MAXNUMSpot checked against tables for x, n between 0 and 100.
- zeta: Riemann zeta function of two arguments
-
SYNOPSIS:# double x, q, y, zeta();$y = zeta( $x, $q );DESCRIPTION:inf.- -xzeta(x,q) = > (k+q)-k=0where x > 1 and q is not a negative integer or zero.The Euler-Maclaurin summation formula is used to obtainthe expansionn- -xzeta(x,q) = > (k+q)-k=11-x inf. B x(x+1)...(x+2j)(n+q) 1 - 2j+ --------- - ------- + > --------------------x-1 x - x+2j+12(n+q) j=1 (2j)! (n+q)where the B2j are Bernoulli numbers. Note that (see zetac.c)zeta(x,1) = zetac(x) + 1.ACCURACY:REFERENCE:Gradshteyn, I. S., and I. M. Ryzhik, Tables of Integrals,Series, and Products, p. 1073; Academic Press, 1980.
- zetac: Riemann zeta function
-
SYNOPSIS:# double x, y, zetac();$y = zetac( $x );DESCRIPTION:inf.- -xzetac(x) = > k , x > 1,-k=2is related to the Riemann zeta function byRiemann zeta(x) = zetac(x) + 1.Extension of the function definition for x < 1 is implemented.Zero is returned for x > log2(MAXNUM).An overflow error may occur for large negative x, due to thegamma function in the reflection formula.ACCURACY:Tabulated values have full machine accuracy.Relative error:arithmetic domain # trials peak rmsIEEE 1,50 10000 9.8e-16 1.3e-16DEC 1,50 2000 1.1e-16 1.9e-17
TODO
- •
-
Include more operating systems when generating mconf.h.
MAINTAINER
Shlomi Fish, <http://www.shlomifish.org/>, <https://metacpan.org/author/SHLOMIF> .
BUGS
Please report any on the rt.cpan.org interface: <https://rt.cpan.org/Dist/Display.html?Queue=Math-Cephes>
VERSION CONTROL
This distribution is maintained in this GitHub repository:
<https://github.com/shlomif/Math-Cephes>.
SEE ALSO
For interfaces to programs which can do symbolic manipulation, see PDL, Math::Pari, and Math::ematica. For a command line interface to the routines of Math::Cephes, see the included "pmath" script. For a different interface to the fraction and complex number routines, see Math::Cephes::Fraction and Math::Cephes::Complex. For an interface to some polynomial routines, see Math::Cephes::Polynomial, and for some matrix routines, see Math::Cephes::Matrix.
COPYRIGHT
The C code for the Cephes Math Library is Copyright 1984, 1987, 1989, 2002 by Stephen L. Moshier, and is available at <http://www.netlib.org/cephes/>. Direct inquiries to 30 Frost Street, Cambridge, MA 02140.
The file arrays.c included here to handle passing arrays into and out of C routines comes from the PGPLOT module of Karl Glazebrook <[email protected]>.
The perl interface is copyright 2000, 2002 by Randy Kobes. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Perl interface maintained by Shlomi Fish starting from 2012. All explicit or implicit copyrights on the changes are disclaimed by him.