|
Rcpp Version 0.9.10
|
00001 00002 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*- 00003 // 00004 // auto generated file (from script/stats.R) 00005 // 00006 // exp.h: Rcpp R/C++ interface class library -- 00007 // 00008 // Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois 00009 // 00010 // This file is part of Rcpp. 00011 // 00012 // Rcpp is free software: you can redistribute it and/or modify it 00013 // under the terms of the GNU General Public License as published by 00014 // the Free Software Foundation, either version 2 of the License, or 00015 // (at your option) any later version. 00016 // 00017 // Rcpp is distributed in the hope that it will be useful, but 00018 // WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of the GNU General Public License 00023 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>. 00024 00025 #ifndef Rcpp__stats__exp_h 00026 #define Rcpp__stats__exp_h 00027 00028 namespace Rcpp { 00029 namespace stats { 00030 inline double d_exp_0( double x, int give_log){ 00031 00032 #ifdef IEEE_754 00033 /* NaNs propagated correctly */ 00034 if (ISNAN(x) ) return x + 1.0 ; 00035 #endif 00036 00037 if (x < 0.) 00038 return R_D__0; 00039 return give_log ? (-x) : ::exp(-x); 00040 } 00041 inline double q_exp_0( double p, int lower_tail, int log_p){ 00042 #ifdef IEEE_754 00043 if (ISNAN(p)) return p + 1.0; 00044 #endif 00045 00046 if ((log_p && p > 0) || (!log_p && (p < 0 || p > 1)) ) return R_NaN ; 00047 if (p == R_DT_0) 00048 return 0; 00049 00050 return - R_DT_Clog(p); 00051 } 00052 inline double p_exp_0(double x, int lower_tail, int log_p) { 00053 #ifdef IEEE_754 00054 if (ISNAN(x) ) 00055 return x + 1.0 ; 00056 #endif 00057 00058 if (x <= 0.) 00059 return R_DT_0; 00060 /* same as weibull( shape = 1): */ 00061 x = -x; 00062 if (lower_tail) 00063 return (log_p 00064 /* log(1 - exp(x)) for x < 0 : */ 00065 ? (x > -M_LN2 ? ::log(-::expm1(x)) : ::log1p(-::exp(x))) 00066 : -::expm1(x)); 00067 /* else: !lower_tail */ 00068 return R_D_exp(x); 00069 } 00070 00071 } // stats 00072 } // Rcpp 00073 00074 RCPP_DPQ_0(exp,Rcpp::stats::d_exp_0,Rcpp::stats::p_exp_0,Rcpp::stats::q_exp_0) 00075 00076 namespace Rcpp{ 00077 00078 // we cannot use the RCPP_DPQ_1 macro here because of rate and shape 00079 template <bool NA, typename T> 00080 inline stats::D1<REALSXP,NA,T> dexp( const Rcpp::VectorBase<REALSXP,NA,T>& x, double shape, bool log = false ) { 00081 return stats::D1<REALSXP,NA,T>( ::Rf_dexp, x, 1.0/shape, log ); 00082 } 00083 00084 template <bool NA, typename T> 00085 inline stats::P1<REALSXP,NA,T> pexp( const Rcpp::VectorBase<REALSXP,NA,T>& x, double shape, bool lower = true, bool log = false ) { 00086 return stats::P1<REALSXP,NA,T>( ::Rf_pexp, x, 1.0/shape, lower, log ); 00087 } 00088 00089 template <bool NA, typename T> 00090 inline stats::Q1<REALSXP,NA,T> qexp( const Rcpp::VectorBase<REALSXP,NA,T>& x, double shape, bool lower = true, bool log = false ) { 00091 return stats::Q1<REALSXP,NA,T>( ::Rf_qexp, x, 1.0/shape, lower, log ); 00092 } 00093 00094 } // Rcpp 00095 00096 #endif 00097