## Discuss Scratch

- DadOfMrLog
- Scratcher

1000+ posts

### Power block

You should test it. (TBH, though, it doesn't take that much thought to realise that it can't work – if you enter two numbers that are <=1, such as 1 and 0.01, then the “mod” operator can't give anything larger than what you put in – i.e. you certainly can't get an integer >1, which is what you want…) I didn't test it for non-integers; I'm a theoretical mathematician, not a practical mathematician.

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

If you think about it, yours is restricted because it only works with real numbers, unlike mine.

Yup, that's the best way to make it general – create a fully complex-compatible version.

If the user is expecting to work only with real numbers, though, then you'll have to look at the imaginary part and decide if it's ‘close enough’ to zero to return an ‘allowed’ (i.e. real) answer rather than “NaN”…

*Last edited by DadOfMrLog (Jan. 2, 2017 00:11:29)*

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

No because it returns the reciprocal of the denominator, which is less than one if the denominator is greater than one.You should test it. (TBH, though, it doesn't take that much thought to realise that it can't work – if you enter two numbers that are <=1, such as 1 and 0.01, then the “mod” operator can't give anything larger than what you put in – i.e. you certainly can't get an integer >1, which is what you want…) I didn't test it for non-integers; I'm a theoretical mathematician, not a practical mathematician.

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

Users can just enter 0 for the imaginary parts.If you think about it, yours is restricted because it only works with real numbers, unlike mine.

Yup, that's the best way to make it general – create a fully complex-compatible version.

If the user is expecting to work only with real numbers, though, then you'll have to look at the imaginary part and decide if it's ‘close enough’ to zero to return an ‘allowed’ (i.e. real) answer rather than “NaN”…

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

reciprocal of the denominator, which is less than one if the denominator is greater than one.Ah! I see what you're intending to do there now. No because it returns the

Yes, that has the right theory (assuming there is a rational representation). In practice I expect you'll start running into rounding error issues once the values of numerator and denominator become larger than a few hundred or so.

Besides, once the numerator or denominator gets too large, it'll likely overflow or underflow when you try to perform the power calculation by raising to the numerator power, or underflow by trying to take the denominator root.

Anyway, here's my attempt to find a fairly simple rational representation, based on your earlier script:

define Find fraction for (x)

if <((x) mod (1)) = [0]> then // check if it's already an integer

set [Denominator v] to [1]

set [Numerator v] to (x)

stop [this script v]

end

if <(x)<[0]> then // deal with negative case...

Find fraction for (()-(x)) // ...by finding positive fraction instead...

set [Numerator v] to (() - (Numerator)) // ...and negating top of it

stop [this script v]

end

set [tol v] to ((x)*(1e-10)) // tolerance for checking if fraction is (near enough) correct

set [a v] to [1]

set [b v] to ((x) mod (1)) // start with fractional part of x

forever // hopefully will get stopped by tests below...

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

set [Denominator v] to (round ((1)/(b)))

set [Numerator v] to (round ((x)/(b)))

if <([abs v] of ( (x)-((Numerator)/(Denominator)) )) < (tol)> then

stop [this script v] // the test above seemed to be the most effective way to check we have what we want

end

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

set [Denominator v] to (round ((1)/(a)))

set [Numerator v] to (round ((x)/(a)))

if <([abs v] of ( (x)-((Numerator)/(Denominator)) )) < (tol)> then

stop [this script v]

end

end

Above works quite nicely for many reasonably simple fractions. But rounding errors cause problems once the rational representation starts to have larger values on top and/or bottom.

Users can just enter 0 for the imaginary parts.No, I mean for the result, not the operands. I'm thinking of a custom block that only deals with reals here – and it only gives a non-NaN result if the answer is also real(ish).

(In practice, many Scratchers would not have much idea about complex numbers, and would simply want a custom block that has two slots, for two variables/expressions, and so those would be real-valued and they would expect it to give back a real value, if possible.)

*Last edited by DadOfMrLog (Jan. 2, 2017 10:46:50)*

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

You do realize that rational representation is only a way to get to exponential representation. There are others.reciprocal of the denominator, which is less than one if the denominator is greater than one.Ah! I see what you're intending to do there now. No because it returns the

Yes, that has the right theory (assuming there is a rational representation). In practice I expect you'll start running into rounding error issues once the values of numerator and denominator become larger than a few hundred or so.

Besides, once the numerator or denominator gets too large, it'll likely overflow or underflow when you try to perform the power calculation by raising to the numerator power, or underflow by trying to take the denominator root.

Anyway, here's my attempt to find a fairly simple rational representation, based on your earlier script:define Find fraction for (x)

if <((x) mod (1)) = [0]> then // check if it's already an integer

set [Denominator v] to [1]

set [Numerator v] to (x)

stop [this script v]

end

if <(x)<[0]> then // deal with negative case...

Find fraction for (()-(x)) // ...by finding positive fraction instead...

set [Numerator v] to (() - (Numerator)) // ...and negating top of it

stop [this script v]

end

set [tol v] to ((x)*(1e-10)) // tolerance for checking if fraction is (near enough) correct

set [a v] to [1]

set [b v] to ((x) mod (1)) // start with fractional part of x

forever // hopefully will get stopped by tests below...

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

set [Denominator v] to (round ((1)/(b)))

set [Numerator v] to (round ((x)/(b)))

if <([abs v] of ( (x)-((Numerator)/(Denominator)) )) < (tol)> then

stop [this script v] // the test above seemed to be the most effective way to check we have what we want

end

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

set [Denominator v] to (round ((1)/(a)))

set [Numerator v] to (round ((x)/(a)))

