30 static double *data = NULL;
31 static long last_n = 0;
37 data =
trealloc(data,
sizeof(*data) * n);
40 for (i = 0; i < n; i++)
57 static double *data = NULL;
58 static long last_n = 0;
61 if (n <= 0 || percentile < 0 || percentile > 100)
64 data =
trealloc(data,
sizeof(*data) * n);
67 for (i = 0; i < n; i++)
70 *value = data[(long)((n - 1) * (percentile / 100.0))];
85 static double *data = NULL;
86 static long last_n = 0;
89 if (n <= 0 || positions <= 0)
92 data =
trealloc(data,
sizeof(*data) * n);
95 memcpy((
char *)data, (
char *)x,
sizeof(*x) * n);
97 for (ip = 0; ip < positions; ip++)
98 position[ip] = data[(
long)((n - 1) * (percent[ip] / 100.0))];
114 static double *data = NULL;
115 static int64_t last_n = 0;
116 int64_t ip, jp, count;
118 if (n <= 0 || positions <= 0)
120 for (ip=count=0; ip<n; ip++)
123 if (count > last_n) {
124 data =
trealloc(data,
sizeof(*data) * count);
127 for (ip=jp=0; ip<n; ip++)
131 for (ip = 0; ip < positions; ip++)
132 position[ip] = data[(
long)((count - 1) * (percent[ip] / 100.0))];
151 for (i = sum = 0; i < n; i++)
172 *value = (min + max) / 2;
189 double *hist, *cdf, xMin, xMax, xCenter, xRange;
191 if (bins < 2 || positions <= 0 || n <= 0)
193 if (!(hist = malloc(
sizeof(*hist) * bins)))
196 xCenter = (xMax + xMin) / 2;
197 xRange = (xMax - xMin) * (1 + 1. / bins) / 2;
198 xMin = xCenter - xRange;
199 xMax = xCenter + xRange;
203 for (i = 1; i < bins; i++)
204 cdf[i] += cdf[i - 1];
205 for (i = 0; i < bins; i++)
206 cdf[i] /= cdf[bins - 1];
208 for (j = 0; j < positions; j++) {
209 for (i = k = 0; i < bins; i++) {
210 if (cdf[i] < percent[j] / 100.0)
215 position[j] = xMin + (k * (xMax - xMin)) / bins;
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
int find_min_max(double *min, double *max, double *list, int64_t n)
Finds the minimum and maximum values in a list of doubles.
long make_histogram(double *hist, long n_bins, double lo, double hi, double *data, int64_t n_pts, long new_start)
Compiles a histogram from data points.
int double_cmpasc(const void *a, const void *b)
Compare two doubles in ascending order.