C++

'std::lerp' Is Not a Member of 'std' Fix

std::lerp lives in one header, <cmath> - not in <numeric>, where its C++20 sibling std::midpoint lives and where an interpolation function from that family is expected. On this library version a handful of headers rescue it by accident: in the sweep probed here, covering all 106 standard headers in the library's header set, <ccomplex>, <complex>, <ctgmath>, <random>, and <valarray> pull the name in on the side, and the textbook combination of <iostream> and <vector> does not. This error offers no note at all - no header is named, no include is suggested - so the fix has to come from knowing the name's home. This guide pins down the one failing shape, the five transitive rescues, and the one include that fixes the error by specification.

Written December 2, 2026 · Tested with GCC 13.3.0 · 20 min read

By the end of this guide
  • The error: the include is missing, in a lean file
  • The textbook version fails too - with no note to follow
  • Neighboring headers: 100 fail the same way, and five rescue it
  • The fix

Written December 2, 2026

Tested with GCC 13.3.0

What this guide is

std::lerp is a function defined in the header <cmath>. It computes the linear interpolation between a and b when the parameter t is inside [0, 1), and the linear extrapolation otherwise: the result of a + t(b - a), with accounting for floating-point calculation imprecision. The library provides overloads of the function for the floating-point types, and additional overloads are provided for all other combinations of arithmetic types, where the arguments are converted to a common floating-point type. The function has existed since C++20 and is constexpr and noexcept from its introduction. When both a and b are finite, these properties are guaranteed: if t is 0, the result is equal to a; if t is 1, the result is equal to b; if t is between 0 and 1 inclusive, the result is finite; if t is finite and a equals b, the result is equal to a; and the function is monotonic - as t grows, the result moves in the direction from a to b and never against it.

Because the function lives in one specific header, 'lerp' is not a member of 'std' has one common cause:

  • The #include <cmath> line is missing, and no other header in the file pulls the name in transitively. For this error, in the contexts probed here, GCC prints no suggestion tail on the error line, no help lines - and no note lines at all. The fix has to come from the name's home header, not from the diagnostic.

This name also has a second cause: std::lerp is a C++20 name, so a file that includes <cmath> and is compiled as C++17 gets the identical error - shown in the versions section below. What makes the error worth separating from its closest relative is where the name is expected to live. std::lerp shares its feature-test macro and its C++20 introduction with std::midpoint, so the first header reached for is <numeric>, the midpoint header - and in the sweep probed here <numeric> fails, with the same bare error as every other failing header. The sweep covers every one of the 106 standard headers in this library's header set, compiled as the only header in the program, and the outcome splits only two ways - the one uniform failure, or a rescue - and the rescue set has exactly six entries: <cmath> itself, <ccomplex>, <complex>, <ctgmath>, <random>, and <valarray>. Its sibling in this family - std::midpoint - has its own guide and is linked at the end, not re-taught here.

The error: the include is missing, in a lean file

This program returns success if the interpolation of 0.0 and 10.0 at t equal to 0.5 is 5.0, but includes only <limits>:

