Rcpp Version 0.9.10
weibull.h
Go to the documentation of this file.
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 // weibull.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__weibull_h
00026 #define Rcpp__stats__weibull_h
00027 
00028 namespace Rcpp {
00029 namespace stats {
00030 
00031 inline double dweibull_1(double x, double shape /*, double scale [=1.0] */ , int give_log){
00032     double tmp1, tmp2;
00033 #ifdef IEEE_754
00034     if (ISNAN(x) || ISNAN(shape) )
00035         return x + shape + 1.0;
00036 #endif
00037     if (shape <= 0 ) return R_NaN ;
00038 
00039     if (x < 0) return R_D__0;
00040     if (!R_FINITE(x)) return R_D__0;
00041     /* need to handle x == 0 separately */
00042     if(x == 0 && shape < 1) return ML_POSINF;
00043     tmp1 = ::pow(x, shape - 1);
00044     tmp2 = tmp1 * x;
00045     /* These are incorrect if tmp1 == 0 */
00046     return  give_log ?
00047         -tmp2 + ::log(shape * tmp1 ) :
00048         shape * tmp1 * ::exp(-tmp2) ;
00049 }
00050 inline double pweibull_1(double x, double shape /*, double scale [=1.0] */, int lower_tail, int log_p) {
00051 #ifdef IEEE_754
00052     if (ISNAN(x) || ISNAN(shape) )
00053         return x + shape + 1.0;
00054 #endif
00055     if(shape <= 0) return R_NaN;
00056 
00057     if (x <= 0)
00058         return R_DT_0;
00059         x = -::pow(x , shape);
00060     if (lower_tail)
00061         return (log_p
00062                 /* log(1 - exp(x))  for x < 0 : */
00063                 ? (x > -M_LN2 ? ::log(-::expm1(x)) : ::log1p(-::exp(x)))
00064                 : -::expm1(x));
00065     /* else:  !lower_tail */
00066     return R_D_exp(x);
00067 }
00068 inline double qweibull_1(double p, double shape /*, double scale [=1.0] */, int lower_tail, int log_p){
00069 #ifdef IEEE_754
00070     if (ISNAN(p) || ISNAN(shape))
00071         return p + shape + 1.0;
00072 #endif
00073     if (shape <= 0 ) return R_NaN ;
00074 
00075     R_Q_P01_boundaries(p, 0, ML_POSINF);
00076 
00077     return ::pow(- R_DT_Clog(p), 1./shape) ;
00078 }
00079 
00080 } // stats
00081 } // Rcpp
00082 
00083 RCPP_DPQ_1(weibull,Rcpp::stats::dweibull_1,Rcpp::stats::pweibull_1,Rcpp::stats::qweibull_1)
00084 RCPP_DPQ_2(weibull,::Rf_dweibull,::Rf_pweibull,::Rf_qweibull)
00085 
00086 #endif
00087 
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Defines