Discuss Scratch

elast27
New Scratcher
2 posts

"To the power of" operation

PLEASEEEE make a “to the power of” operation (not just 10^ but any power)

pwrof

This will be super useful for a project i'm working on
Paddle2See
Scratch Team
1000+ posts

"To the power of" operation

Try this:

10 ^oflogofx*y

That should give you x raised to the y power.

Last edited by Paddle2See (Dec. 6, 2014 02:50:13)

nimrocco
Scratcher
100+ posts

"To the power of" operation

Paddle2See wrote:

Try this:

10 ^oflogofx*y

That should give you x raised to the y power.
little_kitten
Scratcher
500+ posts

"To the power of" operation

I think you should do this:
defineone^tworepeattwosetanswertoone*one
VoltageGames
Scratcher
1000+ posts

"To the power of" operation

No support…
there's a workaround, I just don't know it…

Last edited by VoltageGames (Dec. 6, 2014 17:47:14)

TheHockeyist
Scratcher
1000+ posts

"To the power of" operation

Hmm… why can't the ST be more direct and include a power block? It would also eliminate “e^” and “10^” from the dropdown, so you lose two things and add one, meaning Scratch is one thing simpler.
RDoc
Scratcher
46 posts

"To the power of" operation

Paddle2See wrote:

Try this:

10 ^oflogofx*y

That should give you x raised to the y power.
Only for positive values of X though.

This has been asked for many times and I don't see why it should be so difficult to implement, but anyway,
I think this is a pretty general solution:

defineexpvalue,powerifvalue<0 andpowermod1>0thensetanswerto imaginary resultelsesetanswertoe^ofpower*lnofabsofvalue//useabstohandlenegativevaluesifvalue0)andpowermod2=1then//handleoddorevenexponentsofnegativevaluessetanswertoanswer*-1 negative value and non-integer exponent?

Last edited by RDoc (Dec. 7, 2014 20:08:56)

elast27
New Scratcher
2 posts

"To the power of" operation

Paddle2See wrote:

Try this:

10 ^oflogofx*y

That should give you x raised to the y power.
Thank you so much this really helped )
lalala3
Scratcher
100+ posts

"To the power of" operation

little_kitten wrote:

I think you should do this:
defineone^tworepeattwosetanswertoone*one
This doesn't work for fractional powers. See RDoc's solution above.

VoltageGames wrote:

No support…
there's a workaround, I just don't know it…
A workaround was given on the second post, its inability to handle negative bases aside. If you'd bothered to actually read the thread, you should have seen it.

I support this suggestion, despite its workarounds, because the exponent operator is a common and important one, used almost as often as addition, subtraction, multiplication, and division, and requiring users to use a workaround like RDoc's is even more egregious than Cyoce's example of
a+b=a-0-b
in almost every respect.

Edit: Link added.

Last edited by lalala3 (Dec. 10, 2014 00:59:56)

Cyoce
Scratcher
500+ posts

"To the power of" operation

Support.
I was about to respond to

Paddle2See wrote:

Try this:

10 ^oflogofx*y

That should give you x raised to the y power.
Talking about how the ability to compose a function of much more complicated functions does not invalidate said function, but

lalala3 wrote:

little_kitten wrote:

I think you should do this:
defineone^tworepeattwosetanswertoone*one
This doesn't work for fractional powers. See RDoc's solution above.

VoltageGames wrote:

No support…
there's a workaround, I just don't know it…
A workaround was given on the second post, its inability to handle negative bases aside. If you'd bothered to actually read the thread, you should have seen it.

I support this suggestion, despite its workarounds, because the exponent operator is a common and important one, used almost as often as addition, subtraction, multiplication, and division, and requiring users to use a workaround like RDoc's is even more egregious than Cyoce's example of
a+b=a-0-b
in almost every respect.

Last edited by Cyoce (Dec. 10, 2014 00:52:42)

Sillywilly24
Scratcher
6 posts

"To the power of" operation

This works 100 percent of the time
ifx<0theniffloorofymod2=0thensetanswerto10 ^oflogofabsofx*yelseset answerto-1*10 ^oflogofabsofx*yelsesetanswerto10 ^oflogofx*y
sets answer to x to the power of y
Sillywilly24
Scratcher
6 posts

"To the power of" operation

my above solution can be simplified a lot but it works so whatever
NilsTheBest
Scratcher
1000+ posts

"To the power of" operation

Sillywilly24 wrote:

This works 100 percent of the time
ifx<0theniffloorofymod2=0thensetanswerto10 ^oflogofabsofx*yelseset answerto-1*10 ^oflogofabsofx*yelsesetanswerto10 ^oflogofx*y
sets answer to x to the power of y
hi, thanks for helping but please don't necropost, this post was made years ago and probably has already been solved. Thanks ^^
Inkulumo
Scratcher
500+ posts

"To the power of" operation

NilsTheBest wrote:

Sillywilly24 wrote:

This works 100 percent of the time
ifx<0theniffloorofymod2=0thensetanswerto10 ^oflogofabsofx*yelseset answerto-1*10 ^oflogofabsofx*yelsesetanswerto10 ^oflogofx*y
sets answer to x to the power of y
hi, thanks for helping but please don't necropost, this post was made years ago and probably has already been solved. Thanks ^^
If the post is constructive (of which it is) and it is suggesting a workaround, it's allowed.
space_elephant
Scratcher
500+ posts

"To the power of" operation

TheHockeyist wrote:

Hmm… why can't the ST be more direct and include a power block? It would also eliminate “e^” and “10^” from the dropdown, so you lose two things and add one, meaning Scratch is one thing simpler.
It would not remove e because the constant e in still required for scratch projects. It could be changed to
e
bbrainstormer
Scratcher
11 posts

"To the power of" operation

Sillywilly24 wrote:

This works 100 percent of the time
ifx<0theniffloorofymod2=0thensetanswerto10 ^oflogofabsofx*yelseset answerto-1*10 ^oflogofabsofx*yelsesetanswerto10 ^oflogofx*y
sets answer to x to the power of y

If the answer is complex it returns the absolute value with the sign of the real part.
steve3rom
Scratcher
31 posts

"To the power of" operation

Paddle2See wrote:

Try this:

10 ^oflogofx*y

That should give you x raised to the y power.


When I try this, inputting 2 as x and 3 as y I get 7.999999999997. However I should get 8. If I just put a round around the code, will it work? Thanks.
Maximouse
Scratcher
1000+ posts

"To the power of" operation

steve3rom wrote:

Paddle2See wrote:

Try this:

10 ^oflogofx*y

That should give you x raised to the y power.


When I try this, inputting 2 as x and 3 as y I get 7.999999999997. However I should get 8. If I just put a round around the code, will it work? Thanks.
If you only need integers, you can use round and it will work.
E_Equals_EmCeCube3
Scratcher
1000+ posts

"To the power of" operation

It looks like this idea has been suggested before in this topic.
Feel free to continue the discussion there so we can keep individual suggestions organized and in one topic.
Super_Scratch_Bros20
Scratcher
1000+ posts

"To the power of" operation

Support. I know that there's a workaround, but if you think about it, LOTS of things have workarounds. We don't technically need variables; we can use lists. We don't need the
move10steps
block or the
changexby10
block; we can just use
gotox:xposition+10y:yposition
. We don't need backdrops; we can just use sprites that look like backdrops.

These features will simplify the amount of work that needs to be done. Again, support.

Powered by DjangoBB