Discuss Scratch

PawnMate314
Scratcher
38 posts

Exponents on Scratch

Hello!

I’m making a project that provides custom blocks that perform math operations not included with Scratch. So far, I have found methods of making factorials, nPr and nCr, and hyperbolic functions (sinh cosh and tanh). I would now like to find a rigorous method of performing exponents. I’m well aware that you can replace integer exponents with repeated multiplication (e.g. 2^3 = 2*2*2) and that negative exponents are the reciprocal of the the positive exponent (e.g. 2^-3 = 1/2^3), but I do not know a substitution for any real exponent using only Scratch blocks. Does anyone know a solution?

Thank you for answering my question. Have a great day!
indium13
Scratcher
4 posts

Exponents on Scratch

For x^y try

setx2toxrepeatysetxtox*x2

It's not the most efficient but it's the only way I can think of.

Last edited by indium13 (Feb. 15, 2023 00:32:33)

Spentine
Scratcher
1000+ posts

Exponents on Scratch

You can use various exponential identities to create exponents. I already have it memorized though.
e ^oflnofx*y
This calculates x ^ y.

Some others you might find helpful:

e ^oflnofx*1/y
y-th root of x

lnofx/lnofy
log y (x)

The thing is, although works for positive real numbers, negatives mess it up. This is because the graph will seep into the c o m p l e x p l a n e.

-1 ^ 1.5
= sqrt(-1 ^ 3)
= sqrt(-1)
= i

Last edited by Spentine (Feb. 15, 2023 01:57:04)

PawnMate314
Scratcher
38 posts

Exponents on Scratch

Wow! Thank you so much! I wasn’t aware of this property of logarithms.

Have a good day!

lion334
Scratcher
100+ posts

Exponents on Scratch

indium13 wrote:

For x^y try

setx2toxrepeatysetxtox*x2

It's not the most efficient but it's the only way I can think of.
Woah! Think this might work. Personally I'd have used custom blocks (but in the same way), but this should work the same…

Powered by DjangoBB