Raised This Month: $ Target: $400
 0% 

Simple question about verifying values


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 03-03-2014 , 04:57   Simple question about verifying values
Reply With Quote #1

Is the following example
Code:
if (get_pcvar_num(pcvar) == 1 || get_pcvar_num(pcvar) == 3)
the same as
Code:
if (get_pcvar_num(pcvar) == (1 | 3))
?

Thanks in advance.
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 03-03-2014 , 06:00   Re: Simple question about verifying values
Reply With Quote #2

single | is bitwise OR. Probably you can do it like that:

Code:
if (1<<get_pcvar_num(pcvar) & (1<<1)|(1<<3))
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 03-03-2014 , 06:09   Re: Simple question about verifying values
Reply With Quote #3

Quote:
Originally Posted by NiHiLaNTh View Post
single | is bitwise OR. Probably you can do it like that:

Code:
if (1<<get_pcvar_num(pcvar) & (1<<1)|(1<<3))
Hi Nihi ^_^
Yes that works but doesn't it multiply the value with itself?
What I'm trying to do is optimize, since getting the same cvar twice in a single check is pointless.
What's the best way I could do that?
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 03-03-2014 , 11:27   Re: Simple question about verifying values
Reply With Quote #4

Your 2nd example isn't right, it doesn't work that way. Unless you are dealing with bits, you will need to do as you did in your 1st example
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 03-03-2014 , 13:05   Re: Simple question about verifying values
Reply With Quote #5

Quote:
Originally Posted by YamiKaitou View Post
Your 2nd example isn't right, it doesn't work that way. Unless you are dealing with bits, you will need to do as you did in your 1st example
Yes, I tested several ways of doing it and the best one seems to be creating a new variable and storing the cvar value.
Thank you.
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
Reply



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 05:59.


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