/* ndtri.c
*
* Inverse of Normal distribution function
*
*
*
* SYNOPSIS :
*
* double x , y , ndtri ( ) ;
*
* x = ndtri ( y ) ;
*
*
*
* DESCRIPTION :
*
* Returns the argument , x , for which the area under the
* Gaussian probability density function ( integrated from
* minus infinity to x ) is equal to y .
*
*
* For small arguments 0 < y < exp ( - 2 ) , the program computes
* z = sqrt ( - 2 . 0 * log ( y ) ) ; then the approximation is
* x = 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 ( 2 pi ) = w + w * * 3 R ( w * * 2 ) / S ( w * * 2 ) ) .
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* DEC 0 . 125 , 1 5500 9 . 5 e - 17 2 . 1 e - 17
* DEC 6 e - 39 , 0 . 135 3500 5 . 7 e - 17 1 . 3 e - 17
* IEEE 0 . 125 , 1 20000 7 . 2 e - 16 1 . 3 e - 16
* IEEE 3 e - 308 , 0 . 135 50000 4 . 6 e - 16 9 . 8 e - 17
*
*
* ERROR MESSAGES :
*
* message condition value returned
* ndtri domain x < = 0 - MAXNUM
* ndtri domain x > = 1 MAXNUM
*
*/
/*
Cephes Math Library Release 2 . 1 : January , 1989
Copyright 1984 , 1987 , 1989 by Stephen L . Moshier
Direct inquiries to 30 Frost Street , Cambridge , MA 02140
*/
#include "mconf.h"
extern double MAXNUM;
#ifdef UNK
/* sqrt(2pi) */
static double s2pi = 2 .50662827463100050242 E0;
#endif
#ifdef DEC
static unsigned short s2p[] = {0040440 ,0066230 ,0177661 ,0034055 };
#define s2pi *(double *)s2p
#endif
#ifdef IBMPC
static unsigned short s2p[] = {0 x2706,0 x1ff6,0 x0d93,0 x4004};
#define s2pi *(double *)s2p
#endif
#ifdef MIEEE
static unsigned short s2p[] = {
0 x4004,0 x0d93,0 x1ff6,0 x2706
};
#define s2pi *(double *)s2p
#endif
/* approximation for 0 <= |y - 0.5| <= 3/8 */
#ifdef UNK
static double P0[5 ] = {
-5 .99633501014107895267 E1,
9 .80010754185999661536 E1,
-5 .66762857469070293439 E1,
1 .39312609387279679503 E1,
-1 .23916583867381258016 E0,
};
static double Q0[8 ] = {
/* 1.00000000000000000000E0,*/
1 .95448858338141759834 E0,
4 .67627912898881538453 E0,
8 .63602421390890590575 E1,
-2 .25462687854119370527 E2,
2 .00260212380060660359 E2,
-8 .20372256168333339912 E1,
1 .59056225126211695515 E1,
-1 .18331621121330003142 E0,
};
#endif
#ifdef DEC
static unsigned short P0[20 ] = {
0141557 ,0155170 ,0071360 ,0120550 ,
0041704 ,0000214 ,0172417 ,0067307 ,
0141542 ,0132204 ,0040066 ,0156723 ,
0041136 ,0163161 ,0157276 ,0007747 ,
0140236 ,0116374 ,0073666 ,0051764 ,
};
static unsigned short Q0[32 ] = {
/*0040200,0000000,0000000,0000000,*/
0040372 ,0026256 ,0110403 ,0123707 ,
0040625 ,0122024 ,0020277 ,0026661 ,
0041654 ,0134161 ,0124134 ,0007244 ,
0142141 ,0073162 ,0133021 ,0131371 ,
0042110 ,0041235 ,0043516 ,0057767 ,
0141644 ,0011417 ,0036155 ,0137305 ,
0041176 ,0076556 ,0004043 ,0125430 ,
0140227 ,0073347 ,0152776 ,0067251 ,
};
#endif
#ifdef IBMPC
static unsigned short P0[20 ] = {
0 x142d,0 x0e5e,0 xfb4f,0 xc04d,
0 xedd9,0 x9ea1,0 x8011,0 x4058,
0 xdbba,0 x8806,0 x5690,0 xc04c,
0 xc1fd,0 x3bd7,0 xdcce,0 x402b,
0 xca7e,0 x8ef6,0 xd39f,0 xbff3,
};
static unsigned short Q0[36 ] = {
/*0x0000,0x0000,0x0000,0x3ff0,*/
0 x74f9,0 xd220,0 x4595,0 x3fff,
0 xe5b6,0 x8417,0 xb482,0 x4012,
0 x81d4,0 x350b,0 x970e,0 x4055,
0 x365f,0 x56c2,0 x2ece,0 xc06c,
0 xcbff,0 xa8e9,0 x0853,0 x4069,
0 xb7d9,0 xe78d,0 x8261,0 xc054,
0 x7563,0 xc104,0 xcfad,0 x402f,
0 xcdd5,0 xfabf,0 xeedc,0 xbff2,
};
#endif
#ifdef MIEEE
static unsigned short P0[20 ] = {
0 xc04d,0 xfb4f,0 x0e5e,0 x142d,
0 x4058,0 x8011,0 x9ea1,0 xedd9,
0 xc04c,0 x5690,0 x8806,0 xdbba,
0 x402b,0 xdcce,0 x3bd7,0 xc1fd,
0 xbff3,0 xd39f,0 x8ef6,0 xca7e,
};
static unsigned short Q0[32 ] = {
/*0x3ff0,0x0000,0x0000,0x0000,*/
0 x3fff,0 x4595,0 xd220,0 x74f9,
0 x4012,0 xb482,0 x8417,0 xe5b6,
0 x4055,0 x970e,0 x350b,0 x81d4,
0 xc06c,0 x2ece,0 x56c2,0 x365f,
0 x4069,0 x0853,0 xa8e9,0 xcbff,
0 xc054,0 x8261,0 xe78d,0 xb7d9,
0 x402f,0 xcfad,0 xc104,0 x7563,
0 xbff2,0 xeedc,0 xfabf,0 xcdd5,
};
#endif
/* Approximation for interval z = sqrt(-2 log y ) between 2 and 8
* i . e . , y between exp ( - 2 ) = . 135 and exp ( - 32 ) = 1 . 27 e - 14 .
*/
#ifdef UNK
static double P1[9 ] = {
4 .05544892305962419923 E0,
3 .15251094599893866154 E1,
5 .71628192246421288162 E1,
4 .40805073893200834700 E1,
1 .46849561928858024014 E1,
2 .18663306850790267539 E0,
-1 .40256079171354495875 E-1 ,
-3 .50424626827848203418 E-2 ,
-8 .57456785154685413611 E-4 ,
};
static double Q1[8 ] = {
/* 1.00000000000000000000E0,*/
1 .57799883256466749731 E1,
4 .53907635128879210584 E1,
4 .13172038254672030440 E1,
1 .50425385692907503408 E1,
2 .50464946208309415979 E0,
-1 .42182922854787788574 E-1 ,
-3 .80806407691578277194 E-2 ,
-9 .33259480895457427372 E-4 ,
};
#endif
#ifdef DEC
static unsigned short P1[36 ] = {
0040601 ,0143074 ,0150744 ,0073326 ,
0041374 ,0031554 ,0113253 ,0146016 ,
0041544 ,0123272 ,0012463 ,0176771 ,
0041460 ,0051160 ,0103560 ,0156511 ,
0041152 ,0172624 ,0117772 ,0030755 ,
0040413 ,0170713 ,0151545 ,0176413 ,
0137417 ,0117512 ,0022154 ,0131671 ,
0137017 ,0104257 ,0071432 ,0007072 ,
0135540 ,0143363 ,0063137 ,0036166 ,
};
static unsigned short Q1[32 ] = {
/*0040200,0000000,0000000,0000000,*/
0041174 ,0075325 ,0004736 ,0120326 ,
0041465 ,0110044 ,0047561 ,0045567 ,
0041445 ,0042321 ,0012142 ,0030340 ,
0041160 ,0127074 ,0166076 ,0141051 ,
0040440 ,0046055 ,0040745 ,0150400 ,
0137421 ,0114146 ,0067330 ,0010621 ,
0137033 ,0175162 ,0025555 ,0114351 ,
0135564 ,0122773 ,0145750 ,0030357 ,
};
#endif
#ifdef IBMPC
static unsigned short P1[36 ] = {
0 x8edb,0 x9a3c,0 x38c7,0 x4010,
0 x7982,0 x92d5,0 x866d,0 x403f,
0 x7fbf,0 x42a6,0 x94d7,0 x404c,
0 x1ba9,0 x10ee,0 x0a4e,0 x4046,
0 x463e,0 x93ff,0 x5eb2,0 x402d,
0 xbfa1,0 x7a6c,0 x7e39,0 x4001,
0 x9677,0 x448d,0 xf3e9,0 xbfc1,
0 x41c7,0 xee63,0 xf115,0 xbfa1,
0 xe78f,0 x6ccb,0 x18de,0 xbf4c,
};
static unsigned short Q1[32 ] = {
/*0x0000,0x0000,0x0000,0x3ff0,*/
0 xd41b,0 xa13b,0 x8f5a,0 x402f,
0 x296f,0 x89ee,0 xb204,0 x4046,
0 x461c,0 x228c,0 xa89a,0 x4044,
0 xd845,0 x9d87,0 x15c7,0 x402e,
0 xba20,0 xa83c,0 x0985,0 x4004,
0 x0232,0 xcddb,0 x330c,0 xbfc2,
0 xb31d,0 x456d,0 x7f4e,0 xbfa3,
0 x061e,0 x797d,0 x94bf,0 xbf4e,
};
#endif
#ifdef MIEEE
static unsigned short P1[36 ] = {
0 x4010,0 x38c7,0 x9a3c,0 x8edb,
0 x403f,0 x866d,0 x92d5,0 x7982,
0 x404c,0 x94d7,0 x42a6,0 x7fbf,
0 x4046,0 x0a4e,0 x10ee,0 x1ba9,
0 x402d,0 x5eb2,0 x93ff,0 x463e,
0 x4001,0 x7e39,0 x7a6c,0 xbfa1,
0 xbfc1,0 xf3e9,0 x448d,0 x9677,
0 xbfa1,0 xf115,0 xee63,0 x41c7,
0 xbf4c,0 x18de,0 x6ccb,0 xe78f,
};
static unsigned short Q1[32 ] = {
/*0x3ff0,0x0000,0x0000,0x0000,*/
0 x402f,0 x8f5a,0 xa13b,0 xd41b,
0 x4046,0 xb204,0 x89ee,0 x296f,
0 x4044,0 xa89a,0 x228c,0 x461c,
0 x402e,0 x15c7,0 x9d87,0 xd845,
0 x4004,0 x0985,0 xa83c,0 xba20,
0 xbfc2,0 x330c,0 xcddb,0 x0232,
0 xbfa3,0 x7f4e,0 x456d,0 xb31d,
0 xbf4e,0 x94bf,0 x797d,0 x061e,
};
#endif
/* Approximation for interval z = sqrt(-2 log y ) between 8 and 64
* i . e . , y between exp ( - 32 ) = 1 . 27 e - 14 and exp ( - 2048 ) = 3 . 67 e - 890 .
*/
#ifdef UNK
static double P2[9 ] = {
3 .23774891776946035970 E0,
6 .91522889068984211695 E0,
3 .93881025292474443415 E0,
1 .33303460815807542389 E0,
2 .01485389549179081538 E-1 ,
1 .23716634817820021358 E-2 ,
3 .01581553508235416007 E-4 ,
2 .65806974686737550832 E-6 ,
6 .23974539184983293730 E-9 ,
};
static double Q2[8 ] = {
/* 1.00000000000000000000E0,*/
6 .02427039364742014255 E0,
3 .67983563856160859403 E0,
1 .37702099489081330271 E0,
2 .16236993594496635890 E-1 ,
1 .34204006088543189037 E-2 ,
3 .28014464682127739104 E-4 ,
2 .89247864745380683936 E-6 ,
6 .79019408009981274425 E-9 ,
};
#endif
#ifdef DEC
static unsigned short P2[36 ] = {
0040517 ,0033507 ,0036236 ,0125641 ,
0040735 ,0044616 ,0014473 ,0140133 ,
0040574 ,0012567 ,0114535 ,0102541 ,
0040252 ,0120340 ,0143474 ,0150135 ,
0037516 ,0051057 ,0115361 ,0031211 ,
0036512 ,0131204 ,0101511 ,0125144 ,
0035236 ,0016627 ,0043160 ,0140216 ,
0033462 ,0060512 ,0060141 ,0010641 ,
0031326 ,0062541 ,0101304 ,0077706 ,
};
static unsigned short Q2[32 ] = {
/*0040200,0000000,0000000,0000000,*/
0040700 ,0143322 ,0132137 ,0040501 ,
0040553 ,0101155 ,0053221 ,0140257 ,
0040260 ,0041071 ,0052573 ,0010004 ,
0037535 ,0066472 ,0177261 ,0162330 ,
0036533 ,0160475 ,0066666 ,0036132 ,
0035253 ,0174533 ,0027771 ,0044027 ,
0033502 ,0016147 ,0117666 ,0063671 ,
0031351 ,0047455 ,0141663 ,0054751 ,
};
#endif
#ifdef IBMPC
static unsigned short P2[36 ] = {
0 xd574,0 xe793,0 xe6e8,0 x4009,
0 x780b,0 xc327,0 xa931,0 x401b,
0 xb0ac,0 xf32b,0 x82ae,0 x400f,
0 x9a0c,0 x18e7,0 x541c,0 x3ff5,
0 x2651,0 xf35e,0 xca45,0 x3fc9,
0 x354d,0 x9069,0 x5650,0 x3f89,
0 x1812,0 xe8ce,0 xc3b2,0 x3f33,
0 x2234,0 x4c0c,0 x4c29,0 x3ec6,
0 x8ff9,0 x3058,0 xccac,0 x3e3a,
};
static unsigned short Q2[32 ] = {
/*0x0000,0x0000,0x0000,0x3ff0,*/
0 xe828,0 x568b,0 x18da,0 x4018,
0 x3816,0 xaad2,0 x704d,0 x400d,
0 x6200,0 x2aaf,0 x0847,0 x3ff6,
0 x3c9b,0 x5fd6,0 xada7,0 x3fcb,
0 xc78b,0 xadb6,0 x7c27,0 x3f8b,
0 x2903,0 x65ff,0 x7f2b,0 x3f35,
0 xccf7,0 xf3f6,0 x438c,0 x3ec8,
0 x6b3d,0 xb876,0 x29e5,0 x3e3d,
};
#endif
#ifdef MIEEE
static unsigned short P2[36 ] = {
0 x4009,0 xe6e8,0 xe793,0 xd574,
0 x401b,0 xa931,0 xc327,0 x780b,
0 x400f,0 x82ae,0 xf32b,0 xb0ac,
0 x3ff5,0 x541c,0 x18e7,0 x9a0c,
0 x3fc9,0 xca45,0 xf35e,0 x2651,
0 x3f89,0 x5650,0 x9069,0 x354d,
0 x3f33,0 xc3b2,0 xe8ce,0 x1812,
0 x3ec6,0 x4c29,0 x4c0c,0 x2234,
0 x3e3a,0 xccac,0 x3058,0 x8ff9,
};
static unsigned short Q2[32 ] = {
/*0x3ff0,0x0000,0x0000,0x0000,*/
0 x4018,0 x18da,0 x568b,0 xe828,
0 x400d,0 x704d,0 xaad2,0 x3816,
0 x3ff6,0 x0847,0 x2aaf,0 x6200,
0 x3fcb,0 xada7,0 x5fd6,0 x3c9b,
0 x3f8b,0 x7c27,0 xadb6,0 xc78b,
0 x3f35,0 x7f2b,0 x65ff,0 x2903,
0 x3ec8,0 x438c,0 xf3f6,0 xccf7,
0 x3e3d,0 x29e5,0 xb876,0 x6b3d,
};
#endif
double ndtri(y0)
double y0;
{
double x, y, z, y2, x0, x1;
int code;
double polevl(), p1evl(), log(), sqrt();
if ( y0 <= 0 .0 )
{
mtherr( "ndtri" , DOMAIN );
return ( -MAXNUM );
}
if ( y0 >= 1 .0 )
{
mtherr( "ndtri" , DOMAIN );
return ( MAXNUM );
}
code = 1 ;
y = y0;
if ( y > (1 .0 - 0 .13533528323661269189 ) ) /* 0.135... = exp(-2) */
{
y = 1 .0 - y;
code = 0 ;
}
if ( y > 0 .13533528323661269189 )
{
y = y - 0 .5 ;
y2 = y * y;
x = y + y * (y2 * polevl( y2, P0, 4 )/p1evl( y2, Q0, 8 ));
x = x * s2pi;
return (x);
}
x = sqrt( -2 .0 * log(y) );
x0 = x - log(x)/x;
z = 1 .0 /x;
if ( x < 8 .0 ) /* y > exp(-32) = 1.2664165549e-14 */
x1 = z * polevl( z, P1, 8 )/p1evl( z, Q1, 8 );
else
x1 = z * polevl( z, P2, 8 )/p1evl( z, Q2, 8 );
x = x0 - x1;
if ( code != 0 )
x = -x;
return ( x );
}
Messung V0.5 in Prozent C=93 H=90 G=91
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-06-27)
¤
*© Formatika GbR, Deutschland