Skip to content
Snippets Groups Projects
Commit e422044f authored by Rahil Doshi's avatar Rahil Doshi
Browse files

Refactor interpolate_binary_search_cpp.h

parent 1d67844f
No related branches found
No related tags found
No related merge requests found
Pipeline #77631 passed
...@@ -33,12 +33,13 @@ double interpolate_binary_search_cpp( ...@@ -33,12 +33,13 @@ double interpolate_binary_search_cpp(
} }
} }
// Linear interpolation // Get interpolation points
const double x1 = arrs.y_bs[right]; const double x1 = arrs.x_bs[left];
const double x2 = arrs.y_bs[left]; const double x2 = arrs.x_bs[right];
const double y1 = arrs.x_bs[right]; const double y1 = arrs.y_bs[left];
const double y2 = arrs.x_bs[left]; const double y2 = arrs.y_bs[right];
const double slope = (y2 - y1) / (x2 - x1); // Linear interpolation
return y1 + slope * (y_target - x1); const double inv_slope = (x2 - x1) / (y2 - y1);
return x1 + inv_slope * (y_target - y1);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment