Rcpp Version 1.0.14
Loading...
Searching...
No Matches
gamma.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2//
3// auto generated file (from script/stats.R)
4//
5// gamma.h: Rcpp R/C++ interface class library --
6//
7// Copyright (C) 2010 - 2016 Douglas Bates, Dirk Eddelbuettel and Romain Francois
8//
9// This file is part of Rcpp.
10//
11// Rcpp is free software: you can redistribute it and/or modify it
12// under the terms of the GNU General Public License as published by
13// the Free Software Foundation, either version 2 of the License, or
14// (at your option) any later version.
15//
16// Rcpp is distributed in the hope that it will be useful, but
17// WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
23
24#ifndef Rcpp__stats__gamma_h
25#define Rcpp__stats__gamma_h
26
27namespace Rcpp {
28namespace stats {
29
30inline double dgamma_1(double x, double shape, int log_p){
31 double pr;
32#ifdef IEEE_754
33 if (ISNAN(x) || ISNAN(shape) )
34 return x + shape + 1.0 ;
35#endif
36 if (shape < 0) return R_NaN ;
37 if (x < 0)
38 return R_D__0;
39 if (shape == 0) /* point mass at 0 */
40 return (x == 0)? ML_POSINF : R_D__0;
41 if (x == 0) {
42 if (shape < 1) return ML_POSINF;
43 if (shape > 1) return R_D__0;
44 /* else */
45 return log_p ? 0.0 : 1.0 ;
46 }
47
48 if (shape < 1) {
49 pr = ::Rf_dpois(shape, x, log_p);
50 return log_p ? pr + ::log(shape/x) : pr*shape/x;
51 }
52 /* else shape >= 1 */
53 pr = ::Rf_dpois(shape-1, x, log_p);
54 return pr;
55}
56inline double pgamma_1(double x, double alph, int lower_tail, int log_p){
57 return ::Rf_pgamma(x, alph, 1.0, lower_tail, log_p) ;
58}
59inline double qgamma_1(double p, double alpha, int lower_tail, int log_p){
60 return ::Rf_qgamma(p, alpha, 1.0, lower_tail, log_p );
61}
62
63}
64}
65
66// 1 parameter case (scale = 1)
68
69
70// 2 parameter case
71RCPP_DPQ_2(gamma,::Rf_dgamma,::Rf_pgamma,::Rf_qgamma)
72
73
74#endif
75
#define RCPP_DPQ_2(__NAME__, __D__, __P__, __Q__)
Definition dpq.h:363
#define RCPP_DPQ_1(__NAME__, __D__, __P__, __Q__)
Definition dpq.h:340
double pgamma_1(double x, double alph, int lower_tail, int log_p)
Definition gamma.h:56
double dgamma_1(double x, double shape, int log_p)
Definition gamma.h:30
double qgamma_1(double p, double alpha, int lower_tail, int log_p)
Definition gamma.h:59
Rcpp API.
Definition algo.h:28
T as(SEXP x)
Definition as.h:151
#define R_D__0
Definition macros.h:27
#define ML_POSINF
Definition stats.h:27