2.5(x) * (x^2)
X=src.Level
How would i put this into byond, and make it follow order of operations?
I assume: 2.5*(src.Level)*(src.Level^2) ?
would that follow order of operations?
I'd like X^2 first, then 2.5*X then [2.5X(X^2)]
The Answer (if my math isnt a failure) should be [2.5X^3]
Example: Level 5 would be 312.5 Exp.
Does
2.5*(src.Level)*(src.Level^2) ? in byond = 2.5(x) * (x^2)
ID:155192
![]() Aug 22 2011, 10:16 am
|
|
Close.
You can't just do 2.5X and expect the compiler to interpret that as multiplication. You need to explicitly put 2.5 * X. |
well,Yes obviously.
X is just the stand in for whatever level is being applied. A number with a variable next to it is implied multiplication. 10X = 10 * X, so i would type out 10 * src.Level Understand what I mean? So I'm assuming based off of what you've told me That I would take (2.5X)*X*X Ofcourse if its following order of operations then there is no need for () i'm guessing i'd just write it like so: 2.5*src.Level*(src.Level**2) if level 50 this would equal 312500 in byond right? |
I tested it and the result is indeed 312500.
mob |
As I said. (If you checked the reference link at all. Seriously people need to stop skipping these links. You're asking ridiculously simple questions that are quite easily explained if you stopped for a second and read the reference.)
BYOND follows the regular order of operations, so you don't need the parentheses. And you don't have to ask me if that's the number you'd get. You can check it yourself by making a simple test verb: #define SQR(X) ( (X) * (X) ) |
See here.
However, that code won't do what you expect. The caret (^) is the bitwise exclusive or operator. The exponent operator is '**' in DM.
[EDIT]
And, if you are simply squaring an object, it's better to do X * X rather than X ** 2. (Multiplication is a much more efficient operation for the computer to do than an exponential operation.) The same could apply to cubing, etc. (e.g. Use X * X * X instead of X ** 3.)