7float chispre(
float *x,
float *p,
float *f,
long q) {
8 mfunnamep(
"float chispre(float *x, float *p, float *f, long q)");
11 for (
long i = 0; i < q; ++i) {
13 r += p[i] * (x[i + 1] - x[i]);
17 for (
long i = 0; i < q; ++i)
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";
68 mfunnamep(
"double chispre(DynLinArr< double >& f, int s_allow_zero_f=0)");
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(DynLinArr< double >& "
79 "f, int s_allow_zero_f)\n";
88 for (
int i = 0; i < q; ++i)
95 "double chisran(double flat_random_number, DynLinArr < double > f)");
101 if (flat_random_number == 0.0) {
102 for (
long n = 0; n < q; ++n) {
103 if (f[n] > 0.0)
return double(n);
106 if (flat_random_number == 1.0) {
107 for (
long n = q - 1; n >= 0; n--) {
108 if (f[n] < 1.0)
return double(n + 1);
111 if (flat_random_number <= f[0]) {
112 return flat_random_number / f[0];
117 while (nr - nl > 1) {
119 if (flat_random_number < f[nc]) {
125 const double xl = double(nl + 1);
126 const double xr = double(nr + 1);
127 const double yl = f[nl];
128 const double yr = f[nr];
129 const double a = (xr - xl) / (yr - yl);
135 return a * (flat_random_number - yl) + b;
140 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)