## Discuss Scratch

- pokejofe
- Scratcher

68 posts

### Power block

Support!

if <([10^ v] of (( power) * ([log v] of ( base))) :: operators) = (( base) ^ ( power) :: operators)> then

say [This makes sense]

else

say [I think the kumquats made this bug]

end

Generation 377: the first time you see this copy and paste it on top of your sig in the scratch forums and increase generation by 1. Social experiment. I did not start this

Kumquats haven't eaten my signature! although I don't know what has…

Edit: I figured out what ate my signature! nothing. A bee stung it!

but I have seen some apples that looked like troublemakers hanging around it lately…

- superben100
- Scratcher

1000+ posts

### Power block

Support!

But…

^_^

But…

(((y) / (2)) * ((x) * (x)))x ^ y

^_^

*Last edited by superben100 (May 21, 2016 02:16:03)*

Hey there, I'm Superben100!

I've been on Scratch for over 4 years, so if you have any questions, feel free to ask!

I've been on Scratch for over 4 years, so if you have any questions, feel free to ask!

- Owengren
- Scratcher

100+ posts

### Power block

My project needs one! But, I have a workaround:I was thinking of making a calculator project.Yes, but how many projects need a x^y 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.

define (x) ^ (y)

set [output v] to [0]

repeat (y)

change [output v] by (([sin v] of (y)) / (([floor v] of (x)) + ((length of ((y) * (10))) - ([abs v] of ((x) + ((y) - ((x) / (4))))))))

- Lythium
- Scratcher

1000+ posts

### Power block

^^^ and this is why we need powers.My project needs one! But, I have a workaround:I was thinking of making a calculator project.Yes, but how many projects need a x^y 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.define (x) ^ (y)

set [output v] to [0]

repeat (y)

change [output v] by (([sin v] of (y)) / (([floor v] of (x)) + ((length of ((y) * (10))) - ([abs v] of ((x) + ((y) - ((x) / (4))))))))

- TheMonsterOfTheDeep
- Scratcher

1000+ posts

### Power block

…that's not a workaround…My project needs one! But, I have a workaround:I was thinking of making a calculator project.Yes, but how many projects need a x^y 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.define (x) ^ (y)

set [output v] to [0]

repeat (y)

change [output v] by (([sin v] of (y)) / (([floor v] of (x)) + ((length of ((y) * (10))) - ([abs v] of ((x) + ((y) - ((x) / (4))))))))

(sorry for the bump)

*Last edited by TheMonsterOfTheDeep (Aug. 9, 2016 06:36:43)*

my latest extension: 2d vector math

- savaka
- Scratcher

1000+ posts

### Power block

I added some arguments for the power block

THERE IS NO REAL WORKAROUND

THERE IS NO REAL WORKAROUND

- TheLogFather
- Scratcher

1000+ posts

### Power block

THERE IS NO REAL WORKAROUNDHuh?

…though I still think it'd be quite nice to have the block, despite not being entirely clear where it'd go, since it feels like it should be part of the multichoice maths operators block (the one with the dropdown menu), but cannot go there 'cos it takes two args rather than one…

*Last edited by TheLogFather (Aug. 9, 2016 12:54:31)*

Siggy the Kumquat slayer:

Main account: DadOfMrLog –– Frameworks for basic pen-rendered 3D in scratch (see studio). Examples:

- - - - 3D Text - - - - - - Simple shapes - - - Controllable structures - - - On the ground - - - - - - In space - - - -

- - - - 3D Text - - - - - - Simple shapes - - - Controllable structures - - - On the ground - - - - - - In space - - - -

- savaka
- Scratcher

1000+ posts

### Power block

o wow u did itTHERE IS NO REAL WORKAROUNDHuh?

…though I still think it'd be quite nice to have the block, despite not being entirely clear where it'd go, since it feels like it should be part of the multichoice maths operators block (the one with the dropdown menu), but cannot go there 'cos it takes two args rather than one…

- Gaza101
- Scratcher

500+ posts

### Power block

Pretty sure this has been suggested before. It's freaking useful and I'm clueless as to why we don't yet have a block like this. Support.

