Coverage Report

Created: 2026-09-14 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/r-source/src/nmath/qgeom.c
Line
Count
Source
1
/*
2
 *  Mathlib : A C Library of Special Functions
3
 *  Copyright (C) 1998       Ross Ihaka
4
 *  Copyright (C) 2000--2016 The R Core Team
5
 *  Copyright (C) 2004--2016 The R Foundation
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  (at your option) any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program; if not, a copy is available at
19
 *  https://www.R-project.org/Licenses/
20
 *
21
 *  DESCRIPTION
22
 *
23
 *    The quantile function of the geometric distribution.
24
 */
25
26
#include "nmath.h"
27
#include "dpq.h"
28
29
double qgeom(double p, double prob, int lower_tail, int log_p)
30
0
{
31
0
#ifdef IEEE_754
32
0
    if (ISNAN(p) || ISNAN(prob))
33
0
  return p + prob;
34
0
#endif
35
0
    if (prob <= 0 || prob > 1) ML_WARN_return_NAN;
36
37
0
    R_Q_P01_check(p);
38
0
    if (prob == 1) return(0);
39
0
    R_Q_P01_boundaries(p, 0, ML_POSINF);
40
41
/* add a fuzz to ensure left continuity, but value must be >= 0 */
42
0
    return fmax2(0, ceil(R_DT_Clog(p) / log1p(- prob) - 1 - 1e-12));
43
0
}