## Discuss Scratch

### Power block

`(() ^ () :: operators)`

This is necessary because there is no real workaround (AFAIK) that will work for all power calculations in Scratch.
Oh wait there is
(credit to DadOfMrLog) but this workaround is huge and no reason to not just have the block

It also isn't too complicated for young people who may not have learned this math yet because this block already has more complicated math operations:
`([sqrt v] of (9))`
The block could be positioned right above that block so both blocks with somewhat complex math are together.

Last edited by savaka (Aug. 9, 2016 14:44:58)

### Power block

You can use logarithms to do that.
`([10^ v] of ((y) * ([log v] of (x))) // =  x^y`

Last edited by drmcw (Sept. 11, 2013 12:22:57)

10 !

### Power block

yes, but same can be said of the change x/y by and go to blocks… They aren't necessary, but for new scratchers are a great help.

### Power block

xlk wrote:

yes, but same can be said of the change x/y by and go to blocks… They aren't necessary, but for new scratchers are a great help.
Yes, but how many projects need a x^y block?

10 !

### Power block

Lilifant7253 wrote:

You can do it like this too:
`when gf clickedset [variable1 v] to (1)repeat (y)set [variable1 v] to ((variable1) * (x))`
That doesn't work for negative or non-integer powers, though.

Last edited by jvvg (Sept. 11, 2013 17:39:29)

jvvg
Administrator and backend engineer on the Scratch Wiki
Executive director of FutureSight Technologies

### Power block

drmcw wrote:

You can use logarithms to do that.
`([10^ v] of ((y) * ([log v] of (x))) // =  x^y`
Does this work for all negatives and decimals?

### Power block

drmcw wrote:

xlk wrote:

yes, but same can be said of the change x/y by and go to blocks… They aren't necessary, but for new scratchers are a great help.
Yes, but how many projects need a x^y block?
I was thinking of making a calculator project.

### Power block

jvvg wrote:

Lilifant7253 wrote:

You can do it like this too:
`when gf clickedset [variable1 v] to (1)repeat (y)set [variable1 v] to ((variable1) * (x))`
That doesn't work for negative or non-integer powers, though.
It actually does. Check out my project to test non-integer numbers. I don't think it works with negatives.

Last edited by mitchboy (Sept. 11, 2013 21:42:01)

Capsicum annuum.

### Power block

savaka wrote:

drmcw wrote:

You can use logarithms to do that.
`([10^ v] of ((y) * ([log v] of (x))) // =  x^y`
Does this work for all negatives and decimals?
You can't make x negative.

10 !

### Power block

mitchboy wrote:

jvvg wrote:

Lilifant7253 wrote:

You can do it like this too:
`when gf clickedset [variable1 v] to (1)repeat (y)set [variable1 v] to ((variable1) * (x))`
That doesn't work for negative or non-integer powers, though.
It actually does. Check out my project to test non-integer numbers. I don't think it works with negatives.

It works fine for non-integer x, but as jvvg wrote, it can't work with non-integer *powers* (i.e. where y is not a whole number).
It will give an answer, because it will repeat a certain whole number of times [round(y) rather than floor(y), interestingly], but it will be wrong…

@savaka:
Note that using:

`([10^ v] of ((y) * ([log v] of (x))) // =  x^y`
or
`([e^ v] of ((y) * ([ln v] of (x))) // =  x^y`
may give you a non-integer result even though both x and y are integers - because the log(x) [or ln(x)] won't be an integer, so there can be rounding errors when it then does 10 to the power [or e to the power] of that.
If you want to ensure you get exactly an integer (maybe for testing if it is less/greater/exactly some integer value) then you should round it.

Personally, I think it'd be nice to see this added somewhere - though it would unfortunately not be able to go into the current drop-down with the other less well-known maths operators (sqrt,abs,etc.) because it has two ‘slots’ rather than just the one. It would need to be on its own like ‘mod’. Or else that block could also become a drop-down, containing “mod” and ^. (But I haven't checked how that affects certain things in the way script is encoded…)

Unfortunately, those are the only really useful two-argument operators that I can think of (apart from the obvious ones like +, -, *, /, already elsewhere) - others start to become really rather obscure, and not so useful…