- dvargasews
- Scratcher

500+ posts

### Power block

You forgot that fractional powers of negative roots are okay unless the denominator is even. Try this:OK, so here's my definitive x^y custom block… The thing is that you can't do negative numbers with logs.define result = (x) ^ (y)That should cover everything but non-integer powers of negative numbers (which gets a bit hairy…), and it makes sure that integer raised to integer gives exactly an integer (in case you assume you'll get an integer, perhaps because you check for equality with an integer at some point).

if <(y) = [0]> then

set [result v] to [1] // yes, we also include 0^0=1 :O

else

if <(x) = [0]> then

set [result v] to [0] // 0^y=0 for any y except zero (see above)

else

set [result v] to ([e ^ v] of ((y)*([ln v] of ([abs v] of (x))))) // no negative x for now

if <(x) < [0]> then // now deal with power of negative number

if <(round(y)) = (y)> then // we can do integer powers of negative numbers

if <((y) mod (2)) = [1]> then

set [result v] to ((0) - (result)) // odd powers will be negative

end

else

set [result v] to [NaN] // but let's not go there at this stage...

end

end

if <<(y) > [0]> and <<(round(x)) = (x)> and <(round(y)) = (y)>>> then

set [result v] to (round (result)) // ensure we get exactly an integer if both x & y were ints

end

end

end

Hope I've got that all right!

define result = (x) ^ (y)By the way, you use 0-x instead of -1*x too? What a coincidence!

if <(y) = [0]> then

set [result v] to [1] // yes, we also include 0^0=1 :O

else

if <(x) = [0]> then

set [result v] to [0] // 0^y=0 for any y except zero (see above)

else

set [result v] to ([e^ v] of ((y)*([ln v] of ([abs v] of (x)))) // no negative x for now

if <(x) < [0]> then // now deal with power of negative number

if <(round(y)) = (y)> then // we can do integer powers of negative numbers

if <((y) mod (2)) = [1]> then

set [result v] to ((0) - (result)) // odd powers will be negative

end

else

if <((round ((1) / ((1) GCF (y)))) mod (0)) = [0]> then // I won't bother doing a greatest common factor block, but you probably know how to make one.

set [result v] to [NaN] // but let's not go there at this stage...

else //y's denominator is odd.

set [Result v] to ((0) - ([e ^ v] of ((y)*([ln v] of ([abs v] of (x)))))

end

end

end

if <<(y) > [0]> and <<(round(x)) = (x)> and <(round(y)) = (y)>>> then

set [result v] to (round (result)) // ensure we get exactly an integer if both x & y were ints

end

end

end

*Last edited by dvargasews (Jan. 17, 2017 21:21:42)*

Please read my signature! It might explain some lingo that I used in my post or comment. However, not all of it shows, so you have to highlight the entire bottom of the post, from “Please read my signature!” to where it says report, and copy and paste in into a new sheet or tab or whatever.

I can't decide my signature between:

1. I'm a grammar stickler, and my pet peeve is when people use good as an adverb.

2. I have lots of [creativity]original ideas[/creativity]. [creativity]This[/creativity] is one of those ideas.

3. If I used this symbol: ⸮ in my comment, please look it up before doing anything else.

4. {Minot, North Dakota/Donald Trump parodies} “WE'RE GONNA BUILD A DAM AND MAKE CANADA PAY FOR IT!” “When Canada sends its water, they’re not sending their best drinking water…They’re bringing sleet. They’re bringing floods. The water's toxic.” (It's just a joke that I came up with.)

5. One should make his/her signature text small; that way (s)he can cram more text into the signature.

6. New [scratchblocks] idea each week! (Thanks to Bright-Idea (Read her signature.) for inspiration/the general idea.) Here's the archive:

Note: I stopped this because of signature character limits.

Week of 1-23-2017: Hat-caps tinyurl.com/htauyu2

Week of 1-16-2017: Country-colored scratchblocks tinyurl.com/z8lz6c4

Week of 1-9-2017: Drop-down booleans tinyurl.com/j5d3k6l

Week of 1-2-2017: Block->string inputs and more truth values tinyurl.com/jqu7avs

- DadOfMrLog
- Scratcher

1000+ posts

### Power block

Uhhhrrrmmm… I'd like to see you try to reliably do what you really need to do here (which is to find a fractional representation of y) with all the foibles of decimal numbers represented internally with binary floating-point… I won't bother doing a greatest common factor block, but you probably know how to make one.

Alternate account: TheLogFather –– HowTos and useful custom blocks (see studio). Examples below…

- String manipulation - - - X to power of Y - - - Clone point to clone - Detect New Scratcher - Speed tests studio -

- dvargasews
- Scratcher

500+ posts

### Power block

Sure, the numerator of y is the LCM of y and 1, and the denominator of y can be calculated by dividing the numerator by y, but it is also the reciprocal of the GCF of 1 and y because for all x and all y, LCM(x, y)*GCF(x, y)=x*y. This returns the numerator and denominator of y in standard form.Uhhhrrrmmm… I'd like to see you try to reliably do what you really need to do here (which is to find a fractional representation of y) with all the foibles of decimal numbers represented internally with binary floating-point… I won't bother doing a greatest common factor block, but you probably know how to make one.

*Last edited by dvargasews (Dec. 28, 2016 20:59:20)*

Please read my signature! It might explain some lingo that I used in my post or comment. However, not all of it shows, so you have to highlight the entire bottom of the post, from “Please read my signature!” to where it says report, and copy and paste in into a new sheet or tab or whatever.

I can't decide my signature between:

1. I'm a grammar stickler, and my pet peeve is when people use good as an adverb.

2. I have lots of [creativity]original ideas[/creativity]. [creativity]This[/creativity] is one of those ideas.

3. If I used this symbol: ⸮ in my comment, please look it up before doing anything else.

4. {Minot, North Dakota/Donald Trump parodies} “WE'RE GONNA BUILD A DAM AND MAKE CANADA PAY FOR IT!” “When Canada sends its water, they’re not sending their best drinking water…They’re bringing sleet. They’re bringing floods. The water's toxic.” (It's just a joke that I came up with.)

5. One should make his/her signature text small; that way (s)he can cram more text into the signature.

6. New [scratchblocks] idea each week! (Thanks to Bright-Idea (Read her signature.) for inspiration/the general idea.) Here's the archive:

Note: I stopped this because of signature character limits.

Week of 1-23-2017: Hat-caps tinyurl.com/htauyu2

Week of 1-16-2017: Country-colored scratchblocks tinyurl.com/z8lz6c4

Week of 1-9-2017: Drop-down booleans tinyurl.com/j5d3k6l

Week of 1-2-2017: Block->string inputs and more truth values tinyurl.com/jqu7avs

- JonathanSchaffer
- Scratcher

1000+ posts

### Power block

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

([10^ v] of ((y) * ([log v] of (x)))) // = x^y

do you like siri, alexa, cortana, or google assistant, but can't buy an iphone, echo, or google home?

then try alice!

alice is a wonderful virtual assistant that works on linux and is tested on raspberry pi*

she can play music, search online, answer questions, tell jokes, give you the date and time, and plenty of other things

then try alice!

alice is a wonderful virtual assistant that works on linux and is tested on raspberry pi*

she can play music, search online, answer questions, tell jokes, give you the date and time, and plenty of other things

*you may need to install additional software like python 2, libttspico-utils, and timidity

- DadOfMrLog
- Scratcher

1000+ posts

### Power block

I'm a bit confused by what you're trying to do here. Are your x & y integers? Sure, the numerator of y is the LCM of y and 1, and the denominator of y can be calculated by dividing the numerator by y, but it is also the reciprocal of the GCF of 1 and y because for all x and all y, LCM(x, y)*GCF(x, y)=x*y. This returns the numerator and denominator of y in standard form.

If so, how can LCM(1,y) be anything but y, and LCM(1,y) anything but 1?

If not… well… how are you defining LCM & GCF for non-integers?

But seriously, how are you going to turn an arbitrary floating-point value into a fraction (i.e. a/b where a & b are integers), preferably in its lowest form?

And once you do, and you still find that one of a or b is large (which is very likely), how are you going to raise some other arbitrary number to that power without it overflowing to Infinity, or underflowing to zero, due to double-precision floating-point's min/max bounds? (Guess you'll have to write your own code to do arbitrary-precision multiplication…)

*Last edited by DadOfMrLog (Dec. 30, 2016 09:58:53)*

Alternate account: TheLogFather –– HowTos and useful custom blocks (see studio). Examples below…

- String manipulation - - - X to power of Y - - - Clone point to clone - Detect New Scratcher - Speed tests studio -

- dvargasews
- Scratcher

500+ posts

### Power block

LCM and GCF can also work for non-integers because for any x and y, if c is a constant, then LCM(x/c, y/c)=LCM(x, y)/c, and GCF(x/c, y/c)=GCF(x, y)/c.I'm a bit confused by what you're trying to do here. Are your x & y integers? Sure, the numerator of y is the LCM of y and 1, and the denominator of y can be calculated by dividing the numerator by y, but it is also the reciprocal of the GCF of 1 and y because for all x and all y, LCM(x, y)*GCF(x, y)=x*y. This returns the numerator and denominator of y in standard form.

If so, how can LCM(1,y) be anything but y, and LCM(1,y) anything but 1?

If not… well… how are you defining LCM & GCF for non-integers?

But seriously, how are you going to turn an arbitrary floating-point value into a fraction (i.e. a/b where a & b are integers), preferably in its lowest form?

And once you do, and you still find that one of a or b is large (which is very likely), how are you going to raise some other arbitrary number to that power without it overflowing to Infinity, or underflowing to zero, due to double-precision floating-point's min/max bounds? (Guess you'll have to write your own code to do arbitrary-precision multiplication…)

The numerator of y is LCM(1, y), and the denominator of y is 1/(GCF(1, y)).

That won't be a problem because using the sliders, one can only set x and y to a multiple of 0.01.

Or to find the GCF of a and b for any numbers a and b, you could just do it the old-fashioned way (in terms of finding remainders instead of plugging it in to a calculator, which would be to make a block like this:

if <(a) = (b)> then

set [GCF v] to (a)

else

if <(a) > (b)> then

find the LCM of (a) and (b) :: custom

else

find the LCM and GCF of (b) and (a) :: custom

end

end

define find the LCM and GCF of (greater number) and (lesser number)

set [a v] to (greater number)//I like to reuse variables if I can, but if you need to save a or b, you may use other variables.

set [b v] to (lesser number)

repeat until <<(a) = [0]> or <(b) = [0]>>

set [a v] to ((a) mod (b))

if <(a) = [0]> then

set [GCF v] to (b)

else

set [b v] to ((b) mod (a))

if <(b) = [0]> then

set [GCF v] to (a)

end

end

end

set [LCM v] to (((greater number)*(lesser number))/(LCM))

*Last edited by dvargasews (Jan. 2, 2017 00:29:19)*

Please read my signature! It might explain some lingo that I used in my post or comment. However, not all of it shows, so you have to highlight the entire bottom of the post, from “Please read my signature!” to where it says report, and copy and paste in into a new sheet or tab or whatever.

I can't decide my signature between:

1. I'm a grammar stickler, and my pet peeve is when people use good as an adverb.

2. I have lots of [creativity]original ideas[/creativity]. [creativity]This[/creativity] is one of those ideas.

3. If I used this symbol: ⸮ in my comment, please look it up before doing anything else.

4. {Minot, North Dakota/Donald Trump parodies} “WE'RE GONNA BUILD A DAM AND MAKE CANADA PAY FOR IT!” “When Canada sends its water, they’re not sending their best drinking water…They’re bringing sleet. They’re bringing floods. The water's toxic.” (It's just a joke that I came up with.)

5. One should make his/her signature text small; that way (s)he can cram more text into the signature.

6. New [scratchblocks] idea each week! (Thanks to Bright-Idea (Read her signature.) for inspiration/the general idea.) Here's the archive:

Note: I stopped this because of signature character limits.

Week of 1-23-2017: Hat-caps tinyurl.com/htauyu2

Week of 1-16-2017: Country-colored scratchblocks tinyurl.com/z8lz6c4

Week of 1-9-2017: Drop-down booleans tinyurl.com/j5d3k6l

Week of 1-2-2017: Block->string inputs and more truth values tinyurl.com/jqu7avs

- IgnaxioScratcher
- Scratcher

68 posts

### Power block

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.

I quote this, like scratch team says, if a block has a workaround, it dont need reasons for not exist, it can be still used for make scratch easier, but if the workaround is too easy, it will be rejected

*Last edited by IgnaxioScratcher (Dec. 31, 2016 00:14:30)*

#BRINGITBACK RIP disscus button,

I love collabs! If you have one, please tell!

Please visit my collab Bus Musican Simulator!

Im also part of:

- DadOfMrLog
- Scratcher

1000+ posts

### Power block

Sorry, been busy with stuff over New Year, so not got around to replying to this – particularly since there's so much I could say in reply… LCM and GCF can also work for non-integers because for any x and y, if c is a constant, then LCM(x/c, y/c)=LCM(x, y)/c, and GCF(x/c, y/c)=GCF(x, y)/c.

The numerator of y is LCM(1, y), and the denominator of y is 1/(GCF(1, y)).

But I think I'll just ask if you've actually tried out that script you gave above with non-integer values? (BTW, it primarily calculates GCF, not LCM, so you could swap those variables to make that clear.)

It'll find the GCF for two integers, but I think if you try it with non-integers, and you investigate what's going on, then that will help explain why your argument above doesn't help solve the essential problem here – which is to find a rational representation for any given value, and so use that to perform the exponentiation by raising to the numerator, and taking the root for the denominator.

That won't be a problem because using the sliders, one can only set x and y to a multiple of 0.01.OK, if you're going to restrict the inputs to only values of the form int/100, then that does make things rather easy…

However, two problems here…

Firstly, I don't see the point of a custom block for x^y that's restricted in such a way – the whole idea of it is to try to make a general power block.

Secondly, it's not necessarily true that a slider is restricted like that – check out the ones in my power project, for example.

I had loads of other things to say about floating-point format in computers, and how they bring about some really interesting twists to all this…

But I've said enough already, so I'll just end by noting…

Happy New Year!

*Last edited by DadOfMrLog (Jan. 1, 2017 12:47:03)*

Alternate account: TheLogFather –– HowTos and useful custom blocks (see studio). Examples below…

- String manipulation - - - X to power of Y - - - Clone point to clone - Detect New Scratcher - Speed tests studio -

- dvargasews
- Scratcher

500+ posts

### Power block

I didn't test it for non-integers; I'm a theoretical mathematician, not a practical mathematician.Sorry, been busy with stuff over New Year, so not got around to replying to this – particularly since there's so much I could say in reply… LCM and GCF can also work for non-integers because for any x and y, if c is a constant, then LCM(x/c, y/c)=LCM(x, y)/c, and GCF(x/c, y/c)=GCF(x, y)/c.

The numerator of y is LCM(1, y), and the denominator of y is 1/(GCF(1, y)).

But I think I'll just ask if you've actually tried out that script you gave above with non-integer values? (BTW, it primarily calculates GCF, not LCM, so you could swap those variables to make that clear.)

It'll find the GCF for two integers, but I think if you try it with non-integers, and you investigate what's going on, then that will help explain why your argument above doesn't help solve the essential problem here – which is to find a rational representation for any given value, and so use that to perform the exponentiation by raising to the numerator, and taking the root for the denominator.

Also, I'm sure that my longer version would work for anything.

LCM and GCF can also work for non-integers because for any x and y, if c is a constant, then LCM(x/c, y/c)=LCM(x, y)/c, and GCF(x/c, y/c)=GCF(x, y)/c.I'm a bit confused by what you're trying to do here. Are your x & y integers? Sure, the numerator of y is the LCM of y and 1, and the denominator of y can be calculated by dividing the numerator by y, but it is also the reciprocal of the GCF of 1 and y because for all x and all y, LCM(x, y)*GCF(x, y)=x*y. This returns the numerator and denominator of y in standard form.

If so, how can LCM(1,y) be anything but y, and LCM(1,y) anything but 1?

If not… well… how are you defining LCM & GCF for non-integers?

But seriously, how are you going to turn an arbitrary floating-point value into a fraction (i.e. a/b where a & b are integers), preferably in its lowest form?

And once you do, and you still find that one of a or b is large (which is very likely), how are you going to raise some other arbitrary number to that power without it overflowing to Infinity, or underflowing to zero, due to double-precision floating-point's min/max bounds? (Guess you'll have to write your own code to do arbitrary-precision multiplication…)

The numerator of y is LCM(1, y), and the denominator of y is 1/(GCF(1, y)).

That won't be a problem because using the sliders, one can only set x and y to a multiple of 0.01.

Or to find the GCF of a and b for any numbers a and b, you could just do it the old-fashioned way (in terms of finding remainders instead of plugging it in to a calculator, which would be to make a block like this:if <(a) = (b)> then

set [GCF v] to (a)

else

if <(a) > (b)> then

find the LCM of (a) and (b) :: custom

else

find the LCM and GCF of (b) and (a) :: custom

end

end

define find the LCM and GCF of (greater number) and (lesser number)

set [a v] to (greater number)//I like to reuse variables if I can, but if you need to save a or b, you may use other variables.

set [b v] to (lesser number)

repeat until <<(a) = [0]> or <(b) = [0]>>

set [a v] to ((a) mod (b))

if <(a) = [0]> then

set [GCF v] to (b)

else

set [b v] to ((b) mod (a))

if <(b) = [0]> then

set [GCF v] to (a)

end

end

end

set [LCM v] to (((greater number)*(lesser number))/(LCM))

If you think about it, yours is restricted because it only works with real numbers, unlike mine. (Yes, I know that it's still buggy.)That won't be a problem because using the sliders, one can only set x and y to a multiple of 0.01.OK, if you're going to restrict the inputs to only values of the form int/100, then that does make things rather easy…

However, two problems here…

Firstly, I don't see the point of a custom block for x^y that's restricted in such a way – the whole idea of it is to try to make a general power block.

Secondly, it's not necessarily true that a slider is restricted like that – check out the ones in my power project, for example.

I had loads of other things to say about floating-point format in computers, and how they bring about some really interesting twists to all this…

But I've said enough already, so I'll just end by noting…

Also, I'm pretty sure that your sliders are restricted.

Happy New Year! http://tinyurl.com/ze7sm2c

*Last edited by dvargasews (Jan. 2, 2017 00:28:59)*

Please read my signature! It might explain some lingo that I used in my post or comment. However, not all of it shows, so you have to highlight the entire bottom of the post, from “Please read my signature!” to where it says report, and copy and paste in into a new sheet or tab or whatever.

I can't decide my signature between:

1. I'm a grammar stickler, and my pet peeve is when people use good as an adverb.

2. I have lots of [creativity]original ideas[/creativity]. [creativity]This[/creativity] is one of those ideas.

3. If I used this symbol: ⸮ in my comment, please look it up before doing anything else.

4. {Minot, North Dakota/Donald Trump parodies} “WE'RE GONNA BUILD A DAM AND MAKE CANADA PAY FOR IT!” “When Canada sends its water, they’re not sending their best drinking water…They’re bringing sleet. They’re bringing floods. The water's toxic.” (It's just a joke that I came up with.)

5. One should make his/her signature text small; that way (s)he can cram more text into the signature.

6. New [scratchblocks] idea each week! (Thanks to Bright-Idea (Read her signature.) for inspiration/the general idea.) Here's the archive:

Note: I stopped this because of signature character limits.

Week of 1-23-2017: Hat-caps tinyurl.com/htauyu2

Week of 1-16-2017: Country-colored scratchblocks tinyurl.com/z8lz6c4

Week of 1-9-2017: Drop-down booleans tinyurl.com/j5d3k6l

Week of 1-2-2017: Block->string inputs and more truth values tinyurl.com/jqu7avs