Re: compare a large number of variables



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

.



Relevant Pages

  • Re: OOs best feature survey results
    ... > Interface is a poor man substitution for multiple inheritance. ... The "n" means a numeric compare. ... What is your criteria for which everyday concept to make into ... Relativity ...
    (comp.object)
  • Re: Skip Record If
    ... Word MVP web site http://word.mvps.org ... multiple "Skip Record Ifs"? ... disregarding all my other "compare to's. ...
    (microsoft.public.word.docmanagement)
  • Re: Can I compare more than two merge field values using =AND or =OR?
    ... you can build a multiple OR test this way: ... [Microsoft MVP - Word] ... It works fine when I try and compare the values of two mergefields: ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Can I compare more than two merge field values using =AND or =
    ... "macropod" wrote: ... you can build a multiple OR test this way: ... It works fine when I try and compare the values of two mergefields: ...
    (microsoft.public.word.mailmerge.fields)
  • Re: help on comparing lines in a text file
    ... so the file will have multiple lines and I guess I am really concerned ... > and when I said that the outer loops were redundant, ... > assumption that there are just two lines that you want to compare. ... > including which lines you want to stuff in which arrays and which arrays ...
    (perl.beginners)