Re: compare a large number of variables
- From: Netocrat <netocrat@xxxxxxxxxxx>
- Date: Thu, 18 Aug 2005 00:30:12 +1000
On Tue, 16 Aug 2005 23:55:15 -0700, Einar wrote:
> Hello Eric,
>
> Yes, your suggestions work perfectly, but I was mor looking for a nice
> bit operator to operate on all my variables and then to compare it with
> the value. something like (a|b|c|d...z) != value (this wont work
> however... ). This is just to get rid of a for-loop or lots of
> if-statements, so it is nothing necesary, I'm just convinced that it is
> possible to solve in another way, and I can't forget about it....
> Ahhhrg.
How about (off the top of my head and untested):
if ( !( ((a|b|c|d...z) == value) && ((a&b&c&d...z) == value) ) )
/* one or more of a,b,c,d...z is not equal to value */
I don't think that would generally be as efficient as using multiple
comparisons against value because in that case the first mismatch will
prevent the rest from being evaluated. You never know though - on some
hardware it might be; or the compiler might rewrite it for you.
Another alternative (also untested):
if ( ((a|b|c|d...z)&a&b&c&d...z) != value )
/* one or more of a,b,c,d...z is not equal to value */
--
http://members.dodo.com.au/~netocrat
.
- Follow-Ups:
- Re: compare a large number of variables
- From: Michael Wojcik
- Re: compare a large number of variables
- References:
- compare a large number of variables
- From: Einar
- Re: compare a large number of variables
- From: Eric Sosman
- Re: compare a large number of variables
- From: Einar
- compare a large number of variables
- Prev by Date: Re: compare a large number of variables
- Next by Date: Re: pointer arithmetic and user-defined types
- Previous by thread: Re: compare a large number of variables
- Next by thread: Re: compare a large number of variables
- Index(es):
Relevant Pages
|