8float chispre(
float *x,
float *p,
float *f,
long q) {
9 mfunnamep(
"float chispre(float *x, float *p, float *f, long q)");
12 for (
long i = 0; i < q; ++i) {
14 r += p[i] * (x[i + 1] - x[i]);
18 for (
long i = 0; i < q; ++i) f[i] /= r;
22float chisran(
float flat_random_number,
float *x,
float *f,
long q) {
24 "float chisran(float flat_random_number, float *x, float *f, long q)");
27 if (flat_random_number == 0.0) {
28 for (
long n = 0; n < q; ++n) {
29 if (f[n] > 0.0)
return x[n];
32 if (flat_random_number == 1.0) {
33 for (
long n = q - 1; n >= 0; n--) {
34 if (f[n] < 1.0)
return x[n + 1];
37 if (flat_random_number <= f[0]) {
38 return flat_random_number / f[0];
45 if (flat_random_number < f[nc]) {
51 const float xl = x[nl + 1];
52 const float xr = x[nr + 1];
53 const float yl = f[nl];
54 const float yr = f[nr];
55 const float a = (xr - xl) / (yr - yl);
57 return a * (flat_random_number - yl) + b;
62 mcerr <<
"should never happen\n";
67double chispre(std::vector<double> &f,
int s_allow_zero_f) {
68 mfunnamep(
"double chispre(vector<double>& f, int s_allow_zero_f=0)");
70 const long q = f.size();
73 for (
int i = 0; i < q; ++i) {
74 if (s_allow_zero_f == 0) {
78 mcout <<
"Warning: f[i] < 0.0 in double chispre(vector<double>& f, "
79 "int s_allow_zero_f)\n";
88 for (
int i = 0; i < q; ++i) f[i] /= r;
92double chisran(
double flat_random_number,
const std::vector<double> &f) {
93 mfunnamep(
"double chisran(double flat_random_number, vector<double> f)");
94 const long q = f.size();
97 if (flat_random_number == 0.0) {
98 for (
long n = 0; n < q; ++n) {
99 if (f[n] > 0.0)
return double(n);
102 if (flat_random_number == 1.0) {
103 for (
long n = q - 1; n >= 0; n--) {
104 if (f[n] < 1.0)
return double(n + 1);
107 if (flat_random_number <= f[0]) {
108 return flat_random_number / f[0];
113 while (nr - nl > 1) {
115 if (flat_random_number < f[nc]) {
121 const double xl = double(nl + 1);
122 const double xr = double(nr + 1);
123 const double yl = f[nl];
124 const double yr = f[nr];
125 const double a = (xr - xl) / (yr - yl);
131 return a * (flat_random_number - yl) + b;
136 mcerr <<
"should never happen\n";
#define check_econd21(a, sign1_b1_sign0, sign2_b2, stream)
#define check_econd11(a, signb, stream)
#define check_econd11a(a, signb, add, stream)
#define mfunnamep(string)
float chispre(float *x, float *p, float *f, long q)
float chisran(float flat_random_number, float *x, float *f, long q)
#define Iprint2n(file, name1, name2)