diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2021-06-17 23:40:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-17 23:40:57 +0200 |
| commit | fcac47896696899badc9a436d798d48158895ea3 (patch) | |
| tree | 08302428c205c02b60d6b0d142a2127737f4480e /src/test/rustdoc-gui/basic-code.goml | |
| parent | e062e5d34ee80e0d5da403e8c5609f29e6a7dbcb (diff) | |
| parent | 525d76026fe855f6a9de4604d9fee50d974994a3 (diff) | |
| download | rust-fcac47896696899badc9a436d798d48158895ea3.tar.gz rust-fcac47896696899badc9a436d798d48158895ea3.zip | |
Rollup merge of #85925 - clarfonthey:lerp, r=m-ou-se
Linear interpolation #71016 is a previous attempt at implementation that was closed by the author. I decided to reuse the feature request issue (#71015) as a tracking issue. A member of the rust-lang org will have to edit the original post to be formatted correctly as I am not the issue's original author. The common name `lerp` is used because it is the term used by most code in a wide variety of contexts; it also happens to be the recently chosen name of the function that was added to C++20. To ensure symmetry as a method, this breaks the usual ordering of the method from `lerp(a, b, t)` to `t.lerp(a, b)`. This makes the most sense to me personally, and there will definitely be discussion before stabilisation anyway. Implementing lerp "correctly" is very dififcult even though it's a very common building-block used in all sorts of applications. A good prior reading is [this proposal](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0811r2.html#linear-interpolation) for the C++20 lerp which talks about the various guarantees, which I've simplified down to: 1. Exactness: `(0.0).lerp(start, end) == start` and `(1.0).lerp(start, end) == end` 2. Consistency: `anything.lerp(x, x) == x` 3. Monotonicity: once you go up don't go down Fun story: the version provided in that proposal, from what I understand, isn't actually monotonic. I messed around with a *lot* of different lerp implementations because I kind of got a bit obsessed and I ultimately landed on one that uses the fused `mul_add` instruction. Floating-point lerp lore is hard to come by, so, just trust me when I say that this ticks all the boxes. I'm only 90% certain that it's monotonic, but I'm sure that people who care deeply about this will be there to discuss before stabilisation. The main reason for using `mul_add` is that, in general, it ticks more boxes with fewer branches to be "correct." Although it will be slower on architectures without the fused `mul_add`, that's becoming more and more rare and I have a feeling that most people who will find themselves needing `lerp` will also have an efficient `mul_add` instruction available.
Diffstat (limited to 'src/test/rustdoc-gui/basic-code.goml')
0 files changed, 0 insertions, 0 deletions
