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

id: 2860

category: Suggestions

posts: 492

illusionist illusionist loading
Could we please have an exponents block?

Right there in operators with the other math blocks:

( ) + ( )
( ) - ( )
( ) / ( )
( ) * ( )
( ) ^ ( ) <———

It can't take more than a few seconds to add, can't it?
Hardmath123 Hardmath123 loading
+1 This is totally worth it!
this would be so cool! +1
+1. Although I think there is a workaround.
Wes64 Wes64 loading
i made one

its not perfect but it works.
OrcaCat OrcaCat loading

Wes64 wrote:

i made one

its not perfect but it works.
It also isn't a reporter block

Is it possible to hack a reporter block?
bobbysq bobbysq loading

OrcaCat wrote:

Wes64 wrote:

i made one

its not perfect but it works.
It also isn't a reporter block

Is it possible to hack a reporter block?
It used to be somewhat possible. Then it was fixed. You would just put %(something) in a variable but I forgot how it worked or if it did anything at all.
lunaluvgood lunaluvgood loading
+1
but while you are at it, add a square root block.
lalala3 lalala3 loading

lunaluvgood wrote:

+1
but while you are at it, add a square root block.
There is already one in there.
ImagineIt ImagineIt loading

Wes64 wrote:

i made one

its not perfect but it works.
That doesn't work with negatives.
OrcaCat OrcaCat loading

lalala3 wrote:

lunaluvgood wrote:

+1
but while you are at it, add a square root block.
There is already one in there.


And if there wasn't, do (x)^(0.5)
Nothing is permanent.
There is a workaround.
I'll try to express it without scratchblocks.

(10 ^ ) of (log(2) * (10))
where you're finding 2^10


Square roots: (and any roots)

(10 ^) of (log(8) / (3))
where you're finding the cube root of 8


obviously these do not work with exponents or roots of zero.

anyway I still +1 this block
IanSan5653 IanSan5653 loading
+100! This seems so simple, yet essential.
Wes64 Wes64 loading

OrcaCat wrote:

Wes64 wrote:

i made one

its not perfect but it works.
It also isn't a reporter block
it doesn't need to be you still get the number you need.
OrcaCat OrcaCat loading

Wes64 wrote:

OrcaCat wrote:

Wes64 wrote:

i made one

its not perfect but it works.
It also isn't a reporter block
it doesn't need to be you still get the number you need.
Yeah, true.

But I still can't wait until custom reporters.
Nothing is permanent.
OrcaCat OrcaCat loading

veggieman001 wrote:

veggieman001 wrote:

ImagineIt wrote:

Wes64 wrote:

i made one

its not perfect but it works.
That doesn't work with negatives.
That's because negative numbers don't have real square roots and Scratch doesn't support complex numbers.
Disregard this post, I thought you said the sqrt block didn't work with negatives (probably thought you were quoting the post above yours)
Yeah… I wasn't sure what the relationship of Natural Log and e was. But I thought it was something with square roots because of what you said.

