Does Swift not have a "lerp"?

Have I missed this somewhere? I don't see it in Numerics either.

This sort of thing, I mean:

#expect(.mix(1, 2, 1 / 4) == 1.25)
extension FloatingPoint {
  static func mix(_ `.0`: Self, _ `.1`: Self, _ mix: Self) -> Self {
    `.0`.addingProduct(mix, `.1` - `.0`)
  }
}

Have you seen this functionality in other standard libraries, apart from those for shading languages?

C++ appears to have std::lerp in <cmath> (even though C doesn’t seem to have one in <math.h>).

2 Likes

Kinda sorta. The types from my second link have been in the standard library for over 6 years but you still need to import simd to get the mix function that operates on them.

And SwiftUI might as well be considered the standard library at this point.

Don't make no sense to not be able to do it on a scalar.

1 Like

A closed-source library only available on platforms owned by a single vendor cannot be considered part of the standard library.

1 Like

Swift had exactly what you just said in an official capacity for a full year and a half. It’s the same thing now.

I looked at the supposed figures and the percentage of Swift devs that AI thinks use SwiftUI is lower than I would have guessed, but it’s still a growing majority.

All the more who don’t get to use lines, apparently!