1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use cratenormcdf;
/// Lognormal cumulative distribution function (CDF).
///
/// Given a value `x`, a mean `mu`, and a standard deviation `sigma`
/// of the associated normal distribution, this function returns the
/// probability that a lognormal random variable is less than or equal to `x`.
///
/// # Mathematical Definition
/// For a lognormal distribution with parameters <math><mi>μ</mi></math> and <math><mi>σ</mi></math>:
/// - Lower tail (`upper = false`): <math><mi>F</mi><mo>(</mo><mi>x</mi><mo>;</mo><mi>μ</mi><mo>,</mo><mi>σ</mi><mo>)</mo><mo>=</mo><mi>Φ</mi><mo>(</mo><mfrac><mrow><mi>ln</mi><mi>x</mi><mo>-</mo><mi>μ</mi></mrow><mi>σ</mi></mfrac><mo>)</mo></math>
/// - Upper tail (`upper = true`): <math><mn>1</mn><mo>-</mo><mi>F</mi><mo>(</mo><mi>x</mi><mo>;</mo><mi>μ</mi><mo>,</mo><mi>σ</mi><mo>)</mo><mo>=</mo><mn>1</mn><mo>-</mo><mi>Φ</mi><mo>(</mo><mfrac><mrow><mi>ln</mi><mi>x</mi><mo>-</mo><mi>μ</mi></mrow><mi>σ</mi></mfrac><mo>)</mo></math>
///
/// where <math><mi>Φ</mi></math> is the standard normal cumulative distribution function.
///
/// # Domain
/// - `x > 0` (Values <math><mi>x</mi><mo>≤</mo><mn>0</mn></math> return 0 for lower tail, 1 for upper tail).
/// - `sigma > 0`
/// - Returns `NaN` if `sigma` is non-positive or any input is `NaN`.
///
/// # Examples
/// ```
/// use abax::logncdf;
///
/// // For a standard lognormal distribution (mu=0, sigma=1)
/// assert!((logncdf(1.0, 0.0, 1.0, false) - 0.5).abs() < 1e-15);
/// // Upper tail at the median
/// assert!((logncdf(1.0, 0.0, 1.0, true) - 0.5).abs() < 1e-15);
/// ```