Add math.lerp function

Your method is correct for multiple numbers but I was thinking of a traditional two-number input. Apologies for the misunderstanding.

I don’t believe it would, especially since it’s one function. Even with the addition of all the current Luau libraries, the performance of code has not been affected negatively.

There are multiple teams of engineers within Roblox. The team that works on the studio app and the team that works on the website is not the team that works on the Luau codebase. That’s why I believe adding this function shouldn’t redirect focus of Studio and website matters.

2 Likes

Yeah it’s fine. I wanted to replicate the flexibility of the function. For a traditional two or three number system using “<” and “>” would be more than enough.

I meant as in for the engineers. Would slow down the progress on up-coming features by a bit.

Ohhh, that makes a lot of sense! I didn’t really knew that. Sorry for that. I guess you win on this then. I thought there was only a single engineering team, seeing how slow roblox is with most stuff.

2 Likes

I don’t know if this works for every case, but you can also do this:

local function math_min(...: number): number
   local t = {...}
   table.sort(t)
   return t[1]
end

print(math_min(1, 2, -3, 4, 5, -6, -99, 87)) --> -99

@awry_y hates cool roblox features

2 Likes

That’s a clever method of doing so.

No, I just don’t find this feature as cool and needed as people think it is. ¯\_(ツ)_/¯

1 Like

I used to have this Bookmarked:

, but I’ve written the exact same expression so many times that I’ve completely memorised it. I really dislike having to write “utility” functions that have nothing to do with the rest of my code, I agree this should be in the language.

1 Like

My reason for wanting this isn’t to cut down on the utility functions I need to write but rather to abstract away any potential optimisations over the engine. I use lerping a lot in my code and, as such, need the most performant solution. Not only would moving the function over to the C-side likely result in natural optimisations but it would also allow the engine developers, who are likely more experienced in optimisation than many developers, to implement those optimisations for us.

Theres currently a luau RFC open for math.lerp

1 Like

How is this useless, I find myself writing the same function over and over again and I would like a function that eases this need and speeds my productivity. Such a bold and thoughtless claim.

5 Likes

I agree with this request. If there’s a cframe.lerp, surely we can have a math.lerp

i’m not so sure about this one
idk what kind of code you work on but there are definitely places where lerp gets used a lot

poor reasoning
this update should take like 1-2 minutes max
what is 1-2 minutes gonna do to the bigger updates? practically almost nothing. the “tiny bit” of delay probably won’t even amount to 0.1% of the time

as for why they’re slow with big updates, it’s partially a lack of “wanting to do it” (aka procrastinating), partially a lack of idea on what they want to do,
or maybe they’re encountering errors (those things are physically painful in c and c++, they will spam multiple verbose compile errors up your face all because you forgot a semicolon)

math.map is already live in studio. It is an extension of lerp.

--format
local output = math.map(input, input_min, input_max, output_min, output_max)
--lerp
local value = math.map(alpha, 0, 1, from, to)
--example
local celsius = math.map(fahrenheit, 32, 212, 0, 100)
4 Likes

Let’s go, they need to add it to the documentation and maybe present it officially.

1 Like

Wow. This mapping will definitely simplify many scripts in the near future—sliders specifically come to mind.

Out of curiosity, how did you discover math.map?

It has existed since October 18th. Funny that it was in RFC hell for 4 weeks but was added in just two days.

math.lerp is still useful both for performance and showing intent. I’d also like to see a vector.lerp to mirror Vector3:Lerp.

Yeah I figured it would be in Roblox’s GitHub repository; I was wondering how they initially found out about it. I don’t think it was formally announced in the Forum, so is it just by checking the repository frequently you and @Prototrode discover these things?

This shouldn’t be a problem; to restore the pretty slight performance edge of a normal lerp, the math.map function can check if they’re only three arguments. If so, then

return A + ((B - A) * D)

Yeah, I agree with this. It would make more sense linguistically than “map” in certain cases where it’s only functioning as a lerp. Plus it maintains consistency with other functions using the term lerp.

They’re also mentioned in new #updates:release-notes

We just see them on the releases (that be Roblox or Luau).

Alternatively, if you’d like to be on top of everything Luau related, you can watch the repository or join the Roblox OSS Discord Server.

Friggin’ schweet update, can’t wait for math.lerp next

I literally said math.map is an extension of lerp why would we still need lerp lol
It does what lerp does and then some more