Game Development Community

Exponent Math in TorqueScript

by David Higgins · in Torque Game Builder · 03/13/2007 (8:48 pm) · 1 replies

Ok, I went on the assumption that something like:

32/(2^(10-1))

would produce the value "0.0625"

or that "10^2" would produce the value "100"

This assumption was DEAD wrong, since ^ is a bitwise XOR operator, and now I'm dumbfounded to find out that TorqueScript does not have an exponent operator?

I'm no math genius, and I don't even try to claim to be one ... I had a friend give me an equation that would produce the results I was looking for, and now i can't figure out how to get TorqueScript to do it ...

Can I fake the 'power of', sure ... I can write a mPower() function in TorqueScript that just loops for me ... or I can tweak the C++ and add an mPower() function ... but I'd like to keep this completely script based, and errm ... a loop to perform "power of" functionality seems silly ...

Does anyone have any better solution for the above equation, "32/(2^(10-1))"

Basically, given the value 32, I want to get 0.0625 (or 0.062) back ... given the value 128, I want to get 0.250 ...

#1
03/13/2007 (9:25 pm)
I'm pretty sure there's a mPow(x,y) function that will do x^y....