Discuss Scratch
- OmnipotentPotato
-
Scratcher
1000+ posts
Powers
Repeat something negative times?define (Num1) ^ (Num2)
if <(Num2) > (0)> then
repeat (Num2)
set [output v] to ((output) * (Num1))
end
else
repeat ((0) - (Num2))
set [output v] to ((output) * (Num1))
end
end
- stickfiregames
-
Scratcher
1000+ posts
Powers
if num2 is not greater than 0, then 0 - num2 is positive.Repeat something negative times?define (Num1) ^ (Num2)
if <(Num2) > (0)> then
repeat (Num2)
set [output v] to ((output) * (Num1))
end
else
repeat ((0) - (Num2))
set [output v] to ((output) * (Num1))
end
end
It still won't give the right answer though.
- OmnipotentPotato
-
Scratcher
1000+ posts
Powers
Oh, my math teacher would be crying right now.if num2 is not greater than 0, then 0 - num2 is positive.Repeat something negative times?define (Num1) ^ (Num2)
if <(Num2) > (0)> then
repeat (Num2)
set [output v] to ((output) * (Num1))
end
else
repeat ((0) - (Num2))
set [output v] to ((output) * (Num1))
end
end
It still won't give the right answer though.
- MegaApuTurkUltra
-
Scratcher
1000+ posts
Powers
define (b) ^ (p)There
if<(p)=(0)>
if<(b)=(0)>
set [output v] to [undefined]
else
set [output v] to (1)
end
else
set [output v] to (1)
repeat([floor v] of ([abs v] of (p)))
set [output v] to ((output)*(b))
end
if<not<([floor v] of ([abs v] of (p)))=([abs v] of (p))>>
run nth root thingy here::custom
set [output v] to ((output)*(result of nth root thingy))
end
if<(p) < (0)>
set [output v] to ((1)/(output))
end
end
- Zambonifofex
-
Scratcher
100+ posts
Powers
Derp.Nope. First of all, base and power should be switched. Second of all, that doesn't work with negative bases.([e ^ v] of ((base) * ([ln v] of (power))))or([10 ^ v] of ((base) * ([log v] of (power))))
((<(base) > [0]> * ([e ^ v] of (([ln v] of (base)) * (power)))) + (<(base) < [0]> * (((((power) mod (-2)) * (2)) + (1)) * ([e ^ v] of (([ln v] of ([abs v] of (base))) * (power))))))This should work, even if it is cheaty, ugly and slow… (except for 0 ^ 0)
But yeah, I support () ^ (), but it already have been suggested multiple times…
Last edited by Zambonifofex (Nov. 12, 2014 18:58:07)
- GyroscopeBill
-
Scratcher
500+ posts
Powers
ʇɹoddns!troppuSSupport!SupportSupport. Why doesn't this exist yet?Support.Support, even though it has been suggested innumerable times before.SupportSupport, although it has been suggested before.(+1)
I think it should look like(() ^ () :: operators)it is probably more recognised than **
Support!
- Think_Quest
-
New Scratcher
14 posts
Powers
sry, doesn't look like it'll work:define (Num1) ^ (Num2)
if <(Num2) > (0)> then
repeat (Num2)
set [output v] to ((output) * (Num1))
end
else
repeat ((0) - (Num2))
set [output v] to ((output) * (Num1))
end
end
2 ^ -1 = 0.5
not 2*2
- TheLogFather
-
Scratcher
1000+ posts
Powers
doesn't look like it'll work:All that needs to fix it is an extra “set output to 1/output” after the second repeat.
2 ^ -1 = 0.5
not 2*2
Still won't work for non-integer powers, of course…
Zambonifofex's long expression is quite decent for the range in which it works (base>0 with any power, or base<0 with integer powers), though it might trip you up if you're expecting an integer when both base & power are ints.
Since that did cause an issue for some Scratchers when using the “e^ with ln( )” method (or “10^ with log( )”), that's why I wrote my general version in the way I did (plus that power-of-ten ‘fix’).
Last edited by TheLogFather (Nov. 13, 2014 17:13:28)
- FIoer
-
New Scratcher
3 posts
Powers
!troppuSSupport!SupportSupport. Why doesn't this exist yet?Support.Support, even though it has been suggested innumerable times before.SupportSupport, although it has been suggested before.(+1)
I think it should look like(() ^ () :: operators)it is probably more recognised than **
Support!
- FIoer
-
New Scratcher
3 posts
Powers
(No Support) ^ 1Why don't you support?
NOOOOOOOOOOOO! 120 seconds! Why…
- OmnipotentPotato
-
Scratcher
1000+ posts
Powers
Get nerdy. Anything squared is positive (sort of). So, he supports.(No Support) ^ 1Why don't you support?
NOOOOOOOOOOOO! 120 seconds! Why…
- MegaApuTurkUltra
-
Scratcher
1000+ posts
Powers
I'm confused. Shouldn't it be -(no support) or (no support)^(-1)?Get nerdy. Anything squared is positive (sort of). So, he supports.(No Support) ^ 1Why don't you support?
NOOOOOOOOOOOO! 120 seconds! Why…
x^1 = x for any x, so (no support)^1 = no support
- OmnipotentPotato
-
Scratcher
1000+ posts
Powers
Wait a second……. I was thinking (no support)^2I'm confused. Shouldn't it be -(no support) or (no support)^(-1)?Get nerdy. Anything squared is positive (sort of). So, he supports.(No Support) ^ 1Why don't you support?
NOOOOOOOOOOOO! 120 seconds! Why…
x^1 = x for any x, so (no support)^1 = no support
because no support = -support
-support^2 = support * support aka A lot of support.
- Prinseskat
-
Scratcher
1000+ posts
Powers
Joining the “Support!” chain.!troppuSSupport!SupportSupport. Why doesn't this exist yet?Support.Support, even though it has been suggested innumerable times before.SupportSupport, although it has been suggested before.(+1)
I think it should look like(() ^ () :: operators)it is probably more recognised than **
Support!
- RalphMath
-
New Scratcher
27 posts
Powers
This is one I came up with that I think handles everything:
define Raise (value) to (power)
if <((value) < [0]) and (((power) mod [1]) > [0]) > then // for real results with negative values, the powers have to be integers
set [answer v] to [ ] // imaginary result, set answer to empty
else
set [answer v] to ([e^ v] of ((power) * ([ln v] of ([abs v] of (value)))) // power * ln(value) gives ln of answer, use e^ to get answer value
if (((value) < [0]) and (((power) mod [2]) = [1])) then // check if value was negative, if so odd powers give negative answer
set [answer v] to ((answer) * [-1]) // flip sign for odd powers
end
end
- samanyolu
-
Scratcher
1000+ posts
Powers
Support :3ʇɹoddns!troppuSSupport!SupportSupport. Why doesn't this exist yet?Support.Support, even though it has been suggested innumerable times before.SupportSupport, although it has been suggested before.(+1)
I think it should look like(() ^ () :: operators)it is probably more recognised than **
Support!
Last edited by samanyolu (Nov. 15, 2014 08:04:17)
- theonlygusti
-
Scratcher
1000+ posts
Powers
Please fix your post to look like this:
(()^()::operators)
Last edited by theonlygusti (Nov. 15, 2014 10:53:30)
















