Add tau to the standard math functions

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.

8 Likes

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.

6 Likes

It’s not so much a performance thing as it is a convenience thing.

As much as I like this, I already set variables to pi, halfpi, and tau. Adding it to the standard math functions wouldn’t change anything for me. lol

Essentially, we need a way to alter the global namespace. I would love to add my class library to it for example.

1 Like

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.

AAAAAaaaaaaaa

4 Likes

Problem?

1 Like

nothing wrong with immutable global state as long as it’s properly managed and you don’t just throw random utility functions into _G as you go

blob.png

3 Likes

pfffft. nah. you’ll be fine

ᶦ’ᵐ ʲᵒᵏᶦᶰᵍ⋅ ᵖᶫᵉᵃˢᵉ ᵈᵒᶰ’ᵗ ʰᵃᵗᵉ ᵐᵉ ᶠᵒʳ ᶦᵗ ﹔^﹔

2 Likes

2 Likes

None, _G is fine if you don’t use it as a crutch. I find it snobbish to criticize it if you use it occasionally.

There’s a thread discussing about _G here:
http://devforum.roblox.com/t/reasons-to-avoid-global--g/23438

Keep this one on-topic :slight_smile:

1 Like

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.

I am against adding it to the math lib

2 Likes