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

Power (^) doesn't support decimals. #22

Closed
KdudeDev opened this issue Jun 4, 2023 · 2 comments
Closed

Power (^) doesn't support decimals. #22

KdudeDev opened this issue Jun 4, 2023 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@KdudeDev
Copy link
Owner

KdudeDev commented Jun 4, 2023

Power of 2, 3, etc. will work, but anything like 1.7 or 0.5 will do nothing. This means that sqrt() is actually not working.

I have mostly fixed this, but not quite. I can get decimals of 0.5 to work, 0.5, 1.5, etc. will work. Anything like 0.6 or 0.4 will not however.

@KdudeDev
Copy link
Owner Author

KdudeDev commented Jun 8, 2023

Another issue with power is that it doesn't support negative powers. The solution is just to divide instead of multiply in the power function, but I'd like to fix this issue before fixing negative powers.

@KdudeDev KdudeDev added bug Something isn't working help wanted Extra attention is needed labels Jun 9, 2023
@KdudeDev
Copy link
Owner Author

KdudeDev commented Jun 9, 2023

This issue has been fixed. The entire loop has been replaced with first^power, second*power.

I tried this solution before, but it was giving incorrect results and I tossed it.
Turns out its correct, but the way I handle numbers was a problem that wasn't run into before.

Before I believed something like {2.5, 1.3} (2.5 * 10^1.3) just needed to be floored to {2.5, 1} and the answer would be correct. This was never a problem because second was never getting decimals.

This new power solution however would give second with a decimal. And because I was just flooring it out, first was wrong and so I thought it was wrong.

Turns out if you want to get rid of the decimal in second, you multiply first by 10^(second % 1). second % 1 will give us just the decimal of second. 25.532 % 1 = 0.532.

This is the code that uses the above

	first = tonumber(first)
	
	if second % 1 > 0 then
		first *= 10^(second % 1)
	end
	
	second = math.floor(second)

This will fix the number correctly (second having decimals is mathematically fine, but the module was built around not allowing it).

@KdudeDev KdudeDev closed this as completed Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant