it’s short and simple.
i’ve recently had to use it for a few math calculations in different scripts. and having to define it in each script is an inconvenience.
i know it’s as simple as
Previousmaths*math.pi*2
but i’d much rather just be able to do
Previousmaths*math.tau
i haven’t seen any requests for it so far, so… yeah.
PLUS, when working in Radians it’s so much easier to do the math in my head rather than trial and error for 30 minutes on something minute like turning a wheel at a specific speed.
I understand the need to reduce boilerplate in some portions of the API, but this seems like the wrong place to look.
If your fear is that math.pi*2 is too slow or not clean enough, your best option is to localize it along with pi, as x*tau is cleaner and (much) faster than x*math.tau.
local pi, tau = math.pi, math.pi*2
The multiplication by 2 doesn’t cause a loss of precision here because the last bit of tau should be 0, so there’s no real reason to not do this.
If you want performance in lua, hardcode your constants. Lua compiles to bytecode that runs pretty fast, but Lua hardly makes any assumptions about what your code does (“math.pi” literally gets the “math” global, then gets the “pi” index in its hash table) In reality all it should need to do is get a constant. I wrote a lua lexer and simplifier for my game that does things like this automatically before I publish.
If you’re wondering how the compiler might try to optimize your code without explicit typing:
local foo = bar*10/3
Because bar could have a metatable, Lua can’t simplify the constants (I’m pretty sure the compiler does this for simple cases)
This lets the compiler potentially optimize your code:
local foo = bar*(10/3)
Tbh I use pi*2 a lot more than just pi, but I think we should keep it how it is. If you really want a convenient reference to something, use _G. If we’re going to start making changes to Lua’s implementation, I’d like to try adding OP codes for random things like type() and unpack(). Only problem is if someone uses setfenv to override that stuff.
im probably in the minority here but I use tau to denote the constant that represents the ‘full cycle’ of whatever im working with. with angles it’d be 2pi, because 2pi is a full rotation. but when working with more arbitrary things, tau could represent anything.