Commit 01249535 authored by Florian Fischer's avatar Florian Fischer
Browse files

introduce "type-safe" multiplication (*, uint64_t, double) -> uint64_t

parent ec4b3482
Pipeline #66609 passed with stage
in 1 minute and 58 seconds
......@@ -40,22 +40,24 @@ uint64_t calc_var(const uint64_t* data, size_t size, uint64_t mean) {
return sum / size;
}
static uint64_t mul_u64_dbl(uint64_t ul, double dbl) { return (uint64_t)((double)ul * dbl); }
// Using nearest rank
// https://en.wikipedia.org/wiki/Percentile#The_nearest-rank_method
uint64_t get_percentile(const uint64_t* data, size_t size, float prctl) {
uint64_t get_percentile(const uint64_t* data, size_t size, double prctl) {
check_saple_size(size);
if (prctl < 0 || prctl > 1) errx(EXIT_FAILURE, "prctl must be in [0,1]");
size_t n = prctl * size;
size_t n = mul_u64_dbl(size, prctl);
return data[n];
}
uint64_t get_upper_whisker(const uint64_t* data, size_t size, uintptr_t iqr) {
check_saple_size(size);
const float upper_prctl = 0.75;
size_t n = upper_prctl * size;
const uint64_t threshold = data[n] + (1.5 * iqr);
const double upper_prctl = 0.75;
size_t n = mul_u64_dbl(size, upper_prctl);
const uint64_t threshold = data[n] + mul_u64_dbl(iqr, 1.5);
while (data[n] < threshold && n < size) {
++n;
}
......@@ -64,9 +66,9 @@ uint64_t get_upper_whisker(const uint64_t* data, size_t size, uintptr_t iqr) {
uint64_t get_lower_whisker(const uint64_t* data, size_t size, uintptr_t iqr) {
check_saple_size(size);
const float lower_prctl = 0.25;
size_t n = lower_prctl * size;
const uint64_t threshold = data[n] - (1.5 * iqr);
const double lower_prctl = 0.25;
size_t n = mul_u64_dbl(size, lower_prctl);
const uint64_t threshold = data[n] - mul_u64_dbl(iqr, 1.5);
while (data[n] > threshold && n > 0) {
--n;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment