Raised This Month: $32 Target: $400
 8% 

!! operator


Post New Thread Reply   
 
Thread Tools Display Modes
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 03-28-2017 , 21:30   Re: !! operator
Reply With Quote #11

It is not used because instead of

PHP Code:
if(!!g_admin[id]) 
is just

PHP Code:
 if(g_admin[id]) 
Right?

Then with that the !! is useless.

Edit:

Quote:
Originally Posted by fysiks View Post
Using this on a boolean makes absolutely no sense since it's a double negative and will always return the original value.
That's what I understood.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 03-28-2017 at 21:33.
EFFx is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-28-2017 , 21:33   Re: !! operator
Reply With Quote #12

Quote:
Originally Posted by EFFx View Post
It is not used because instead of

PHP Code:
if(!!g_admin[id]) 
is just

PHP Code:
 if(g_admin[id]) 
Right?

Then with that the !! is useless.
Like I said before, it depends on what g_admin[id] contains. If it contains booleans then you use it as a boolean.

If you use an integer in an if statement, it would be equivalent to variable != 0 or !!variable.
__________________
fysiks is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 03-28-2017 , 21:47   Re: !! operator
Reply With Quote #13

Yes dude. As said before as well, it was an example.

Or just !variable

Why would I convert an interger to a boolean ? In what kinda function? Just add bool tag.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 03-28-2017 at 21:47.
EFFx is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 03-28-2017 , 22:49   Re: !! operator
Reply With Quote #14

Sometimes you need to check if both conditions are true or false (have the same bool value), like both players are alive or dead. If you will work with ints it will be failed, because, for example first condition has 7 and second condition has 2, 7 == 2 fails, but (7 != 0) == (2 != 0) is ok.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-29-2017 , 21:50   Re: !! operator
Reply With Quote #15

Quote:
Originally Posted by EFFx View Post
Yes dude. As said before as well, it was an example.

Or just !variable

Why would I convert an interger to a boolean ? In what kinda function? Just add bool tag.
Since it is hard for you to understand how this works, you can simply just never use it and you will be just fine. It is not a necessary operator since there are other ways to do it (like comparing to zero).
__________________
fysiks is offline
Kotoamatsukami
Member
Join Date: Jan 2017
Location: Malaysia
Old 03-30-2017 , 06:02   Re: !! operator
Reply With Quote #16

Quote:
Originally Posted by KliPPy View Post
It's not a single operator, but negation operator "!" being done twice. You would want to use that when you want to coerce a cell into a boolean, following the rule that 0 = false, anything else = true.
Code:
!!(0) == false
!!(1) == true
!!(42) == true
!!(-69) == true
This way you are making sure that your boolean is either "true" or "false" and not bool:420 for example. That's good because some people prefer to do "if(variable == true)" instead of "if(variable)", which won't give correct results if you don't "normalize" your boolean value.
Pardon me.
Based on your explanation, what I understand is;
PHP Code:
new i_Variable 0

if( !!i_Variable 
That will not let the 'if' statement functional, right? So if we do;
PHP Code:
new i_Variable 1

if( !!i_Variable 
Then, this will make the 'if' statement functional. Well, it is not all time should be storing '1' even other than '1' is still available, as long as the variable did not store '0'.

Correct me if I am wrong.
Thank you.
Kotoamatsukami is offline
kristi
Senior Member
Join Date: Nov 2016
Old 03-30-2017 , 10:06   Re: !! operator
Reply With Quote #17

PHP Code:

if(0// false

if(1// true

if(2// false

if(!!2// true 
Is this right ?
kristi is offline
Send a message via Skype™ to kristi
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 03-30-2017 , 10:33   Re: !! operator
Reply With Quote #18

No, if (2) is true as if (!!2) and if (2 != 0).

PHP Code:
new x;
...
x// integer (_) with value of x
bool:x// bool with value of x
!!x// bool with true if x != 0 and false if x == 0
!= 0// the same as !!x 
PHP Code:
new xy;
...
// These are identical
if (x)
if (
!= 0)
if (!!
x)

if (
== y// true if x = y
if (!!== !!y// x and y both are not zero or both are zero
if ((!= 0) == (!= 0)) // same as the previous
if (!== !y// also same 
__________________

Last edited by PRoSToTeM@; 03-30-2017 at 10:49.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:58.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode