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