Behavior change for Vector2.Lerp and Vector4.Lerp
Previously, Vector2.Lerp(Vector2, Vector2, Single) and Vector4.Lerp(Vector4, Vector4, Single) were implemented as
value1 + (value2 - value1) * amount. However, due to a floating-point rounding error, this algorithm doesn't always return
In .NET 5 and later, the implementation uses the same algorithm as Vector3.Lerp(Vector3, Vector3, Single), which is
(value1 * (1.0f - amount)) + (value2 * amount). This algorithm correctly accounts for the rounding error. Now, when
1.0f, the result is precisely
value2. The updated algorithm also allows the algorithm to be freely optimized using MathF.FusedMultiplyAdd when it's available.
No action is necessary. However, if you want to maintain the old behavior, you can implement your own
Lerp function that uses the previous algorithm of
value1 + (value2 - value1) * amount.