Rcpp Version 0.12.12
lnorm.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 // lnorm.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__lnorm_h
25 #define Rcpp__stats__lnorm_h
26 
27 namespace Rcpp {
28 namespace stats {
29 
30 inline double dlnorm_0(double x, int log_p){
31  double y;
32 
33 #ifdef IEEE_754
34  if (ISNAN(x))
35  return x + 1.0;
36 #endif
37 
38  if (x <= 0) return R_D__0;
39 
40  y = ::log(x);
41  return (log_p ?
42  -(M_LN_SQRT_2PI + 0.5 * y * y + ::log(x)) :
43  M_1_SQRT_2PI * ::exp(-0.5 * y * y) / x);
44  /* M_1_SQRT_2PI = 1 / sqrt(2 * pi) */
45 }
46 
47 inline double dlnorm_1(double x, double meanlog, int log_p){
48  double y;
49 
50 #ifdef IEEE_754
51  if (ISNAN(x) || ISNAN(meanlog))
52  return x + meanlog + 1.0;
53 #endif
54 
55  if (x <= 0) return R_D__0;
56 
57  y = (::log(x) - meanlog);
58  return (log_p ?
59  -(M_LN_SQRT_2PI + 0.5 * y * y + ::log(x)) :
60  M_1_SQRT_2PI * ::exp(-0.5 * y * y) / x);
61  /* M_1_SQRT_2PI = 1 / sqrt(2 * pi) */
62 
63 }
64 
65 inline double plnorm_0(double x, int lower_tail, int log_p){
66 #ifdef IEEE_754
67  if (ISNAN(x))
68  return x + 1.0;
69 #endif
70 
71  if (x > 0)
72  return Rcpp::stats::pnorm_0(::log(x), lower_tail, log_p);
73  return R_DT_0;
74 }
75 
76 inline double plnorm_1(double x, double meanlog, int lower_tail, int log_p) {
77 #ifdef IEEE_754
78  if (ISNAN(x) || ISNAN(meanlog))
79  return x + meanlog + 1.0;
80 #endif
81 
82  if (x > 0)
83  return Rcpp::stats::pnorm_1(::log(x), meanlog, lower_tail, log_p);
84  return R_DT_0;
85 }
86 
87 inline double qlnorm_0(double p, int lower_tail, int log_p){
88 #ifdef IEEE_754
89  if (ISNAN(p))
90  return p + 1.0;
91 #endif
93 
94  return ::exp(::Rf_qnorm5(p, 0.0, 1.0, lower_tail, log_p));
95 }
96 
97 inline double qlnorm_1(double p, double meanlog, int lower_tail, int log_p){
98 #ifdef IEEE_754
99  if (ISNAN(p) || ISNAN(meanlog))
100  return p + meanlog + 1.0;
101 #endif
103 
104  return ::exp(::Rf_qnorm5(p, meanlog, 1.0, lower_tail, log_p));
105 }
106 
107 } // stats
108 } // Rcpp
109 
112 RCPP_DPQ_2(lnorm,::Rf_dlnorm,::Rf_plnorm,::Rf_qlnorm)
113 
114 #endif
115 
double pnorm_1(double x, double mu, int lower_tail, int log_p)
Definition: norm.h:56
double dlnorm_0(double x, int log_p)
Definition: lnorm.h:30
double plnorm_0(double x, int lower_tail, int log_p)
Definition: lnorm.h:65
void exp(InputIterator begin, InputIterator end, OutputIterator out)
Definition: algorithm.h:474
double pnorm_0(double x, int lower_tail, int log_p)
Definition: norm.h:78
double qlnorm_0(double p, int lower_tail, int log_p)
Definition: lnorm.h:87
#define ML_POSINF
Definition: stats.h:27
#define R_Q_P01_boundaries(p, _LEFT_, _RIGHT_)
Definition: macros.h:84
double plnorm_1(double x, double meanlog, int lower_tail, int log_p)
Definition: lnorm.h:76
#define RCPP_DPQ_1(__NAME__, __D__, __P__, __Q__)
Definition: dpq.h:340
#define R_DT_0
Definition: macros.h:29
double qlnorm_1(double p, double meanlog, int lower_tail, int log_p)
Definition: lnorm.h:97
#define RCPP_DPQ_2(__NAME__, __D__, __P__, __Q__)
Definition: dpq.h:363
void log(InputIterator begin, InputIterator end, OutputIterator out)
Definition: algorithm.h:469
#define R_D__0
Definition: macros.h:27
Rcpp API.
Definition: algo.h:28
#define RCPP_DPQ_0(__NAME__, __D__, __P__, __Q__)
Definition: dpq.h:318
double dlnorm_1(double x, double meanlog, int log_p)
Definition: lnorm.h:47