|
... I'm sure it's simple, but I have an excuse! I haven't been scripting all summer :) |
|
|
Of course, I mean aside from a series of if statements checking to see if it's greater than 0, preferably. |
|
instawinJoin Date: 2013-06-04 Post Count: 8777 |
if num < 0 then |
|
|
|
Oh, there isn't a math.positive or something? I must be dumber then I thought... |
|
|
If you're trying to get only positive numbers, you can do that using math.abs (x).
But as for just checking if something's under 0, there's no better method than the if
If you're seeing this post, it means I'm either dead (leaving behind a very fabulous looking corpse) or my soul has been captured by pixies! |
|
CasualistJoin Date: 2014-06-26 Post Count: 4443 |
local math = {};
setmetatable(math,{__index = getfenv().math})
math.positive = function(num)
return num > 0
end
print(math.positive(-10))
There you go OP |
|
lordramboJoin Date: 2009-06-16 Post Count: 20628 |
well the definition of a negative number is a number below 0, so the simplest form to translate that to would be: if num < 0
thats almost no bloat at all considering you will need an if statement either way and evaluation of that condition will take almost no time at all since it'll only generate like one instruction plus the conditional jump in the assembly dump |
|
|
# ###### that is negative, is less then 0. Simple. |
|
WowgnomesJoin Date: 2009-09-27 Post Count: 26255 |
local numb = math.random(-500,500)
if math.sqrt(numb*numb) == numb then
print("positive it's positive")
else
print("positive its negitive")
end
|
|
|
local isPositive = -1<0
print(isPositive) |
|
|
*-1>0
or you can use this
function sign(x)
return (x0 and 1) or 0
end |
|
|
and when you use a comparison operator like =, , ==, ~=, they will all return true or false
so you can skip using if statements if you dont want to |
|
WowgnomesJoin Date: 2009-09-27 Post Count: 26255 |
nice, didn't know that!
|
|
|
well @OP doesnt know that apparently so you dont need that sarcasm |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
blarg you're a stupid arrogant skid, stop assuming things and stop acting like you're some kind of genius when time and time again you show that you're incredibly dumb. |
|
|
yet you take the time to be one of the most mentally damaged people on this forum by arguing with individuals for stating things in a better way than you |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
> says the one who explained the dot product wrong (and countless other topics)
> says the one who explains anything to do with programming wrong
> says the one who tries to act superior
you're not good at this. |
|
WowgnomesJoin Date: 2009-09-27 Post Count: 26255 |
I wasn't being sarcastic, I did not know that operators did not need if statements.
|
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
IsNegative = function(num)
return num < 0 and true or false
end)
print(IsNegative(-1))
>> true
|
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
You don't need the "and true or false" time. |
|
CasualistJoin Date: 2014-06-26 Post Count: 4443 |
@wowgnomes the way the and//or keywords work allow them to behave similarly to ternary operators of other languages.
The first result from googling "lua Ternary" will provide you with a nice explanation of how it all works// how it behaves logically |
|
WowgnomesJoin Date: 2009-09-27 Post Count: 26255 |
Thanks! |
|
|
flux thinks that being a bully to people does not make him look superior
in retrospect it makes him look like an immature idiot who has nothing better to do |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
Nah, I only bully people who deserve to be bullied. AKA arrogant ###### and people who have too much of an ego and are stubborn and refuse to acknowledge themselves as wrong when they are wrong. Like you, for example. |
|