Last edited by DadOfMrLog (Sept. 12, 2013 16:27:02)

### Power block

drmcw wrote:

savaka wrote:

drmcw wrote:

You can use logarithms to do that.
`([10^ v] of ((y) * ([log v] of (x))) // =  x^y`
Does this work for all negatives and decimals?
You can't make x negative.

You need to check for zeros, though, because x^0=1 and 0^y = 0 unless x=y=0, in which case you should have 0^0=1 (surprisingly enough…)
So you can do the check for x being zero first, and make the result equal to one straight away if it is, otherwise then check if y=0, and if so set the result to zero straight away.

But dealing with negative x is possible under certain circumstances - if y is an integer then it's just a case of checking if y is even or odd, and using abs(x)^y - you negate the result if y is odd.

Fractional powers of negative numbers are rather more tricky to do if you're only able to deal with real numbers (I'd assume you don't want to get into the realm of complex numbers…)

Last edited by DadOfMrLog (Sept. 12, 2013 16:47:58)

### Power block

jvvg wrote:

Lilifant7253 wrote:

You can do it like this too:
`when gf clickedset [variable1 v] to (1)repeat (y)set [variable1 v] to ((variable1) * (x))`
That doesn't work for negative or non-integer powers, though.
Yes, you're right you've to do it like this. (but y has to be integer):
`when gf clickedset [variable1 v] to (1)repeat ([amount v] of (y))set [variable1 v] to ((variable1) * (x))`
`if <(y) < (0)>set [variable1 v] to ((1) / (variable1))`
Of course there shouldn't be the leak between the repeat and the if block.

Last edited by Lilifant7253 (Sept. 14, 2013 16:10:19)

### Power block

This is a good idea.

`[ v]`
A dropdown to nowhere

### Power block

Sorry, but http://scratch.mit.edu/discuss/topic/9907/ .

Last edited by mathfreak231 (Sept. 16, 2013 21:50:54)

3DS FC: 3239-6065-2543 (Ask me before adding) | AS: Alex~ | X: Alex (DWS)

My browser / operating system: MacOS Macintosh X 10.11.3, Safari 9.0.3, Flash 20.0 (release 0)

### Power block

Would adding this make it easier for new Scratchers? Yup.

And why would you add it as a citation? It doesn't accept OR deny the block.

Alt account of Firedrake969.

Rocket II: A black and white bitmap space game!

I seek not fame, but education.

;

### Power block

firedrake969_test wrote:

Would adding this make it easier for new Scratchers? Yup.

And why would you add it as a citation? It doesn't accept OR deny the block.
It shows that at least 1 scratcher supports it.
And I meant it as something that has already been suggested.

3DS FC: 3239-6065-2543 (Ask me before adding) | AS: Alex~ | X: Alex (DWS)

My browser / operating system: MacOS Macintosh X 10.11.3, Safari 9.0.3, Flash 20.0 (release 0)

### Power block

mathfreak231 wrote:

Sorry, but http://scratch.mit.edu/discuss/topic/9907/ .

firedrake969_test wrote:

Would adding this make it easier for new Scratchers? Yup.

And why would you add it as a citation? It doesn't accept OR deny the block.

mathfreak231 wrote:

firedrake969_test wrote:

Would adding this make it easier for new Scratchers? Yup.

And why would you add it as a citation? It doesn't accept OR deny the block.
It shows that at least 1 scratcher supports it.
And I meant it as something that has already been suggested.
I don't understand what you're talking about.

Last edited by savaka (Sept. 21, 2013 11:14:27)

### Power block

by this logic, we can remove “move (10) steps”

why not just use
`go to x: ((x position) + ([cos v] of ((direction)*(amt)))) y ((x position) + ([sin v] of ((direction)*(amt))))`
i mean jeez so simple

I am a Lava Expert

### Power block

and while we are at it, the “wait” block is also unnecessary, as you can use the timer for it.
BTW, I remember reading somewhere that scratch's blocks are faster than a series of blocks doing the same, so (()^()) would be technically speaking faster than doing logarithms. I mean, is it that hard to add scratchteam?