Rcpp Version 0.12.12
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 
27 namespace Rcpp {
28 namespace stats {
29 
30 inline 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 }
56 inline 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 }
59 inline 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
71 RCPP_DPQ_2(gamma,::Rf_dgamma,::Rf_pgamma,::Rf_qgamma)
72 
73 
74 #endif
75 
double dgamma_1(double x, double shape, int log_p)
Definition: gamma.h:30
double pgamma_1(double x, double alph, int lower_tail, int log_p)
Definition: gamma.h:56
#define ML_POSINF
Definition: stats.h:27
double qgamma_1(double p, double alpha, int lower_tail, int log_p)
Definition: gamma.h:59
#define RCPP_DPQ_1(__NAME__, __D__, __P__, __Q__)
Definition: dpq.h:340
#define RCPP_DPQ_2(__NAME__, __D__, __P__, __Q__)
Definition: dpq.h:363
void log(InputIterator begin, InputIterator end, OutputIterator out)
Definition: algorithm.h:469
#define R_D__0
Definition: macros.h:27
Rcpp API.
Definition: algo.h:28