Minor request. It would be very helpful to have two pi as a constant value in the math library as it has many frequent uses in rotation and would remove a ton of (math.pi * 2) that need to be frequently written everywhere.
There’s lots of people that want this feature after many years of patiently waiting:
Support, I’ve written math.pi * 2 so many times I sometimes forget you’re supposed to multiply it by 2. Having math.tau would just simplify things and is certainly not a complex request
pi is the ratio of the circumference of a circle to its diameter. Outside of engineering, diameter is very rarely used. tau is the ratio of the circumference to the radius. In most math and most especially in video games, radius is the more common measurement to work with. So tau is inherently more natural in the majority of cases.
Here’s my question. Does referencing the math library take longer than just referencing a variable?
For example if you did a loop of
for x = 1,1000000 do
print(math.pi)
task.wait() -- I know, this isn't an accurate timer, but you get my point
end
would that take microseconds longer than
pi = 6.2831853071796
for x = 1,1000000 do
print(pi)
task.wait()
end
If it takes longer then why not make a simple variable at the top of your script
tau = math.pi * 2
as mentioned by @notchloeno, but without referencing the math library like @5P3C1A1_XD posted. This would also mean you don’t have to reference the math library each time you use it and typing pi or tau instead of math.pi or math.tau would be quicker.
How about math.phi = (1 + math.sqrt(5)) / 2 while we’re at it? It’s used in many geometric formulae in particular, and takes longer to type out than tau by a fair bit.
It would have in Lua 5.1, however Luau recognized that globals such as math.pi are extremely common, and Luau can index a global and up to two steps deeper in a single step, i.e. game.Workspace.Part takes only one step in Luau. This is for globals specifically. I don’t believe this works with any variables you create. The specific opcode is named getglobal.
Regardless of performance, the ‘why not’ from our perspective is ‘why not add it’ since it can conceivably be implemented bug-free in a matter of minutes, so long as everyone is on board with the changes.