C++
#include <limits>
int main() {
    return std::lerp(0.0, 10.0, 0.5) == 5.0 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:3:17: error: 'lerp' is not a member of 'std'
    3 |     return std::lerp(0.0, 10.0, 0.5) == 5.0 ? 0 : 1;
      |                 ^~~~

That is the whole output: one plain error line, and nothing after it. No suggestion tail rides on the error line itself, there are no note lines, and there are no help lines. The same program with no include at all fails the same way, just as bare:

C++
int main() {
    return std::lerp(0.0, 10.0, 0.5) == 5.0 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 n_none.cpp -o n_none_prog
n_none.cpp: In function 'int main()':
n_none.cpp:2:17: error: 'lerp' is not a member of 'std'
    2 |     return std::lerp(0.0, 10.0, 0.5) == 5.0 ? 0 : 1;
      |                 ^~~~

The textbook version fails too - with no note to follow

The version most often written first - print the interpolation of two values held in a vector, with std::cout - gets the same error, without <cmath>, and the same silence after it:

C++
#include <iostream>
#include <vector>
int main() {
    std::vector<double> v = {0.0, 10.0};
    std::cout << std::lerp(v[0], v[1], 0.5) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:5:23: error: 'lerp' is not a member of 'std'
    5 |     std::cout << std::lerp(v[0], v[1], 0.5) << "\n";
      |                       ^~~~

What happened: on this library version, neither <vector> nor <iostream> pulls this name in transitively, so the call fails in a textbook file just as it does in a lean one - and there is no note pointing anywhere. In the sweep probed here, the only headers that rescue std::lerp besides <cmath> itself are <ccomplex>, <complex>, <ctgmath>, <random>, and <valarray>, and those rescues are properties of this library version, not rules of the language. A program that uses std::lerp includes <cmath>, whether or not it happens to compile without it.

Neighboring headers: 100 fail the same way, and five rescue it

In a sweep where each of the 106 standard headers in this library's header set was compiled as the only header in a program that returns success if the interpolation of 0.0 and 10.0 at t equal to 0.5 is 5.0, the outcome splits by compile result two ways. Every diagnostic component was classified separately - the error line, any suggestion tail on it, any note lines, and any help lines. These 100 headers all fail with the plain is not a member of 'std' error line, no suggestion tail on that line, no note lines at all, and no help lines:

  • <algorithm>
  • <any>
  • <array>
  • <atomic>
  • <barrier>
  • <bit>
  • <bitset>
  • <cassert>
  • <cctype>
  • <cerrno>
  • <cfenv>
  • <cfloat>
  • <charconv>
  • <chrono>
  • <cinttypes>
  • <ciso646>
  • <climits>
  • <clocale>
  • <codecvt>
  • <compare>
  • <concepts>
  • <condition_variable>
  • <coroutine>
  • <csetjmp>
  • <csignal>
  • <cstdalign>
  • <cstdarg>
  • <cstdbool>
  • <cstddef>
  • <cstdint>
  • <cstdio>
  • <cstdlib>
  • <cstring>
  • <ctime>
  • <cuchar>
  • <cwchar>
  • <cwctype>
  • <deque>
  • <exception>
  • <execution>
  • <expected>
  • <filesystem>
  • <format>
  • <forward_list>
  • <fstream>
  • <functional>
  • <future>
  • <initializer_list>
  • <iomanip>
  • <ios>
  • <iosfwd>
  • <iostream>
  • <istream>
  • <iterator>
  • <latch>
  • <limits>
  • <list>
  • <locale>
  • <map>
  • <memory>
  • <memory_resource>
  • <mutex>
  • <new>
  • <numbers>
  • <numeric>
  • <optional>
  • <ostream>
  • <queue>
  • <ranges>
  • <ratio>
  • <regex>
  • <scoped_allocator>
  • <semaphore>
  • <set>
  • <shared_mutex>
  • <source_location>
  • <span>
  • <spanstream>
  • <sstream>
  • <stack>
  • <stacktrace>
  • <stdexcept>
  • <stdfloat>
  • <stop_token>
  • <streambuf>
  • <string>
  • <string_view>
  • <syncstream>
  • <system_error>
  • <thread>
  • <tuple>
  • <type_traits>
  • <typeindex>
  • <typeinfo>
  • <unordered_map>
  • <unordered_set>
  • <utility>
  • <variant>
  • <vector>
  • <version>

A file with no include at all fails the same way, with the same absence of notes. No failing sole header prints a suggestion tail, a note line, or a help line in this sweep.

A sole <numeric> file shows the failing shape in full - and <numeric> is the header this call is most often expected in, since its sibling std::midpoint lives there. It is not there. Neither is it in <algorithm>:

C++
#include <numeric>
int main() {
    return std::lerp(0.0, 10.0, 0.5) == 5.0 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 v_numeric.cpp -o v_numeric_prog
v_numeric.cpp: In function 'int main()':
v_numeric.cpp:3:17: error: 'lerp' is not a member of 'std'
    3 |     return std::lerp(0.0, 10.0, 0.5) == 5.0 ? 0 : 1;
      |                 ^~~~
C++
#include <algorithm>
int main() {
    return std::lerp(0.0, 10.0, 0.5) == 5.0 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 v_algorithm.cpp -o v_algorithm_prog
v_algorithm.cpp: In function 'int main()':
v_algorithm.cpp:3:17: error: 'lerp' is not a member of 'std'
    3 |     return std::lerp(0.0, 10.0, 0.5) == 5.0 ? 0 : 1;
      |                 ^~~~

And these headers rescue the program - it compiles and runs with no <cmath> anywhere in the file:

  • <ccomplex>
  • <cmath>
  • <complex>
  • <ctgmath>
  • <random>
  • <valarray>

Two contrasts with the neighboring sweeps are worth holding on to. First, there is no note class, no suggestion class, and no link-failure shape in this sweep: every failing sole header fails at compile time with the same bare error. Second, the rescue set is wider than the one std::midpoint produced, and it has a visible shape: apart from <random>, the rescues are the headers built around <cmath> itself - the complex-number headers and <valarray> - which is consistent with a name whose home is a math header, not a numeric-algorithms header. <cmath> - the home header - is on the rescue list by definition, not by transitivity, and the other five rescues are this library version's behavior, not a guarantee.

The fix

Add the header:

C++
#include <cmath>
#include <iostream>
int main() {
    std::cout << std::lerp(0.0, 10.0, 0.0) << " "
              << std::lerp(0.0, 10.0, 1.0) << " "
              << std::lerp(0.0, 10.0, 0.5) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
0 10 5

One include, <cmath>, declares the function - and the three calls already show the documented endpoint rule. At t equal to 0 the result is 0, the first argument exactly. At t equal to 1 the result is 10, the second argument exactly. At t equal to 0.5 the result is 5, halfway between them. Those endpoint equalities are guaranteed when both arguments are finite - they are properties of the function, not rounding luck.

The fixed programs: extrapolation, large values, and the special values

Trap
The parameter is not clamped to the interval. A t outside [0, 1] extrapolates along the same line, and the special values behave position by position, not by one blanket rule:
C++
#include <cmath>
#include <iostream>
#include <limits>
int main() {
    double inf = std::numeric_limits<double>::infinity();
    double nan = std::numeric_limits<double>::quiet_NaN();
    std::cout << std::lerp(0.0, 10.0, 2.0) << " "
              << std::lerp(0.0, 10.0, -1.0) << " "
              << std::lerp(1e308, 1e308, 0.5) << " "
              << std::lerp(inf, inf, 0.5) << " "
              << std::lerp(nan, 1.0, 0.5) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 k_extra.cpp -o k_extra_prog
$ ./k_extra_prog
20 -10 1e+308 inf 1

Read in order: at t equal to 2.0 the result is 20, one full interval past the second argument, and at t equal to -1.0 the result is -10, one full interval before the first - extrapolation, in both directions, with no clamping. The call with both arguments equal to 1e308 at t equal to 0.5 reports 1e+308, the value itself, as the documented rule for finite equal arguments requires. The call with infinity as both arguments reports inf. And the last call is the surprise in this program: a quiet NaN as the first argument, with 1.0 as the second, reports 1 - not a NaN.

A second program moves the special values through every position, because the first program's last result does not generalize:

C++
#include <cmath>
#include <iostream>
#include <limits>
int main() {
    double nan = std::numeric_limits<double>::quiet_NaN();
    double inf = std::numeric_limits<double>::infinity();
    std::cout << std::lerp(nan, 1.0, 0.5) << " "
              << std::lerp(1.0, nan, 0.5) << " "
              << std::lerp(0.0, 10.0, nan) << " "
              << std::lerp(inf, 1.0, 0.5) << " "
              << std::lerp(1.0, inf, 0.5) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 k_nan.cpp -o k_nan_prog
$ ./k_nan_prog
1 nan nan 1 inf

Read in order: a quiet NaN as the first argument again reports 1; a quiet NaN as the second argument reports nan; a quiet NaN as t reports nan; infinity as the first argument, with 1.0 as the second, reports 1; and infinity as the second argument reports inf. The documented guarantees quoted in this guide cover the case where the first two arguments are finite - outside that case, the results here are what this library's implementation computes, position by position, and code that needs a specific NaN or infinity outcome has to state which position it means, not appeal to a general propagation rule.

Integer, mixed, and bool arguments: the additional overloads at work

std::lerp does not share std::midpoint's one-type rule. Additional overloads are provided for combinations of arithmetic types, so a call whose arguments are all integers compiles as it stands - the arguments are converted to a common floating-point type, which for integer arguments is double:

C++
#include <cmath>
#include <iostream>
int main() {
    std::cout << std::lerp(0, 10, 0.5) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 g_int.cpp -o g_int_prog
$ ./g_int_prog
5

A mixed call compiles the same way - an int, a double, and a float in one call, converted to their common floating-point type before the computation:

C++
#include <cmath>
#include <iostream>
int main() {
    std::cout << std::lerp(0, 10.0, 0.5f) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 g_mixed.cpp -o g_mixed_prog
$ ./g_mixed_prog
5

Even a bool call compiles, which separates this function from both of its neighbors: the program below returns success only if the call over true, false, and true equals 1.0, and it compiles and runs - exiting with status 1, because the converted computation, 1 plus 1 times (0 minus 1), is 0, not 1.0:

C++
#include <cmath>
int main() {
    return std::lerp(true, false, true) == 1.0 ? 0 : 1;
}

So mixed-type and bool failures are not shapes this error produces: when a std::lerp call fails with is not a member of 'std', the cause is the header or the standard, not the argument types. Convert arguments explicitly when the common type matters to the result - the conversion the overloads perform is silent about which floating-point type was picked.

Versions: C++20 to call it, constexpr from the start, and no note either way

The call itself needs C++20, and std::lerp is constexpr from its introduction, so a static_assert over the call already compiles under C++20 - including the two endpoint cases, which are constant-evaluated with the same exactness rule:

C++
#include <cmath>
int main() {
    static_assert(std::lerp(0.0, 10.0, 0.0) == 0.0);
    static_assert(std::lerp(0.0, 10.0, 1.0) == 10.0);
    static_assert(std::lerp(0.0, 10.0, 0.5) == 5.0);
    return 0;
}
Command
$ g++ -std=c++20 c_constexpr20.cpp -o c_constexpr20_prog
$ ./c_constexpr20_prog

Under C++17 the name is not there at all, even with <cmath> included - and here this error's silence costs the most, because the output is identical to the missing-include case: the same plain error, and no version note to separate a too-old standard from a missing header:

Terminal
$ g++ -std=c++17 c_lerp17.cpp -o c_lerp17_prog
c_lerp17.cpp: In function 'int main()':
c_lerp17.cpp:3:17: error: 'lerp' is not a member of 'std'
    3 |     return std::lerp(0.0, 10.0, 0.5) == 5.0 ? 0 : 1;
      |                 ^~~~

When the include is already in the file and the error persists, the standard flag is the next thing to check - the diagnostic will not tell you.

The neighboring name: midpoint is not in

The name std::lerp is used alongside does not share its home header. std::midpoint - the midpoint function, also C++20 and constexpr - lives in <numeric>, and it fails in a file whose only include is <cmath> with its own plain error and the same absence of a note. It is shown here only as a neighbor, not re-taught:

C++
#include <cmath>
int main() {
    return std::midpoint(0, 10) == 5 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 b_midpoint_cmath.cpp -o b_midpoint_cmath_prog
b_midpoint_cmath.cpp: In function 'int main()':
b_midpoint_cmath.cpp:3:17: error: 'midpoint' is not a member of 'std'
    3 |     return std::midpoint(0, 10) == 5 ? 0 : 1;
      |                 ^~~~~~~~

The neighboring names, fixed

The two names together take two headers - there is no one header that covers both. The fixed neighbor program reports 5 5: the interpolation call is 5, and the midpoint call is 5:

C++
#include <cmath>
#include <iostream>
#include <numeric>
int main() {
    std::cout << std::lerp(0.0, 10.0, 0.5) << " "
              << std::midpoint(0, 10) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 b_neighbours_fixed.cpp -o b_neighbours_fixed_prog
$ ./b_neighbours_fixed_prog
5 5

The split is the whole lesson of this family: lerp takes <cmath> and midpoint takes <numeric>, the two functions were introduced together in C++20 under one shared feature-test macro, and a file that uses both and lacks either header gets the same plain error with the name swapped.

A different wording - and no argument-dependent rescue for this name

Including <cmath> is not the only half of the name. This program includes the header, drops the std:: qualifier, and passes plain doubles:

C++
#include <cmath>
int main() {
    return lerp(0.0, 10.0, 0.5) == 5.0 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 g_unqualified.cpp -o g_unqualified_prog
g_unqualified.cpp: In function 'int main()':
g_unqualified.cpp:3:12: error: 'lerp' was not declared in this scope; did you mean 'std::lerp'?
    3 |     return lerp(0.0, 10.0, 0.5) == 5.0 ? 0 : 1;
      |            ^~~~
      |            std::lerp
In file included from g_unqualified.cpp:1:
/usr/include/c++/13/cmath:3655:5: note: 'std::lerp' declared here
 3655 |     lerp(_Tp __x, _Up __y, _Vp __z) noexcept
      |     ^~~~

That wording - was not declared in this scope, with did you mean 'std::lerp'? on the error line and a note pointing at a declaration - is a different defect with a different fix: the header is present, the qualifier is not. Qualify the name as std::lerp; adding includes does not bring the name out of namespace std. Doubles are fundamental types and have no associated namespace, so argument-dependent lookup has nothing to find the name from in this call.

The exact rule

  • std::lerp is declared by #include <cmath>, and by no other header by rule. In the sweep probed here, every one of the other 100 headers in the library's header set - among them <algorithm>, <iostream>, <numeric>, <vector>, <utility>, and <version> - does not declare it, and neither does a file with no include at all.
  • 'lerp' is not a member of 'std' means the <cmath> include is missing and nothing else in the file pulled the name in - or, under a standard before C++20, that the name does not exist yet in that standard. In every context probed here, GCC prints no suggestion tail on the error line, no note lines, and no help lines for this name - the missing-include case and the too-old-standard case print identically, and only the file's own include list and standard flag separate them.
  • In the sweep probed here, the split is two-way: a sole header either fails with that one uniform bare shape, or rescues the program. No probed sole header produces a note class, a suggestion class, or a declared-but-not-defined link-failure shape for this name.
  • In the sweep probed here, five headers besides <cmath> rescue std::lerp transitively - <ccomplex>, <complex>, <ctgmath>, <random>, and <valarray> - so a file whose only include is one of those compiles and runs the call without <cmath>. That is this library version's behavior, not a guarantee - in the probed set, no header besides <cmath> is required to pull std::lerp in.
  • The endpoint and interval rules are the documented ones for finite arguments: the fixed program here prints 0 10 5 for the calls at t equal to 0, 1, and 0.5 over 0.0 and 10.0, and the function is monotonic between its arguments.
  • The parameter is not clamped: the fixed program prints 20 -10 1e+308 inf 1 for the calls at t equal to 2.0 and -1.0, the equal-arguments call at 1e308, the infinity-with-itself call, and the quiet-NaN-first-argument call - the last of those reports 1 in this program, not a NaN, and the second special-value program prints 1 nan nan 1 inf, so NaN and infinity outcomes depend on the position the special value occupies, and no general propagation rule is stated for them here.
  • The arguments do not share one required type: with <cmath> included, an all-integer call and a mixed int, double, and float call each print 5, and a bool call compiles as well - additional overloads convert arithmetic arguments to a common floating-point type. Those are not include defects in any shape.
  • std::lerp is a C++20 function and is constexpr and noexcept since C++20: a static_assert over the call compiles under C++20, and under C++17 the name itself is absent with the same plain error and no note.
  • std::midpoint is not declared by #include <cmath>: in the program here, which includes only <cmath>, it gets its own is not a member of 'std' error, with no note - and the fixed neighbor program, which includes both <cmath> and <numeric>, prints 5 5 for the interpolation call and the midpoint call.
  • 'lerp' was not declared in this scope for an unqualified lerp use is a different defect: qualify the name as std::lerp - the include alone does not bring the name out of namespace std. For this name no argument-dependent-lookup case rescues the unqualified call in the program probed here: double arguments have no associated namespace.

The fixes, ranked

  • First, check the include list of the file that names std::lerp. If <cmath> is not there, add it - that is the fix in the common case, and it holds whether the file failed in a lean context, failed in a textbook file, or happened to compile before through a transitive rescue.
  • Second, do not wait for a note to confirm the header - for this error there is none. In the contexts probed here the diagnostic is one bare line; take the fix from the name's home header, <cmath>, not from the output.
  • Third, do not reach for <numeric> because the call belongs to the interpolation family alongside std::midpoint. In the sweep probed here, <numeric> fails for std::lerp with the same error - the two C++20 siblings live in different headers, lerp in <cmath> and midpoint in <numeric>.
  • Fourth, do not be reassured by <iostream>, <vector>, or <string> being present - in the sweep here none of them rescues this name at all - and do not remove <cmath> because a file compiles without it: in the probed set five headers rescue it, and those rescues are not guaranteed.
  • Fifth, check the standard before changing the code when the include is already right. Under C++17 this name does not exist; under C++20 it exists and is already constexpr, so a static_assert over the call needs nothing newer. The diagnostic will not separate these cases, so read the build's standard flag directly.
  • Sixth, if the error says was not declared in this scope instead, fix the name's qualifier to std::lerp as well - and do not look for an argument-dependent-lookup case that makes the unqualified call work over plain doubles, because there is none.
  • Seventh, do not convert the arguments as a fix for this error: integer, mixed, and bool calls all compile with <cmath> included, so an is not a member of 'std' failure is never an argument-type defect for this function.
  • Eighth, if the failing name is the neighboring one, the fix is the other header: midpoint takes an added <numeric> - two headers for the pair, one per name.

Which fix for which cause

  • #include <cmath> missing, std::lerp used in a file whose only include is one of the 100 headers listed as failing in the sweep section above, or that includes nothing: the message is 'lerp' is not a member of 'std', with no suggestion tail, no note lines, and no help lines - add #include <cmath>.
  • std::lerp used in a textbook file including <iostream> and <vector>: the message is the same bare error - add #include <cmath>.
  • std::lerp used with only <cmath>, <ccomplex>, <complex>, <ctgmath>, <random>, or <valarray> included: no error on this library version - add #include <cmath> anyway when it is not the include already present, because the other five rescues are not guaranteed.
  • std::lerp used with <cmath> included under C++17: the message is 'lerp' is not a member of 'std' with no note - compile as C++20 or later. A static_assert over the call needs only C++20, where the function is already constexpr.
  • std::midpoint used without <numeric> in a file whose only include is <cmath>: the message names midpoint, with no note - add #include <numeric>. For that name the header is the other half of the pair.
  • lerp used without the std:: qualifier, <cmath> included, over double arguments: the message is 'lerp' was not declared in this scope; did you mean 'std::lerp'? - qualify the name as std::lerp.
  • std::lerp called with integer arguments, with mixed arithmetic arguments, or with bool arguments, <cmath> included: no error in the programs probed here - the additional overloads convert the arguments to a common floating-point type, so no include or conversion change is needed for those shapes.

Checklist

  • Check the include list of the file that names the call, not just the project. The include must be in that file, or in a header that file includes directly by design.
  • Do not read the absence of a note as a different error. For this name the missing-include diagnostic is one bare line in every probed context.
  • Do not import the sibling's header into this error: lerp takes <cmath> and midpoint takes <numeric>, so there is a per-name header to look up in this pair - the opposite of the gcd, lcm, and midpoint family, where one header covers every name.
  • Do not assume the textbook includes rescue this name, and do not delete a working <cmath> line because a file compiles without it. In the sweep here <iostream> and <vector> do not rescue std::lerp at all, and the five headers that do rescue it do so only transitively.
  • Match the standard to the use: the call itself needs C++20 and <cmath>, and a constant-expression call needs nothing more, since the function is constexpr from C++20.
  • Do not assume the parameter is clamped: at t equal to 2.0 the call over 0.0 and 10.0 is 20, and at t equal to -1.0 it is -10. Code that passes an out-of-range t expecting a clamp gets extrapolation instead.
  • Do not assume a NaN in any position makes the result a NaN: in the programs here a quiet NaN as the first argument reports 1, while a quiet NaN as the second argument or as t reports nan. The documented guarantees cover finite first arguments; outside them, check the position you mean.
  • Do not add conversions to fix this error: integer, mixed, and bool calls compile as they stand, because the additional overloads convert arithmetic arguments to a common floating-point type.
  • After the fix, confirm the program runs, not just that it compiles: the fixed programs here print 0 10 5 for the endpoint and midpoint calls, 20 -10 1e+308 inf 1 for the extrapolation and special-value calls, and 5 5 for the neighbor calls.
  • 'std::midpoint' Is Not a Member of 'std' Fix - the same missing-include shape for the other C++20 interpolation function, with the headers swapped: its sweep splits into 103 uniform bare failures and the two transitive rescues <execution> and <random>, where this guide's sweep splits into 100 uniform bare failures and five transitive rescues - and the two guides differ in the argument rule as well, since std::midpoint requires its two arguments to share one non-bool arithmetic type, where std::lerp accepts integer, mixed, and even bool arguments through its additional overloads.

Sources

  • cppreference, std::lerp — for std::lerp being a function defined in <cmath> since C++20, constexpr and noexcept, computing a + t(b - a) with accounting for floating-point calculation imprecision, as the linear interpolation between a and b when t is inside [0, 1) and the linear extrapolation otherwise; for the additional overloads provided for all other combinations of arithmetic types, with the arguments converted to a common floating-point type; for the guaranteed properties when both a and b are finite - the result equal to a at t equal to 0, equal to b at t equal to 1, finite for t between 0 and 1 inclusive, equal to a when t is finite and a equals b, and monotonic in t; and for the feature-test macro __cpp_lib_interpolate (201902L, C++20), shared with std::midpoint.
  • cppreference, Standard library header <cmath> — for <cmath> being the header that declares std::lerp in its synopsis, as the linear interpolation function.
  • cppreference, std::midpoint — for std::midpoint being a pair of function template overloads defined in <numeric> since C++20, constexpr from its introduction - the home-header contrast the neighbor sections of this guide rest on, and the shared feature-test macro with std::lerp.

Keep Exploring