Lol. I could've just done this.
( ( var ) ^ ( var ) )
PPPPPPPLLLLLLLLLLLLLZZZZZZZZZZZZ!!!!!!!!!!!!!!!!!!!
dracae dracae loading
I support.
(EDIT: There's a workaround though, so…)
But what if we wanted to do x^50 or something? Why use 50 blocks when you could use 1?
EDIT: Support (though I started this post topic, so…)
mitchboy mitchboy loading

8solarplanets wrote:

But what if we wanted to do x^50 or something? Why use 50 blocks when you could use 1?
You wouldn't need 50 blocks. I'm currently working on a x^y custom block right now, if you're interested.
Thanks. (I have Scratch 2.0, never heard of 1.4…)
dracae dracae loading

8solarplanets wrote:

Thanks. (I have Scratch 2.0, never heard of 1.4…)
There's some log things that works…
But what if we wanted, for example 84 ^ 59? There's no block for that.
mitchboy mitchboy loading

8solarplanets wrote:

But what if we wanted, for example 84 ^ 59? There's no block for that.
There now is.

This project.

EDIT: 84 ^ 59 = 3.40782965354148e+113. Boom.
But I wanted a block that you could link to other blocks, not a project.
EDIT: An operator block.
mitchboy mitchboy loading

8solarplanets wrote:

But I wanted a block that you could link to other blocks, not a project.
EDIT: An operator block.
You can go see inside, drag the custom block script into your backpack, and boom! You now have a x ^ y block! (Note: requires a variable named Result.)
…I want it implemented so that EVERY SCRATCH USER can have one, not just the code geeks.
kayybee kayybee loading

8solarplanets wrote:

But what if we wanted, for example 84 ^ 59? There's no block for that.
Actually, that's not the problem. You can do set X to 1, and repeat {set X to X*84} 59 times.

The problem is like 84^(pi) or stuff. You can't repeat something pi times.

So we use logs.

But younger scratchers might not know logs, and you can't create custom returning values right now, so this would be good.

But saying PPPPPPPPLLLLLLLLLZZZZZZZ just makes you seem immature, so it's not the greatest idea to put that in your suggestion.
It's like a demand, e.g. I WANT CAKE AND IF I DO NOT GET 49620672093657 SLICES I WILL GO ON STRIKE AND AVOID WORK!!!!!!!!!!!
Calm down, please. What you ask is already suggested before several times. And don't worry, I'm sure at some point they'll add the exponent block.

The workarounds goes like this:
//short version
x ^ y = 10 ^ (y * log x)

//long version
if y = 0
set x = 1
else
tempx = x
repeat (y - 1)
x = x * tempx
kayybee kayybee loading

ProdigyZeta7 wrote:

Calm down, please. What you ask is already suggested before several times. And don't worry, I'm sure at some point they'll add the exponent block.

The workarounds goes like this:
//short version
x ^ y = 10 ^ (y * log x)

//long version
if y = 0
set x = 1
else
tempx = x
repeat (y - 1)
x = x * tempx

your “long version” workaround isn't really the same as te short version.

The short version works for all real numbers, the long one doesn't.
mitchboy mitchboy loading

kayybee wrote:

The short version works for all real numbers, the long one doesn't.
Actually, 3.14 ^ 3.14 results in 30.959 on my custom block (about seven posts above). Try it. It just doesn't work with negative numbers or fractions. And my project barely involves any heavy scripting or math at all. All you need is:
- three variables
- a repeat block
- a subtraction and a multiplication block
- a set variable block

That's it. It took me like two minutes.
Photoguy77 Photoguy77 loading
I certainly support this!
RalphMath RalphMath loading
Please, please, please add this as an operator just like +-*/ it's a real limitation when teaching a lot of math concepts not to have exponentiation.
Iditaroid Iditaroid loading

RalphMath wrote:

Please, please, please add this as an operator just like +-*/ it's a real limitation when teaching a lot of math concepts not to have exponentiation.
I know this is technically necroposting but you raise a good point! An exponent block would certainly make things easier for teachers working with Scratch!
Cyoce Cyoce loading
Support
((0) ^ (0) :: operators)
Support, even though
((base) ^ (log) :: operators)
is exactly the same as
([10^ v] of ((log) * ([log v] of (base) :: operators)) :: operators)
Cyoce Cyoce loading

mitchboy wrote:

8solarplanets wrote:

But what if we wanted, for example 84 ^ 59? There's no block for that.
There now is.

This project.

EDIT: 84 ^ 59 = 3.40782965354148e+113. Boom.
That project doesn't work. It doesn't even work for all integers, let alone decimals. Not sure how to get exponents for decimals, but here's how it works for integers:
define exponentify (x), (y)
set [result v] to [1]
if <(y) > [0]> then
repeat (y)
set [result v] to ((result) * (x))
end
else
repeat (y)
set [result v] to ((result) / (x))
lalala3 lalala3 loading
Like so:

theonlygusti wrote:

Support, even though
((base) ^ (log) :: operators)
is exactly the same as
([10^ v] of ((base) * ([log v] of (log) :: operators)) :: operators)
Well, not really. The “base” and the “log” should be switched, but whatever. The problem with this is that the very idea that one might be forced to do this is fundamentally absurd for reasons that should be clear to anyone who's learned about logarithmic functions in math class.
lalala3 lalala3 loading

Iditaroid wrote:

RalphMath wrote:

Please, please, please add this as an operator just like +-*/ it's a real limitation when teaching a lot of math concepts not to have exponentiation.
I know this is technically necroposting but you raise a good point! An exponent block would certainly make things easier for teachers working with Scratch!
No. Technically, it's only necroposting if the topic has been resolved. It's just that people don't think and instead pull out their torches and pitchforks whenever someone posts on an old thread, regardless of whether the topic has actually been resolved, so the word (as well as the concept) has become depreciated.
lalala3 lalala3 loading
Reposting from another thread, because it's relevant:

lalala3 wrote:

I just figured out something. Neither of the workarounds are perfect. The one using loops has issues with raising numbers to negative or fractional powers, while the other workaround (using logs) doesn't work if the base isn't positive. I thus propose the following solution:
Define (base) ^ (exponent)
if <(base :: custom) > (0)> then
set [answer v] to ([10 ^ v] of ((exponent) * ([log v] of (base))))
else
if <((exponent) mod (1)) = (0)> then
set [answer v] to [1]
repeat ([abs v] of (exponent))
set [answer v] to ((answer) * (base))
end
if <(exponent) < (0)> then
set [answer v] to ((1)/(answer))
end
else
set [answer v] to [undefined]
end
end
Can we have a proper exponent block now? Please?
RalphMath RalphMath loading

mitchboy wrote:

kayybee wrote:

The short version works for all real numbers, the long one doesn't.
Actually, 3.14 ^ 3.14 results in 30.959 on my custom block (about seven posts above). Try it. It just doesn't work with negative numbers or fractions. And my project barely involves any heavy scripting or math at all. All you need is:
- three variables
- a repeat block
- a subtraction and a multiplication block
- a set variable block

That's it. It took me like two minutes.
Well, the actual value of 3.14 ^ 3.14 is approximately 36.3378. Anyone considering writing an exponentiation block really needs to understand how logarithms and powers work.
RalphMath RalphMath loading
Here's my attempt, it might be a bit faster for large negative exponents since it doesn't loop.

define exp (value, power)
if <<[value] < [0 ]> and << [power] mod [1]> > [0]>> then
set [answer] to [ ]
else
set [answer] to ([e^ v] of ([power] * ([ln v] of ([abs v] of [value])))
if <([value] < [0]) and (([power] mod [2]) = [1])> then
set [answer] to ([answer] * [-1])
end
Lets keep the spam down.

As for the suggestion, I would support. It would not be very easy using those
(((((((((...) * (0)) * (0)) * (0)) * (0)) * (0)) * (0)) * (0)) * (0))
blocks…
Tymewalk Tymewalk loading
Support. There's no reason not to have this, seeing as how the workarounds (even just multiplying several times) get out of hand quickly.
If this is going to be the ‘official’ exponent suggestion topic, then I guess I'd better make sure there's a link to this in here:


- https://scratch.mit.edu/projects/16871883/ -

Note the features, which deal with some of the issues mentioned here when using the e^/ln workaround.