if <([abs v] of ( (x)-((Numerator)/(Denominator)) )) < (tol)> then

stop [this script v]

end

end

Above works quite nicely for many reasonably simple fractions. But rounding errors cause problems once the rational representation starts to have larger values on top and/or bottom.Users can just enter 0 for the imaginary parts.No, I mean for the result, not the operands. I'm thinking of a custom block that only deals with reals here – and it only gives a non-NaN result if the answer is also real(ish).

(In practice, many Scratchers would not have much idea about complex numbers, and would simply want a custom block that has two slots, for two variables/expressions, and so those would be real-valued and they would expect it to give back a real value, if possible.)

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

- dvargasews
- Scratcher

500+ posts

### Power block

This discussion is about powers. I was talking about powers of imaginary numbers. If you feel that what I was talking about was off-topic, then feel free to report this conversation for being off-topic, but I doubt that Paddle2See will agree with you (He seems to be the most active moderator on the forums.). ^

Maybe you could move the discussion about imaginary numbers off of this topic since it's getting a bit off-topic now?

Sigton

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

- PkmnQ
- Scratcher

100+ posts

### Power block

how is that simple? 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 should've used

change x by ()as the easy workaround block.

still, your point is good.

*Last edited by PkmnQ (May 27, 2017 09:05:54)*

Check out a sorting algorithm I discovered at school!

Or maybe, you can also check this odd vector detector.

- DIAMOND_77
- Scratcher

15 posts

### Power block

if you want to say do 3^3 you just do this: ((3)*(3) *(3)) just put an operator in an operator!

- dvargasews
- Scratcher

500+ posts

### Power block

But what if the power is variable? Like if you want to say do 3^3 you just do this: ((3)*(3) *(3)) just put an operator in an operator!

((2) ^ (number of lives left) ::operators reporter)? One could use a repeat block, but that wouldn't work for non-integer exponents, like

((2) ^ (batting average) ::operators reporter).

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

- Charles12310
- Scratcher

1000+ posts

### Power block

Workaround:

Alternatives:

define find (base)^(power)

set [number v] to (base)

repeat (([abs v] of (power)) - (1))

set [number v] to ((number) * (base))

end

if <(power) < (0)> then

set [number v] to ((1)/(number))

end

Alternatives:

([10^ v] of ((power) * ([log v] of (base))) :: operators )

([e^ v] of ((power) * ([ln v] of (base))) :: operators )

*Last edited by Charles12310 (July 23, 2017 03:54:23)*

Click This Link For Some Secrets About Me!

A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!

- dvargasews
- Scratcher

500+ posts

### Power block

The first only works with integer powers. Workaround:define find (base)^(power)

set [number v] to (base)

repeat ([abs v] of (power))

set [number v] to ((number) * (base))

end

if <(power) < (0)> then

set [number v] to ((1)/(number))

end

Alternatives:([10^ v] of ((power) * ([log v] of (base))) :: operators )

([e^ v] of ((power) * ([ln v] of (base))) :: operators )

The second only works with real numbers and gets inaccurate with small values.

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

- Jonathan50
- Scratcher

1000+ posts

### Power block

Scratch doesn't support imaginary numbers so it doesn't matter… The second only works with real numbers and gets inaccurate with small values.

- dvargasews
- Scratcher

500+ posts

### Power block

First of all, not directly…Scratch doesn't support imaginary numbers so it doesn't matter… The second only works with real numbers and gets inaccurate with small values.

Second, even though most Scratch members don't use imaginary numbers, they're still good for stuff like projecting 4D objects and quantum wave simulators.

Third, you still haven't addressed the part about how it gets inaccurate when working with really small numbers.

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

- Jonathan50
- Scratcher

1000+ posts

### Power block

not directly…I know you can use them in Scratch but Scratch still doesn't support them. First of all,

Second, even though most Scratch members don't use imaginary numbers, they're still good for stuff like projecting 4D objects and quantum wave simulators.Scratch doesn't support imaginary numbers, so they're a user data type and none of the primitive operations do or can be expected to work on them anyways

Third, you still haven't addressed the part about how it gets inaccurate when working with really small numbers.Yes, because that's an actual problem with the workaround and I didn't mean to address it.

- CodeBit
- Scratcher

70 posts

### Power block

I have been trying to graph functions with a project, and it appears that an object cannot move in a curve if moving towards the left. It only follows the instructions if the x position is greater than 0, but Scratch's left side of the screen has a negative x coordinate. Can anybody solve this? I have used the way using logarithms…

Currently the script can draw a curve this way:

Currently the script can draw a curve this way:

when green flag clicked

forever

change x by (1)

set [ base ] to (x position)

set [ power ] to [ 2 ]

set y to ((0.01) * ([ e^ v] of ((power) * [ ln v] of (base)))

pen down

end

*Last edited by CodeBit (Dec. 23, 2017 03:12:27)*

- CodeBit

- Charles12310
- Scratcher

1000+ posts

### Power block

I really think this idea would be very useful!

2. Logarithms are mostly taught starting at either the end of Middle school or at the beginning of secondary school.

No, there is a workaround.1. This workaround doesn't work with negative numbers. Adding a script to return the result for negative numbers adds more complexity to workarounds.([10^ v] of ((power) * ([log v] of (number))) :: operators )

Enough said.

2. Logarithms are mostly taught starting at either the end of Middle school or at the beginning of secondary school.

Click This Link For Some Secrets About Me!

A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!

- walkcycle
- Scratcher

500+ posts

### Power block

the Scratch's left side of the screen has a negative x coordinate. Can anybody solve this? abs operator makes a negative value positive

try

set [base v] to ([abs v] of (x position))

Help With Scripts for more problems (this is the suggestions forum)