[#mp_units-lerp]
= xref:mp_units.adoc[mp&lowbar;units]::lerp
:relfileprefix: ../
:mrdocs:

Linear interpolation or extrapolation

== Synopsis

Declared in `&lt;mp&hyphen;units&sol;math&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    auto R1,
    auto Origin,
    typename Rep1,
    auto R2,
    typename Rep2,
    typename Factor&gt;
requires requires(Rep1 a, Rep2 b, Factor t) &lcub;
    get&lowbar;common&lowbar;reference(R1, R2)&semi;
    requires requires &lcub; lerp(a, b, t)&semi; &rcub;
&num;if MP&lowbar;UNITS&lowbar;HOSTED
               &verbar;&verbar; requires &lcub; std&colon;&colon;lerp(a, b, t)&semi; &rcub;
&num;endif
               &semi;
  &rcub;
&lsqb;&lsqb;nodiscard&rsqb;&rsqb;
constexpr
xref:mp_units/QuantityPointOf.adoc[QuantityPointOf&lt;get&lowbar;quantity&lowbar;spec(get&lowbar;common&lowbar;reference(R1, R2))&gt;] auto
lerp(
    xref:mp_units/quantity_point-08.adoc[quantity&lowbar;point&lt;R1, Origin, Rep1&gt;] const& a,
    xref:mp_units/quantity_point-08.adoc[quantity&lowbar;point&lt;R2, Origin, Rep2&gt;] const& b,
    Factor const& t) noexcept;
----

== Description

Computes the linear interpolation between `a` and `b`, if the parameter `t` is inside `&lsqb;​0​, 1)&rsqb;` (the linear extrapolation otherwise), i&period;e&period; the result of `a &plus; t(b − a)` with accounting for floating&hyphen;point calculation imprecision&period;

== Return Value

the point resulting from interpolating (or extrapolating) between `a` and `b` by `t`

[NOTE]
====
The return value https://en.cppreference.com/cpp/language/attributes/nodiscard[should not be discarded^].
====
== Parameters

[cols="1,4"]
|===
| Name| Description
| *a*
| the point corresponding to `t &equals;&equals; 0`
| *b*
| the point corresponding to `t &equals;&equals; 1`
| *t*
| the interpolation (or extrapolation) factor
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
