diff --git a/src/lib/mathlib/math/Functions.hpp b/src/lib/mathlib/math/Functions.hpp index b81459ff67..7fb54442d9 100644 --- a/src/lib/mathlib/math/Functions.hpp +++ b/src/lib/mathlib/math/Functions.hpp @@ -160,8 +160,8 @@ const T interpolate(const T &value, const T &x_low, const T &x_high, const T &y_ } else { /* linear function between the two points */ T a = (y_high - y_low) / (x_high - x_low); - T b = y_low - a * x_low; - return a * value + b; + T b = y_low - (a * x_low); + return (a * value) + b; } } diff --git a/src/lib/mathlib/math/FunctionsTest.cpp b/src/lib/mathlib/math/FunctionsTest.cpp index 8788651f26..ebc4e49670 100644 --- a/src/lib/mathlib/math/FunctionsTest.cpp +++ b/src/lib/mathlib/math/FunctionsTest.cpp @@ -172,7 +172,7 @@ TEST(FunctionsTest, interpolate) // corner case when y_low > y_high EXPECT_FLOAT_EQ(interpolate(1.5f, 1.f, 2.f, 6.f, 4.f), 5.f); - // corner case when x_low == x_high == y_low == y_high == 0.f + // corner case when x_low == x_high == y_low == y_high == 0.f EXPECT_FLOAT_EQ(interpolate(0.f, 0.f, 0.f, 0.f, 0.f), 0.f); }