Discuss Scratch

drmcw
Scratcher
1000+ posts

Could we please have an exponents 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 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
jvvg
Scratcher
1000+ posts

Could we please have an exponents block? ( ) ^ ( )

Lilifant7253 wrote:

You can do it like this too:
when gf clicked
set [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)



Professional web developer and lead engineer on the Scratch Wiki
Maybe the Scratch Team isn't so badWhy the April Fools' Day forum didn't work last year
savaka
Scratcher
1000+ posts

Could we please have an exponents 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?
savaka
Scratcher
1000+ posts

Could we please have an exponents 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.
mitchboy
Scratcher
1000+ posts

Could we please have an exponents block? ( ) ^ ( )

jvvg wrote:

Lilifant7253 wrote:

You can do it like this too:
when gf clicked
set [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.
drmcw
Scratcher
1000+ posts

Could we please have an exponents 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 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
DadOfMrLog
Scratcher
1000+ posts

Could we please have an exponents block? ( ) ^ ( )

mitchboy wrote:

jvvg wrote:

Lilifant7253 wrote:

You can do it like this too:
when gf clicked
set [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)



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 -

DadOfMrLog
Scratcher
1000+ posts

Could we please have an exponents 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)



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 -

Lilifant7253
Scratcher
1000+ posts

Could we please have an exponents block? ( ) ^ ( )

jvvg wrote:

Lilifant7253 wrote:

You can do it like this too:
when gf clicked
set [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 clicked
set [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)


I've reached the 1000+ post rank on wednesday, 11th Sept., 2013 18:29 (German time) / 12:29 (Eastern Standard Time)
Hi! I Iike helping others. So feel free to leave a question at my profile!

A-no-meep
Scratcher
100+ posts

Could we please have an exponents block? ( ) ^ ( )

This is a good idea.

[ v]
A dropdown to nowhere
mathfreak231
Scratcher
1000+ posts

Could we please have an exponents block? ( ) ^ ( )

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

I remember adding that thread as a citation on Solving Exponents

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


i have grown as a person. and ive grown, literally. none of my posts from before 2022 represent me accurately.
firedrake969_test
Scratcher
500+ posts

Could we please have an exponents 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.

;
mathfreak231
Scratcher
1000+ posts

Could we please have an exponents 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.

i have grown as a person. and ive grown, literally. none of my posts from before 2022 represent me accurately.
savaka
Scratcher
1000+ posts

Could we please have an exponents block? ( ) ^ ( )

mathfreak231 wrote:

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

I remember adding that thread as a citation on Solving Exponents

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)

scratchisthebest
Scratcher
1000+ posts

Could we please have an exponents 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
xlk
Scratcher
100+ posts

Could we please have an exponents 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?

savaka
Scratcher
1000+ posts

Could we please have an exponents block? ( ) ^ ( )

scratchisthebest wrote:

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
It's not simple. Scratch is supposed to be easy to use. Not everyone knows trigonometry.

xlk wrote:

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?
You could, but that would make less sense, and it's supposed to be easy to use.
scratchisthebest
Scratcher
1000+ posts

Could we please have an exponents block? ( ) ^ ( )

Which is the entire point of our posts.

Someone suggested “hurr use 2 logarihms” which is laughably slow, hard to use, and doesn't even always work.
Also one with a repeat block, which also is very slow and takes forever to enter in.

My trig junk has the same problem, but following their logic, it should be used because we can make it with existing blocks.

I am a Lava Expert
mitchboy
Scratcher
1000+ posts

Could we please have an exponents block? ( ) ^ ( )

Why would you even need a (() ^ ()) block other than a calculator (in which you could just use the workarounds)?

Oh, and you could just check if (exponent) < (0) for negative powers to work.

Last edited by mitchboy (Sept. 21, 2013 16:00:20)


Capsicum annuum.
firedrake969_test
Scratcher
500+ posts

Could we please have an exponents block? ( ) ^ ( )

scratchisthebest wrote:

Which is the entire point of our posts.

Someone suggested “hurr use 2 logarihms” which is laughably slow, hard to use, and doesn't even always work.
Also one with a repeat block, which also is very slow and takes forever to enter in.

My trig junk has the same problem, but following their logic, it should be used because we can make it with existing blocks.
Yea…

Most people learn exponents before they learn logarithms. I know I did.

Support for adding.

Alt account of Firedrake969.

Rocket II: A black and white bitmap space game!

I seek not fame, but education.

;

Powered by DjangoBB