Rcpp Version 1.0.9
weibull.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 // weibull.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__weibull_h
25 #define Rcpp__stats__weibull_h
26 
27 namespace Rcpp {
28 namespace stats {
29 
30 inline double dweibull_1(double x, double shape /*, double scale [=1.0] */ , int give_log){
31  double tmp1, tmp2;
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 
38  if (x < 0) return R_D__0;
39  if (!R_FINITE(x)) return R_D__0;
40  /* need to handle x == 0 separately */
41  if (x == 0 && shape < 1) return ML_POSINF;
42  tmp1 = ::pow(x, shape - 1);
43  tmp2 = tmp1 * x;
44  /* These are incorrect if tmp1 == 0 */
45  return give_log ?
46  -tmp2 + ::log(shape * tmp1) :
47  shape * tmp1 * ::exp(-tmp2);
48 }
49 inline double pweibull_1(double x, double shape /*, double scale [=1.0] */, int lower_tail, int log_p) {
50 #ifdef IEEE_754
51  if (ISNAN(x) || ISNAN(shape))
52  return x + shape + 1.0;
53 #endif
54  if (shape <= 0) return R_NaN;
55 
56  if (x <= 0)
57  return R_DT_0;
58  x = -::pow(x , shape);
59  if (lower_tail)
60  return (log_p
61  /* log(1 - exp(x)) for x < 0 : */
62  ? (x > -M_LN2 ? ::log(-::expm1(x)) : ::log1p(-::exp(x)))
63  : -::expm1(x));
64  /* else: !lower_tail */
65  return R_D_exp(x);
66 }
67 inline double qweibull_1(double p, double shape /*, double scale [=1.0] */, int lower_tail, int log_p){
68 #ifdef IEEE_754
69  if (ISNAN(p) || ISNAN(shape))
70  return p + shape + 1.0;
71 #endif
72  if (shape <= 0) return R_NaN;
73 
75 
76  return ::pow(- R_DT_Clog(p), 1./shape);
77 }
78 
79 } // stats
80 } // Rcpp
81 
83 RCPP_DPQ_2(weibull,::Rf_dweibull,::Rf_pweibull,::Rf_qweibull)
84 
85 #endif
86 
#define RCPP_DPQ_2(__NAME__, __D__, __P__, __Q__)
Definition: dpq.h:363
#define RCPP_DPQ_1(__NAME__, __D__, __P__, __Q__)
Definition: dpq.h:340
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 dweibull_1(double x, double shape, int give_log)
Definition: weibull.h:30
double pweibull_1(double x, double shape, int lower_tail, int log_p)
Definition: weibull.h:49
double qweibull_1(double p, double shape, int lower_tail, int log_p)
Definition: weibull.h:67
Rcpp API.
Definition: algo.h:28
sugar::Pow< RTYPE, NA, T, EXPONENT_TYPE > pow(const VectorBase< RTYPE, NA, T > &t, EXPONENT_TYPE exponent)
Definition: pow.h:79
#define R_DT_0
Definition: macros.h:29
#define R_D__0
Definition: macros.h:27
#define R_Q_P01_boundaries(p, _LEFT_, _RIGHT_)
Definition: macros.h:84
#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
#define ML_POSINF
Definition: stats.h:27