Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Exponents
- belugawhale
-
Scratcher
25 posts
Exponents
On a game I am working on, I would like to include exponential growth, but a custom block that repetitively multiplies some amount of times is lagging my game a lot (because it has to sometimes multiply 50000 times). I think there should be a math block for x^y.
- 0bitasy0
-
Scratcher
77 posts
Exponents
would repeat (y) {set x to (x*x)} make a difference, where you increase y?
- Psiborg
-
Scratcher
500+ posts
Exponents
Any exponent y can be written as either 2z+1 (for odd exponents) or 2z (for even exponents) and
x^2z = x^z * x^z
x^(2z+1) = x^z * x^z * x
So by calculating x^z and using that, you have almost halved the number of multiplications than normally needed for x^y. This could then be extrapolated further as required.
But going back to what you said, an exponent block would be nice
x^2z = x^z * x^z
x^(2z+1) = x^z * x^z * x
So by calculating x^z and using that, you have almost halved the number of multiplications than normally needed for x^y. This could then be extrapolated further as required.
But going back to what you said, an exponent block would be nice

- drmcw
-
Scratcher
1000+ posts
Exponents
You don't need a x^y block when you have e^ and ln.
x^y = e^(y*ln(x))
So you can calculate an exponent with one natural log, one multiplication and an inverse natural log.
x^y = e^(y*ln(x))
So you can calculate an exponent with one natural log, one multiplication and an inverse natural log.
- Psiborg
-
Scratcher
500+ posts
Exponents
You don't need a x^y block when you have e^ and ln.Admittedly that is rather more elegant than my suggestion
x^y = e^(y*ln(x))
So you can calculate an exponent with one natural log, one multiplication and an inverse natural log.

I'd still vote for an x^y block just for the sake of user friendliness though.
- DadOfMrLog
-
Scratcher
1000+ posts
Exponents
One thing to watch for when using the 10^ and log operators (or e^ and ln) is that you may not get exactly an integer result, even though your input values are integers (so x^y should be integer if both x & y are integers). -Rounding errors may give you something which is very close to, but not exactly, an integer.
Might not matter for what you have in mind, and if you know to expect an integer you can always “round” it, but thought I'd mention just in case…
Might not matter for what you have in mind, and if you know to expect an integer you can always “round” it, but thought I'd mention just in case…
Last edited by DadOfMrLog (July 21, 2013 22:08:52)
- belugawhale
-
Scratcher
25 posts
Exponents
You don't need a x^y block when you have e^ and ln.Thanks! I will try that!
x^y = e^(y*ln(x))
So you can calculate an exponent with one natural log, one multiplication and an inverse natural log.
- baconlover5555
-
Scratcher
100+ posts
Exponents
I made a script for you! https://scratch.mit.edu/projects/72768570/
- 15-MinuteGaming
-
Scratcher
100+ posts
Exponents
Your post looks like a suggestion. If so, continue with this post.
- codeman1044
-
Scratcher
1000+ posts
Exponents
No need to post on a topic that's from 2013! Please avoid necroposting.
- AMOGUSDOODLEGUY
-
Scratcher
2 posts
Exponents
On a game I am working on, I would like to include exponential growth, but a custom block that repetitively multiplies some amount of times is lagging my game a lot (because it has to sometimes multiply 50000 times). I think there should be a math block for x^y.I agree i need that
- medians
-
Scratcher
1000+ posts
Exponents
Please do not necropost.On a game I am working on, I would like to include exponential growth, but a custom block that repetitively multiplies some amount of times is lagging my game a lot (because it has to sometimes multiply 50000 times). I think there should be a math block for x^y.I agree i need that
And see the project by @TheLogFather/@DadOfMrLog (the one in his signature).
- Discussion Forums
- » Help with Scripts
-
» Exponents










