MCPcopy Create free account
hub / github.com/apache/arrow / NormalPPF

Function NormalPPF

cpp/src/arrow/util/math_internal.cc:26–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24namespace arrow::internal {
25
26double NormalPPF(double p) {
27 DCHECK(p >= 0.0 && p <= 1.0);
28 if (p == 0.0) {
29 return -HUGE_VAL;
30 }
31 if (p == 1.0) {
32 return HUGE_VAL;
33 }
34
35 // Algorithm from https://doi.org/10.2307/2347330
36 // Wichura, M. J. (1988).
37 // Algorithm AS 241: The Percentage Points of the Normal Distribution.
38 // Journal of the Royal Statistical Society. Series C (Applied Statistics),
39 // 37(3), 477-484.
40 //
41 // Copied from the Rust implementation at https://github.com/ankane/dist-rust/
42 double q = p - 0.5;
43 if (std::abs(q) < 0.425) {
44 double r = 0.180625 - q * q;
45 return q *
46 (((((((2.5090809287301226727e3 * r + 3.3430575583588128105e4) * r +
47 6.7265770927008700853e4) *
48 r +
49 4.5921953931549871457e4) *
50 r +
51 1.3731693765509461125e4) *
52 r +
53 1.9715909503065514427e3) *
54 r +
55 1.3314166789178437745e2) *
56 r +
57 3.3871328727963666080e0) /
58 (((((((5.2264952788528545610e3 * r + 2.8729085735721942674e4) * r +
59 3.9307895800092710610e4) *
60 r +
61 2.1213794301586595867e4) *
62 r +
63 5.3941960214247511077e3) *
64 r +
65 6.8718700749205790830e2) *
66 r +
67 4.2313330701600911252e1) *
68 r +
69 1.0);
70 } else {
71 double r = q < 0.0 ? p : 1.0 - p;
72 r = std::sqrt(-std::log(r));
73 if (r < 5.0) {
74 r -= 1.6;
75 r = (((((((7.74545014278341407640e-4 * r + 2.27238449892691845833e-2) * r +
76 2.41780725177450611770e-1) *
77 r +
78 1.27045825245236838258e0) *
79 r +
80 3.64784832476320460504e0) *
81 r +
82 5.76949722146069140550e0) *
83 r +

Callers 2

TESTFunction · 0.85
TransformValueMethod · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68