Absolute Value

Chris B

New Member
Reaction score
7
Does anyone know how to find the absolute value of a number?

I can, of course, say something like this:
if number < 0
set number = number - number * 2 (EX: -5 - (-10) = -5 + 10 = 5)
endif

But if there's a way to just find the absolute value, that'd be so much easier.

-Chris
 

Chris B

New Member
Reaction score
7
oh yea, it's late lol, all I need to do is have -number. Thanks Troll, didn't think the WE would make it that simple :p I mean, not like this is hard, but the way I have it set out, it makes it a huge pain. Oh well.

-Chris
 

Chris B

New Member
Reaction score
7
Nice Chocobo, didn't even think about that! Thanks for both responses, I aprreciate it :)

One thing though, I've been wondering, is it safe to have equations while initiating a variable, or should I initialize and then set later? Late, does it matter whether I have either of these two?

local real DistX = sqrt((X2-X1)^2)
or
local real DistX
set DistX = sqrt((X2-X1)^2) ?

BTW, I'm sure my syntax in the arithmetic is off, but just setting an example :p

-Chris
 

saw792

Is known to say things. That is all.
Reaction score
280
It's perfectly safe to initialise a variable at declaration.
 

Akolyt0r

New Member
Reaction score
33
i think a custom abs function would be faster than that power squareroot stuff...
..
if a > 0 then
return a
else
return -a
endif
...
 

Akolyt0r

New Member
Reaction score
33
but when calling it 100000 times you will see squrt(x^2) is about 35% slower (i did some benchmarking -.-)
but you are right it doesnt matter xD<
 

Chris B

New Member
Reaction score
7
but when calling it 100000 times you will see squrt(x^2) is about 35% slower (i did some benchmarking -.-)
but you are right it doesnt matter xD<

lol, considering it won't even be used 100 times at once, and it takes a fraction of a second, and is only a fraction slower, it doesn't matter :p

-Chris
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top