[ROOT] problem with operator precedence

From: Hannes SAKULIN (Hannes.Sakulin@cern.ch)
Date: Wed Aug 29 2001 - 10:25:50 MEST


Hi! 
I'll try to ask this question again, here as nobody seems to read the
newsgroup root.cern.ch.
Hannes.

-------- Original Message --------
Subject: problem with operator precedence?
Date: Mon, 30 Jul 2001 15:45:07 +0200
From: Hannes SAKULIN <Hannes.Sakulin@cern.ch>
Organization: CERN
Newsgroups: cern.root

Hi,
I am observing a very strange behavior with root Version 3.01/06 12 July
2001 (from na49). It seems like the precedence of && over || is not
followed in all
cases. 

The if expressions below should always evaluate to true but for some
reason the second one evaluates to false when I call the function
(RunGMT1_cutJul2001()) from within a loop. 

The output of the test program looks like this:

root [8] .x xx.C
TRUE w. brackets   true without 
TRUE w. brackets   false without
*** oops !!! *** eta = 0.9
TRUE w. brackets   false without
*** oops !!! *** eta = 0.9


Does anybody have an ides what is going wrong in my little example?

Best Regards, Hannes Sakulin.


void xx ()
{
  RunGMT1_cutJul2001();
  for (int iev = 0; iev <2; iev++) {
    RunGMT1_cutJul2001();
  }
}

void RunGMT1_cutJul2001()
{
  float eta = .9;
  bool xx;
  if ( 1 && ( (eta > 0.98 && eta < 1.02) ||
	      (eta > 1.38 && eta < 1.42) ||
	      (eta > 0.88 && eta < 0.92) )) {
    cout << "TRUE w. brackets   " ;
    xx=true;
  }
  else {
    cout << "FALSE w. brackets  " ;
    xx=false;
  }

  if (1 && ( eta > 0.98 && eta < 1.02 ||
	     eta > 1.38 && eta < 1.42 ||
	     eta > 0.88 && eta < 0.92 ) ) { 
    cout << "true without " << endl;
  }
  else
    {
      cout << "false without" << endl;
      if (xx) cout << "*** oops !!! *** eta = " << eta << endl;

    }
}



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:58 MET