/* ndtrl.c
*
* Normal distribution function
*
*
*
* SYNOPSIS :
*
* long double x , y , ndtrl ( ) ;
*
* y = ndtrl ( x ) ;
*
*
*
* DESCRIPTION :
*
* Returns the area under the Gaussian probability density
* function , integrated from minus infinity to x :
*
* x
* -
* 1 | | 2
* ndtr ( x ) = - - - - - - - - - | exp ( - t / 2 ) dt
* sqrt ( 2 pi ) | |
* -
* - inf .
*
* = ( 1 + erf ( z ) ) / 2
* = erfc ( z ) / 2
*
* where z = x / sqrt ( 2 ) . Computation is via the functions
* erf and erfc with care to avoid error amplification in computing exp ( - x ^ 2 ) .
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* IEEE - 13 , 0 30000 7 . 7 e - 19 1 . 0 e - 19
* IEEE - 106 . 5 , - 2 30000 4 . 2 e - 19 7 . 2 e - 20
* IEEE 0 , 3 30000 1 . 0 e - 19 2 . 4 e - 20
*
*
* ERROR MESSAGES :
*
* message condition value returned
* erfcl underflow x ^ 2 / 2 > MAXLOGL 0 . 0
*
*/
/* erfl.c
*
* Error function
*
*
*
* SYNOPSIS :
*
* long double x , y , erfl ( ) ;
*
* y = erfl ( x ) ;
*
*
*
* DESCRIPTION :
*
* The integral is
*
* x
* -
* 2 | | 2
* erf ( x ) = - - - - - - - - | exp ( - t ) dt .
* sqrt ( pi ) | |
* -
* 0
*
* The magnitude of x is limited to about 106 . 56 for IEEE
* arithmetic ; 1 or - 1 is returned outside this range .
*
* For 0 < = | x | < 1 , erf ( x ) = x * P6 ( x ^ 2 ) / Q6 ( x ^ 2 ) ; otherwise
* erf ( x ) = 1 - erfc ( x ) .
*
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* IEEE 0 , 1 50000 2 . 0 e - 19 5 . 7 e - 20
*
*/
/* erfcl.c
*
* Complementary error function
*
*
*
* SYNOPSIS :
*
* long double x , y , erfcl ( ) ;
*
* y = erfcl ( x ) ;
*
*
*
* DESCRIPTION :
*
*
* 1 - erf ( x ) =
*
* inf .
* -
* 2 | | 2
* erfc ( x ) = - - - - - - - - | exp ( - t ) dt
* sqrt ( pi ) | |
* -
* x
*
*
* For small x , erfc ( x ) = 1 - erf ( x ) ; otherwise rational
* approximations are computed .
*
* A special function expx2l . c is used to suppress error amplification
* in computing exp ( - x ^ 2 ) .
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* IEEE 0 , 13 50000 8 . 4 e - 19 9 . 7 e - 20
* IEEE 6 , 106 . 56 20000 2 . 9 e - 19 7 . 1 e - 20
*
*
* ERROR MESSAGES :
*
* message condition value returned
* erfcl underflow x ^ 2 > MAXLOGL 0 . 0
*
*
*/
/*
Cephes Math Library Release 2 . 3 : January , 1995
Copyright 1984 , 1995 by Stephen L . Moshier
*/
#include "mconf.h"
extern long double MAXLOGL;
static long double SQRTHL = 7 .071067811865475244008 e-1 L;
/* erfc(x) = exp(-x^2) P(1/x)/Q(1/x)
1 / 8 < = 1 / x < = 1
Peak relative error 5.8e-21 */
#if UNK
static long double P[10 ] = {
1 .130609921802431462353 E9L,
2 .290171954844785638925 E9L,
2 .295563412811856278515 E9L,
1 .448651275892911637208 E9L,
6 .234814405521647580919 E8L,
1 .870095071120436715930 E8L,
3 .833161455208142870198 E7L,
4 .964439504376477951135 E6L,
3 .198859502299390825278 E5L,
-9 .085943037416544232472 E-6 L,
};
static long double Q[10 ] = {
/* 1.000000000000000000000E0L, */
1 .130609910594093747762 E9L,
3 .565928696567031388910 E9L,
5 .188672873106859049556 E9L,
4 .588018188918609726890 E9L,
2 .729005809811924550999 E9L,
1 .138778654945478547049 E9L,
3 .358653716579278063988 E8L,
6 .822450775590265689648 E7L,
8 .799239977351261077610 E6L,
5 .669830829076399819566 E5L,
};
#endif
#if IBMPC
static short P[] = {
0 x4bf0,0 x9ad8,0 x7a03,0 x86c7,0 x401d, XPD
0 xdf23,0 xd843,0 x4032,0 x8881,0 x401e, XPD
0 xd025,0 xcfd5,0 x8494,0 x88d3,0 x401e, XPD
0 xb6d0,0 xc92b,0 x5417,0 xacb1,0 x401d, XPD
0 xada8,0 x356a,0 x4982,0 x94a6,0 x401c, XPD
0 x4e13,0 xcaee,0 x9e31,0 xb258,0 x401a, XPD
0 x5840,0 x554d,0 x37a3,0 x9239,0 x4018, XPD
0 x3b58,0 x3da2,0 xaf02,0 x9780,0 x4015, XPD
0 x0144,0 x489e,0 xbe68,0 x9c31,0 x4011, XPD
0 x333b,0 xd9e6,0 xd404,0 x986f,0 xbfee, XPD
};
static short Q[] = {
/* 0x0000,0x0000,0x0000,0x8000,0x3fff, XPD */
0 x0e43,0 x302d,0 x79ed,0 x86c7,0 x401d, XPD
0 xf817,0 x9128,0 xc0f8,0 xd48b,0 x401e, XPD
0 x8eae,0 x8dad,0 x6eb4,0 x9aa2,0 x401f, XPD
0 x00e7,0 x7595,0 xcd06,0 x88bb,0 x401f, XPD
0 x4991,0 xcfda,0 x52f1,0 xa2a9,0 x401e, XPD
0 xc39d,0 xe415,0 xc43d,0 x87c0,0 x401d, XPD
0 xa75d,0 x436f,0 x30dd,0 xa027,0 x401b, XPD
0 xc4cb,0 x305a,0 xbf78,0 x8220,0 x4019, XPD
0 x3708,0 x33b1,0 x07fa,0 x8644,0 x4016, XPD
0 x24fa,0 x96f6,0 x7153,0 x8a6c,0 x4012, XPD
};
#endif
#if MIEEE
static long P[30 ] = {
0 x401d0000,0 x86c77a03,0 x9ad84bf0,
0 x401e0000,0 x88814032,0 xd843df23,
0 x401e0000,0 x88d38494,0 xcfd5d025,
0 x401d0000,0 xacb15417,0 xc92bb6d0,
0 x401c0000,0 x94a64982,0 x356aada8,
0 x401a0000,0 xb2589e31,0 xcaee4e13,
0 x40180000,0 x923937a3,0 x554d5840,
0 x40150000,0 x9780af02,0 x3da23b58,
0 x40110000,0 x9c31be68,0 x489e0144,
0 xbfee0000,0 x986fd404,0 xd9e6333b,
};
static long Q[30 ] = {
/* 0x3fff0000,0x80000000,0x00000000, */
0 x401d0000,0 x86c779ed,0 x302d0e43,
0 x401e0000,0 xd48bc0f8,0 x9128f817,
0 x401f0000,0 x9aa26eb4,0 x8dad8eae,
0 x401f0000,0 x88bbcd06,0 x759500e7,
0 x401e0000,0 xa2a952f1,0 xcfda4991,
0 x401d0000,0 x87c0c43d,0 xe415c39d,
0 x401b0000,0 xa02730dd,0 x436fa75d,
0 x40190000,0 x8220bf78,0 x305ac4cb,
0 x40160000,0 x864407fa,0 x33b13708,
0 x40120000,0 x8a6c7153,0 x96f624fa,
};
#endif
/* erfc(x) = exp(-x^2) 1/x R(1/x^2) / S(1/x^2)
1 / 128 < = 1 / x < 1 / 8
Peak relative error 1.9e-21 */
#if UNK
static long double R[5 ] = {
3 .621349282255624026891 E0L,
7 .173690522797138522298 E0L,
3 .445028155383625172464 E0L,
5 .537445669807799246891 E-1 L,
2 .697535671015506686136 E-2 L,
};
static long double S[5 ] = {
/* 1.000000000000000000000E0L, */
1 .072884067182663823072 E1L,
1 .533713447609627196926 E1L,
6 .572990478128949439509 E0L,
1 .005392977603322982436 E0L,
4 .781257488046430019872 E-2 L,
};
#endif
#if IBMPC
static short R[] = {
0 x260a,0 xab95,0 x2fc7,0 xe7c4,0 x4000, XPD
0 x4761,0 x613e,0 xdf6d,0 xe58e,0 x4001, XPD
0 x0615,0 x4b00,0 x575f,0 xdc7b,0 x4000, XPD
0 x521d,0 x8527,0 x3435,0 x8dc2,0 x3ffe, XPD
0 x22cf,0 xc711,0 x6c5b,0 xdcfb,0 x3ff9, XPD
};
static short S[] = {
/* 0x0000,0x0000,0x0000,0x8000,0x3fff, XPD */
0 x5de6,0 x17d7,0 x54d6,0 xaba9,0 x4002, XPD
0 x55d5,0 xd300,0 xe71e,0 xf564,0 x4002, XPD
0 xb611,0 x8f76,0 xf020,0 xd255,0 x4001, XPD
0 x3684,0 x3798,0 xb793,0 x80b0,0 x3fff, XPD
0 xf5af,0 x2fb2,0 x1e57,0 xc3d7,0 x3ffa, XPD
};
#endif
#if MIEEE
static long R[15 ] = {
0 x40000000,0 xe7c42fc7,0 xab95260a,
0 x40010000,0 xe58edf6d,0 x613e4761,
0 x40000000,0 xdc7b575f,0 x4b000615,
0 x3ffe0000,0 x8dc23435,0 x8527521d,
0 x3ff90000,0 xdcfb6c5b,0 xc71122cf,
};
static long S[15 ] = {
/* 0x3fff0000,0x80000000,0x00000000, */
0 x40020000,0 xaba954d6,0 x17d75de6,
0 x40020000,0 xf564e71e,0 xd30055d5,
0 x40010000,0 xd255f020,0 x8f76b611,
0 x3fff0000,0 x80b0b793,0 x37983684,
0 x3ffa0000,0 xc3d71e57,0 x2fb2f5af,
};
#endif
/* erf(x) = x P(x^2)/Q(x^2)
0 < = x < = 1
Peak relative error 7.6e-23 */
#if UNK
static long double T[7 ] = {
1 .097496774521124996496 E-1 L,
5 .402980370004774841217 E0L,
2 .871822526820825849235 E2L,
2 .677472796799053019985 E3L,
4 .825977363071025440855 E4L,
1 .549905740900882313773 E5L,
1 .104385395713178565288 E6L,
};
static long double U[6 ] = {
/* 1.000000000000000000000E0L, */
4 .525777638142203713736 E1L,
9 .715333124857259246107 E2L,
1 .245905812306219011252 E4L,
9 .942956272177178491525 E4L,
4 .636021778692893773576 E5L,
9 .787360737578177599571 E5L,
};
#endif
#if IBMPC
static short T[] = {
0 xfd7a,0 x3a1a,0 x705b,0 xe0c4,0 x3ffb, XPD
0 x3128,0 xc337,0 x3716,0 xace5,0 x4001, XPD
0 x9517,0 x4e93,0 x540e,0 x8f97,0 x4007, XPD
0 x6118,0 x6059,0 x9093,0 xa757,0 x400a, XPD
0 xb954,0 xa987,0 xc60c,0 xbc83,0 x400e, XPD
0 x7a56,0 xe45a,0 xa4bd,0 x975b,0 x4010, XPD
0 xc446,0 x6bab,0 x0b2a,0 x86d0,0 x4013, XPD
};
static short U[] = {
/* 0x0000,0x0000,0x0000,0x8000,0x3fff, XPD */
0 x3453,0 x1f8e,0 xf688,0 xb507,0 x4004, XPD
0 x71ac,0 xb12f,0 x21ca,0 xf2e2,0 x4008, XPD
0 xffe8,0 x9cac,0 x3b84,0 xc2ac,0 x400c, XPD
0 x481d,0 x445b,0 xc807,0 xc232,0 x400f, XPD
0 x9ad5,0 x1aef,0 x45b1,0 xe25e,0 x4011, XPD
0 x71a7,0 x1cad,0 x012e,0 xeef3,0 x4012, XPD
};
#endif
#if MIEEE
static long T[21 ] = {
0 x3ffb0000,0 xe0c4705b,0 x3a1afd7a,
0 x40010000,0 xace53716,0 xc3373128,
0 x40070000,0 x8f97540e,0 x4e939517,
0 x400a0000,0 xa7579093,0 x60596118,
0 x400e0000,0 xbc83c60c,0 xa987b954,
0 x40100000,0 x975ba4bd,0 xe45a7a56,
0 x40130000,0 x86d00b2a,0 x6babc446,
};
static long U[18 ] = {
/* 0x3fff0000,0x80000000,0x00000000, */
0 x40040000,0 xb507f688,0 x1f8e3453,
0 x40080000,0 xf2e221ca,0 xb12f71ac,
0 x400c0000,0 xc2ac3b84,0 x9cacffe8,
0 x400f0000,0 xc232c807,0 x445b481d,
0 x40110000,0 xe25e45b1,0 x1aef9ad5,
0 x40120000,0 xeef3012e,0 x1cad71a7,
};
#endif
#ifdef ANSIPROT
extern long double polevll ( long double , void *, int );
extern long double p1evll ( long double , void *, int );
extern long double expl ( long double );
extern long double logl ( long double );
extern long double erfl ( long double );
extern long double erfcl ( long double );
extern long double fabsl ( long double );
extern long double expx2l ( long double , int );
extern long double sqrtl (long double );
static long double erfcel (long double );
#else
long double polevll(), p1evll(), expl(), logl(), erfl(), erfcl(), fabsl();
long double expx2l(), sqrtl();
static long double erfcel();
#endif
#ifdef INFINITIES
extern long double INFINITYL;
#endif
long double ndtrl(a)
long double a;
{
long double x, y, z;
x = a * SQRTHL;
z = fabsl(x);
if ( z < 1 .0 )
y = 0 .5 L + 0 .5 L * erfl(x);
else
{
/* See below for erfcel. */
y = 0 .5 L * erfcel(z);
/* Multiply by exp(-x^2 / 2) */
z = expx2l(a, -1 );
y = y * sqrtl(z);
if ( x > 0 .0 L )
y = 1 .0 L - y;
}
return (y);
}
long double erfcl(a)
long double a;
{
long double p,q,x,y,z;
#ifdef INFINITIES
if ( a == INFINITYL )
return (0 .0 L);
if ( a == -INFINITYL )
return (2 .0 L);
#endif
if ( a < 0 .0 L )
x = -a;
else
x = a;
if ( x < 1 .0 L )
return ( 1 .0 L - erfl(a) );
z = -a * a;
if ( z < -MAXLOGL )
{
under:
mtherr( "erfcl" , UNDERFLOW );
if ( a < 0 )
return ( 2 .0 L );
else
return ( 0 .0 L );
}
/* Compute z = expl(z). */
z = expx2l(a, -1 );
y = 1 .0 L/x;
if ( x < 8 .0 L )
{
p = polevll( y, P, 9 );
q = p1evll( y, Q, 10 );
}
else
{
q = y * y;
p = y * polevll( q, R, 4 );
q = p1evll( q, S, 5 );
}
y = (z * p)/q;
if ( a < 0 .0 L )
y = 2 .0 L - y;
if ( y == 0 .0 L )
goto under;
return (y);
}
/* Exponentially scaled erfc function
exp ( x ^ 2 ) erfc ( x )
valid for x > 1 .
Use with ndtrl and expx2l. */
static long double erfcel(x)
long double x;
{
long double p, q, y;
y = 1 .0 L/x;
if ( x < 8 .0 L )
{
p = polevll( y, P, 9 );
q = p1evll( y, Q, 10 );
}
else
{
q = y * y;
p = y * polevll( q, R, 4 );
q = p1evll( q, S, 5 );
}
y = p/q;
return (y);
}
long double erfl(x)
long double x;
{
long double y, z;
#if MINUSZERO
if ( x == 0 .0 L )
return (x);
#endif
#ifdef INFINITIES
if ( x == -INFINITYL )
return (-1 .0 L);
if ( x == INFINITYL )
return (1 .0 L);
#endif
if ( fabsl(x) > 1 .0 L )
return ( 1 .0 L - erfcl(x) );
z = x * x;
y = x * polevll( z, T, 6 ) / p1evll( z, U, 6 );
return ( y );
}
Messung V0.5 in Prozent C=97 H=99 G=97
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-06-13)
¤
*© Formatika GbR, Deutschland