The R Project SVN R

Rev

Rev 68947 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 68947 Rev 70913
Line 1... Line 1...
1
/*
1
/*
2
 *  Mathlib : A C Library of Special Functions
2
 *  Mathlib : A C Library of Special Functions
3
 *  Copyright (C) 1998 	     Ross Ihaka
3
 *  Copyright (C) 1998 	     Ross Ihaka
4
 *  Copyright (C) 2000-12    The R Core Team
4
 *  Copyright (C) 2000--2016 The R Core Team
5
 *  Copyright (C) 2004--2005 The R Foundation
5
 *  Copyright (C) 2004--2016 The R Foundation
6
 *
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
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
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
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  (at your option) any later version.
10
 *  (at your option) any later version.
Line 26... Line 26...
26
#include "nmath.h"
26
#include "nmath.h"
27
#include "dpq.h"
27
#include "dpq.h"
28
 
28
 
29
double qgeom(double p, double prob, int lower_tail, int log_p)
29
double qgeom(double p, double prob, int lower_tail, int log_p)
30
{
30
{
31
    if (prob <= 0 || prob > 1) ML_ERR_return_NAN;
-
 
32
 
-
 
33
    R_Q_P01_boundaries(p, 0, ML_POSINF);
-
 
34
 
-
 
35
#ifdef IEEE_754
31
#ifdef IEEE_754
36
    if (ISNAN(p) || ISNAN(prob))
32
    if (ISNAN(p) || ISNAN(prob))
37
	return p + prob;
33
	return p + prob;
38
#endif
34
#endif
-
 
35
    if (prob <= 0 || prob > 1) ML_ERR_return_NAN;
39
 
36
 
-
 
37
    R_Q_P01_check(p);
40
    if (prob == 1) return(0);
38
    if (prob == 1) return(0);
-
 
39
    R_Q_P01_boundaries(p, 0, ML_POSINF);
-
 
40
 
41
/* add a fuzz to ensure left continuity, but value must be >= 0 */
41
/* add a fuzz to ensure left continuity, but value must be >= 0 */
42
    return fmax2(0, ceil(R_DT_Clog(p) / log1p(- prob) - 1 - 1e-12));
42
    return fmax2(0, ceil(R_DT_Clog(p) / log1p(- prob) - 1 - 1e-12));
43
}
43
}