Discuss Scratch
- Discussion Forums
- » Suggestions
- » Could we please have an exponents block? ( ) ^ ( )
- jvvg
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
That doesn't work for negative or non-integer powers, though. You can do it like this too:when gf clicked
set [variable1 v] to (1)
repeat (y)
set [variable1 v] to ((variable1) * (x))
Last edited by jvvg (Sept. 11, 2013 17:39:29)
- savaka
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
Does this work for all negatives and decimals? You can use logarithms to do that.([10^ v] of ((y) * ([log v] of (x))) // = x^y
- savaka
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
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.
- mitchboy
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
It actually does. Check out my project to test non-integer numbers. I don't think it works with negatives.That doesn't work for negative or non-integer powers, though. You can do it like this too:when gf clicked
set [variable1 v] to (1)
repeat (y)
set [variable1 v] to ((variable1) * (x))
Last edited by mitchboy (Sept. 11, 2013 21:42:01)
- drmcw
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
You can't make x negative.Does this work for all negatives and decimals? You can use logarithms to do that.([10^ v] of ((y) * ([log v] of (x))) // = x^y
- DadOfMrLog
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
It actually does. Check out my project to test non-integer numbers. I don't think it works with negatives.That doesn't work for negative or non-integer powers, though. You can do it like this too:when gf clicked
set [variable1 v] to (1)
repeat (y)
set [variable1 v] to ((variable1) * (x))
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^yor
([e^ v] of ((y) * ([ln v] of (x))) // = x^ymay 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)
- DadOfMrLog
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
You can't make x negative.Does this work for all negatives and decimals? You can use logarithms to do that.([10^ v] of ((y) * ([log v] of (x))) // = x^y
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)
- Lilifant7253
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
Yes, you're right you've to do it like this. (but y has to be integer):That doesn't work for negative or non-integer powers, though. You can do it like this too:when gf clicked
set [variable1 v] to (1)
repeat (y)
set [variable1 v] to ((variable1) * (x))
when gf clicked
set [variable1 v] to (1)
repeat ([amount v] of (y))
set [variable1 v] to ((variable1) * (x))
if <(y) < (0)>Of course there shouldn't be the leak between the repeat and the if block.
set [variable1 v] to ((1) / (variable1))
Last edited by Lilifant7253 (Sept. 14, 2013 16:10:19)
- A-no-meep
-
100+ posts
Could we please have an exponents block? ( ) ^ ( )
This is a good idea.
- mathfreak231
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
Sorry, but http://scratch.mit.edu.ezproxyberklee.flo.org/discuss/topic/9907/ .
I remember adding that thread as a citation on Solving Exponents…
I remember adding that thread as a citation on Solving Exponents…
Last edited by mathfreak231 (Sept. 16, 2013 21:50:54)
- firedrake969_test
-
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.
And why would you add it as a citation? It doesn't accept OR deny the block.
- mathfreak231
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
It shows that at least 1 scratcher supports it. 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.
And I meant it as something that has already been suggested.
- savaka
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
http://scratch.mit.edu.ezproxyberklee.flo.org/discuss/topic/9907/ .Sorry, but
I remember adding that thread as a citation on Solving Exponents…
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.
I don't understand what you're talking about.It shows that at least 1 scratcher supports it. 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.
And I meant it as something that has already been suggested.
Last edited by savaka (Sept. 21, 2013 11:14:27)
- scratchisthebest
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
by this logic, we can remove “move (10) steps”
why not just use
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
- xlk
-
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?
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
-
1000+ posts
Could we please have an exponents block? ( ) ^ ( )
It's not simple. Scratch is supposed to be easy to use. Not everyone knows trigonometry. by this logic, we can remove “move (10) steps”
why not just usego to x: ((x position) + ([cos v] of ((direction)*(amt)))) y ((x position) + ([sin v] of ((direction)*(amt))))i mean jeez so simple
You could, but that would make less sense, and it's supposed to be easy to use. 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?
- scratchisthebest
-
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.
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.
- mitchboy
-
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.
Oh, and you could just check if (exponent) < (0) for negative powers to work.
Last edited by mitchboy (Sept. 21, 2013 16:00:20)
- firedrake969_test
-
500+ posts
Could we please have an exponents block? ( ) ^ ( )
Yea… 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.
Most people learn exponents before they learn logarithms. I know I did.
Support for adding.
- Poemon1_REMIX
-
100+ posts
Could we please have an exponents block? ( ) ^ ( )
when GF clickedTry that.
set [x v] to [0]
set [y v] to [0]
repeat (y)
set [x v] to ((x) * (y))
end
- Discussion Forums
- » Suggestions
-
» Could we please have an exponents block? ( ) ^ ( )