Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math calculations don't minify properly #45

Open
Haizlbliek opened this issue Oct 1, 2024 · 1 comment
Open

Math calculations don't minify properly #45

Haizlbliek opened this issue Oct 1, 2024 · 1 comment

Comments

@Haizlbliek
Copy link

If a variable is used inside a math calculation, the whole calculation is not minified.
It probably has something to do with the parenthesis.

Example 1

?(1 * (1 * (1 * (1 * (1 * (1 * (1 * (1 * (x * 1)))))))))

This doesn't get minified, as it has the variable.
However, turning x into a 1 makes the minified result ?1

Expected Result

?x

Actual Result

?1*(1*(1*(1*(1*(1*(1*(1*(a*1))))))))

Example 2

?(1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (x + 1)))))))))

This gives the same type of result.

Expected Result

?x+9

Actual Result

?1+(1+(1+(1+(1+(1+(1+(1+(a+1))))))))

Example 3

x = (9 * (2 * y)) * 4

Taking out the parenthesis fixes this problem (Example 4)

Expected Result

x = 72 * y

Actual Result

a=9*(2*b)*4

Example 4

x = 9 * 2 * y * 4

While this fixes the minification problem, it causes a new one: The left and right half are merged separately.

Expected Result

x = 72 * y

Actual Result

a=18*b*4

Outro

Well, that's what I've found so far. Hope it helps with some minification stuff.

@Haizlbliek Haizlbliek changed the title Math calculations don Math calculations don't minify properly Oct 1, 2024
@thisismypassport
Copy link
Owner

Thanks for the suggestion, but I'm not sure this is worth it as:
a) It's really simple to change the parentheses / order to avoid this, and you lose nothing by doing so.
b) If the variable is not a number but a table with metamethods, this optimization will not be correct. (So doing it would require additional checks/flags/etc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants