From 07b85b6dcc6e84f42da3579b65692a3d4ba04e38 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Thu, 12 Mar 2020 11:44:43 -0700 Subject: uhd: math: Add linear_interp() This lets you linearly interpolate between two points. --- host/tests/math_test.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'host/tests') diff --git a/host/tests/math_test.cpp b/host/tests/math_test.cpp index 4714f6625..bff6fc16f 100644 --- a/host/tests/math_test.cpp +++ b/host/tests/math_test.cpp @@ -6,7 +6,6 @@ // #include -#include #include BOOST_AUTO_TEST_CASE(test_lcm) @@ -18,3 +17,13 @@ BOOST_AUTO_TEST_CASE(test_gcd) { BOOST_CHECK_EQUAL(uhd::math::gcd(6, 15), 3); } + +BOOST_AUTO_TEST_CASE(test_interp) +{ + const double x0 = 1.0, x1 = 2.0; + const double y0 = 2.0, y1 = 4.0; + const double x = 1.5; + const double y_exp = 3.0; + + BOOST_CHECK_EQUAL(uhd::math::linear_interp(x, x0, y0, x1, y1), y_exp); +} -- cgit v1.2.3