Difference between >= and >
#1

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?
Reply
#2

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

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.
Reply
#4

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?
Reply
#5

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.
Reply
#6

> 1 mean more then 1 . >= 1 Mean 1 and also more then 1 . Simple
Reply
#7

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!");
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)