ID:157335
 
As the title states, how can I square or cube a number in Byond? I thought it was ** but perhaps I am wrong. Thanks.
DisturbedSixx wrote:
As the title states, how can I square or cube a number in Byond? I thought it was ** but perhaps I am wrong. Thanks.

** is the exponent operator.

n**2 will give you the square of n, but n*n is faster.
n**3 wil lgive you the cube, but n*n*n is probably still faster.
In response to Lummox JR (#1)
I am pretty confused now. Heres an equation:

1.2(Current Level)^3 - 15(Current Level)^2 + 100(Current Level) - 140

Now, if I set Current Level to 100, by my math, it should equal 1,059,860. But when I do the following in DM:

1.2*P.Lvl*P.Lvl*P.Lvl-15*P.Lvl*P.Lvl+100*P.Lvl-140

It shows me an output of 1.08956...

Why?
In response to DisturbedSixx (#2)
Was there an E (representing scientific figure: [X]E[Y] = X *10^Y)? Because it sounds like there is.

And this is how you put that formula in BYOND (though the method you did is correct as well):
1.2*P.Lvl**3 - 15*P.Lvl**2 + 100*P.Lvl - 140
In response to GhostAnime (#3)
There is no E as far as I can see and both of our equations result in that 1.05986... result. I have no clue why.
In response to DisturbedSixx (#4)
tested and it came as 1.05986e+006

To work around scientific notation use num2text when displaying to users. - the 25 is how many significant digits we want to display.

mob
verb
check(Lvl as num)
src << num2text(1.2*Lvl**3 - 15*Lvl**2 + 100*Lvl - 140, 25)
In response to Pirion (#5)
Thank you very much. I didn't realize it was showing the number in that form since it didn't completely fit on the label.