SA-MP Forums Archive
Difference between >= and > - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Discussion (https://sampforum.blast.hk/forumdisplay.php?fid=84)
+---- Thread: Difference between >= and > (/showthread.php?tid=575961)



Difference between >= and > - Sellize - 31.05.2015

Code:
if(PlayerInfo[playerid][pAdmin] >= 2)
and

Code:
if(PlayerInfo[playerid][pAdmin] > 1)
they both do the same in this case, correct?

So which one would be the best one to use and why?


Re: Difference between >= and > - dominik523 - 31.05.2015

Well, yeah. It's the same thing. I've mostly seen people use i.e. "> 1" in gamemodes rather than ">= 2".


Re: Difference between >= and > - Yashas - 31.05.2015

They both do the same but > is faster than >=.

Its machine-dependent so you won't get a good answer.The compiler might change it but in our case it doesn't.It gives two different assembly outputs.

Assembly Output:
Code:
	load.s.pri fffffffc
	const.alt 4
	sgeq ;for >=
	stor.s.pri fffffffc
	;$exp
	; line 88
	break	; b8e8
	load.s.pri fffffffc
	const.alt 3
	sgrtr ;This is for >
Here is what the CPU would probably do for >=.
1. It will first check if its equal then check if it is greater.
2. It will subtract 1 and then check if it is greater.

I would just ignore the speed difference and use the operator which seems to fit the situation better.


Re: Difference between >= and > - Vince - 31.05.2015

It depends on the situation and on the person writing the code so there isn't really a straightforward answer. I tend to use >= and <= if I want to verify that something is at least (or at most) that value, e.g.:
pawn Code:
if(adminlevel >= 2)
which to me is saying: do something if the adminlevel is at least 2. Whereas with > 1 it would say, again to me: do something if the adminlevel is greater than 1. Then I would have to figure out that "greater than 1" means "at least 2". Hard to explain, really.

Other example is:
pawn Code:
if(0 <= variable <= 100)
// vs
if(-1 < variable < 101)
Which one's more readable?


Re: Difference between >= and > - XXCrazyMan707XX - 31.05.2015

I prefer to use >= and <=, my reasoning? Well it's just a habit and I don't notice any changes in speed.

It's just like a lot of things, we all have our own habits/ways.


Re: Difference between >= and > - SoFahim - 31.05.2015

> 1 mean more then 1 . >= 1 Mean 1 and also more then 1 . Simple


Re: Difference between >= and > - seanny - 02.06.2015

The > symbol means Greater Than which means that something must be bigger than the specified number.
For example:
pawn Code:
new foo;
if(foo > 0)//If foo is greater than/bigger than.
{
    foo = 0;
    print("Hello World!");
}
else
{
    foo = 1;
    print("Goodbye Cruel World!");
}
The >= symbol means Equal or Greater Than which means that something must be the same as or bigger than the specified number.
For example:
pawn Code:
new foo;
if(foo >= 1)//If foo is greater than/bigger than.
{
    foo = 0;
    print("Hello World!");
}
else
{
    foo = 1;
    print("Goodbye Cruel World!");
}