52 lines
1.3 KiB
Markdown
52 lines
1.3 KiB
Markdown
[c.math.lerp]
|
||
|
||
# 29 Numerics library [[numerics]](./#numerics)
|
||
|
||
## 29.7 Mathematical functions for floating-point types [[c.math]](c.math#lerp)
|
||
|
||
### 29.7.4 Linear interpolation [c.math.lerp]
|
||
|
||
[ð](#lib:lerp)
|
||
|
||
`constexpr floating-point-type lerp(floating-point-type a, floating-point-type b,
|
||
floating-point-type t) noexcept;
|
||
`
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9910)
|
||
|
||
*Returns*: a+t(bâa)[.](#1.sentence-1)
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9914)
|
||
|
||
*Remarks*: Let r be the value returned[.](#2.sentence-1)
|
||
|
||
If isfinite(a) && isfinite(b), then:
|
||
|
||
- [(2.1)](#2.1)
|
||
|
||
If t == 0, then r == a[.](#2.1.sentence-1)
|
||
|
||
- [(2.2)](#2.2)
|
||
|
||
If t == 1, then r == b[.](#2.2.sentence-1)
|
||
|
||
- [(2.3)](#2.3)
|
||
|
||
If t >= 0 && t <= 1, then isfinite(r)[.](#2.3.sentence-1)
|
||
|
||
- [(2.4)](#2.4)
|
||
|
||
If isfinite(t) && a == b, then r == a[.](#2.4.sentence-1)
|
||
|
||
- [(2.5)](#2.5)
|
||
|
||
If isfinite(t) || !isnan(t) && b - a != 0, then !isnan(r)[.](#2.5.sentence-1)
|
||
|
||
Let *CMP*(x,y) be 1 if x > y,-1 if x < y, and 0 otherwise[.](#2.sentence-3)
|
||
|
||
For any t1 and t2, the product of*CMP*(lerp(a, b, t2), lerp(a, b, t1)),*CMP*(t2, t1), and*CMP*(b, a) is non-negative[.](#2.sentence-4)
|