Rcpp Version 1.0.9
exp.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 // exp.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__exp_h
25 #define Rcpp__stats__exp_h
26 
27 namespace Rcpp {
28 namespace stats {
29 
30 inline double d_exp_0(double x, int give_log) {
31 
32 #ifdef IEEE_754
33  /* NaNs propagated correctly */
34  if (ISNAN(x)) return x + 1.0;
35 #endif
36 
37  if (x < 0.)
38  return R_D__0;
39  return give_log ? (-x) : ::exp(-x);
40 }
41 
42 inline double q_exp_0(double p, int lower_tail, int log_p) {
43 #ifdef IEEE_754
44  if (ISNAN(p)) return p + 1.0;
45 #endif
46 
47  if ((log_p && p > 0) || (!log_p && (p < 0 || p > 1))) return R_NaN;
48  if (p == R_DT_0)
49  return 0;
50 
51  return - R_DT_Clog(p);
52 }
53 
54 inline double p_exp_0(double x, int lower_tail, int log_p) {
55 #ifdef IEEE_754
56  if (ISNAN(x)) return x + 1.0;
57 #endif
58 
59  if (x <= 0.)
60  return R_DT_0;
61  /* same as weibull(shape = 1): */
62  x = -x;
63  if (lower_tail)
64  return (log_p
65  /* log(1 - exp(x)) for x < 0 : */
66  ? (x > -M_LN2 ? ::log(-::expm1(x)) : ::log1p(-::exp(x)))
67  : -::expm1(x));
68  /* else: !lower_tail */
69  return R_D_exp(x);
70 }
71 
72 } // stats
73 } // Rcpp
74 
76 
77 namespace Rcpp{
78 
79 // we cannot use the RCPP_DPQ_1 macro here because of rate and shape
80 template <bool NA, typename T>
81 inline stats::D1<REALSXP,NA,T> dexp( const Rcpp::VectorBase<REALSXP,NA,T>& x, double shape, bool log = false ) {
82  return stats::D1<REALSXP,NA,T>( ::Rf_dexp, x, 1.0/shape, log );
83 }
84 
85 template <bool NA, typename T>
86 inline stats::P1<REALSXP,NA,T> pexp( const Rcpp::VectorBase<REALSXP,NA,T>& x, double shape, bool lower = true, bool log = false ) {
87  return stats::P1<REALSXP,NA,T>( ::Rf_pexp, x, 1.0/shape, lower, log );
88 }
89 
90 template <bool NA, typename T>
91 inline stats::Q1<REALSXP,NA,T> qexp( const Rcpp::VectorBase<REALSXP,NA,T>& x, double shape, bool lower = true, bool log = false ) {
92  return stats::Q1<REALSXP,NA,T>( ::Rf_qexp, x, 1.0/shape, lower, log );
93 }
94 
95 } // Rcpp
96 
97 #endif
98 
#define RCPP_DPQ_0(__NAME__, __D__, __P__, __Q__)
Definition: dpq.h:318
double expm1(double x)
double log1p(double x)
void exp(InputIterator begin, InputIterator end, OutputIterator out)
Definition: algorithm.h:474
void log(InputIterator begin, InputIterator end, OutputIterator out)
Definition: algorithm.h:469
double d_exp_0(double x, int give_log)
Definition: exp.h:30
double p_exp_0(double x, int lower_tail, int log_p)
Definition: exp.h:54
double q_exp_0(double p, int lower_tail, int log_p)
Definition: exp.h:42
Rcpp API.
Definition: algo.h:28
stats::D1< REALSXP, NA, T > dexp(const Rcpp::VectorBase< REALSXP, NA, T > &x, double shape, bool log=false)
Definition: exp.h:81
stats::Q1< REALSXP, NA, T > qexp(const Rcpp::VectorBase< REALSXP, NA, T > &x, double shape, bool lower=true, bool log=false)
Definition: exp.h:91
stats::P1< REALSXP, NA, T > pexp(const Rcpp::VectorBase< REALSXP, NA, T > &x, double shape, bool lower=true, bool log=false)
Definition: exp.h:86
#define R_DT_0
Definition: macros.h:29
#define R_D__0
Definition: macros.h:27
#define give_log
Definition: macros.h:24
#define R_D_exp(x)
Definition: macros.h:38
#define R_DT_Clog(p)
Definition: macros.h:63