mitchboy wrote:

jvvg wrote:

Lilifant7253 wrote:

You can do it like this too:

when gf clicked

set [variable1 v] to (1)

repeat (y)

set [variable1 v] to ((variable1) * (x))

That doesn't work for negative or non-integer powers, though.

It actually does. Check out my project to test non-integer numbers. I don't think it works with negatives.

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^y

or

([e^ v] of ((y) * ([ln v] of (x))) // = x^y

may 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…