Skip to content

Commit

Permalink
Merge pull request #1480 from quickwit-oss/overflow_issue
Browse files Browse the repository at this point in the history
fix overflow issue in interpolation
  • Loading branch information
PSeitz committed Aug 28, 2022
2 parents 6f563b1 + 3984caf commit 5d43675
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions fastfield_codecs/src/lib.rs
Expand Up @@ -195,6 +195,11 @@ mod tests {
data_and_names.push((vec![5, 50, 3, 13, 1, 1000, 35], "rand small"));
data_and_names.push((vec![10], "single value"));

data_and_names.push((
vec![1572656989877777, 1170935903116329, 720575940379279, 0],
"overflow error",
));

data_and_names
}

Expand Down
11 changes: 9 additions & 2 deletions fastfield_codecs/src/linear.rs
Expand Up @@ -115,9 +115,9 @@ fn diff(val1: u64, val2: u64) -> f64 {
#[inline]
pub fn get_calculated_value(first_val: u64, pos: u64, slope: f32) -> u64 {
if slope < 0.0 {
first_val - (pos as f32 * -slope) as u64
first_val.saturating_sub((pos as f32 * -slope) as u64)
} else {
first_val + (pos as f32 * slope) as u64
first_val.saturating_add((pos as f32 * slope) as u64)
}
}

Expand Down Expand Up @@ -314,6 +314,13 @@ mod tests {

create_and_validate(&data, "large amplitude");
}

#[test]
fn overflow_error_test() {
let data = vec![1572656989877777, 1170935903116329, 720575940379279, 0];
create_and_validate(&data, "overflow test");
}

#[test]
fn linear_interpol_fast_concave_data() {
let data = vec![0, 1, 2, 5, 8, 10, 20, 50];
Expand Down

0 comments on commit 5d43675

Please sign in to comment.