-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathrt.h
More file actions
31 lines (22 loc) · 705 Bytes
/
rt.h
File metadata and controls
31 lines (22 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef Rcpp__stats__random_rt_h
#define Rcpp__stats__random_rt_h
namespace Rcpp {
namespace stats {
class TGenerator : public ::Rcpp::Generator<double> {
public:
TGenerator( double df_ ) : df(df_), df_2(df_/2.0) {}
inline double operator()() const {
/* Some compilers (including MW6) evaluated this from right to left
return norm_rand() / sqrt(rchisq(df) / df); */
double num = norm_rand();
// return num / sqrt(rchisq(df) / df);
// replaced by the followoing line to skip the test in
// rchisq because we already know
return num / ::sqrt( ::Rf_rgamma(df_2, 2.0) / df);
}
private:
double df, df_2 ;
} ;
} // stats
} // Rcpp
#endif