> -----Original Message----- > From: [EMAIL PROTECTED] [mailto:osg-users- > [EMAIL PROTECTED] On Behalf Of Eric Sokolowsky > Sent: Friday, February 23, 2007 1:38 PM > To: osg users > Subject: Re: [osg-users] Vector cross product and operator precedence > > Gazi Alankus wrote: > > I recently discovered a bug in my code that made me question the > > choice of the operator chosen for vector cross product in osg. > > The bitwise xor operator (^) has a lower precedence than addition > > operator (+) in C++. So, addition is done before cross product, which > > is not intuitive and is not the case in mathematics. I decided to stop > > using the ^ operator for cross product, but I couldn't find a function > > version for it - the operator looks like the only choice. I know I can > > write one myself, but I just wanted to point this issue out since it > > probably will lead to bugs in many other people's code. > > > > My apologies if I'm missing something. > > In C++, the ^ operator is nothing more than an overloaded operator^() > that takes the right arguments. Therefore, instead of writing: > > a ^ b > > You can write: > > operator^(a, b) > > And since function calls have a very high precedence (and the comma > operator has a very low precedence) this might achieve your goal. >
Well likewise, you can make it explicit with something like (a^b) + c, but that doesn't solve the fundamental problem of doing what comes naturally and getting a different response. I've been bit by this before. I think Gazi brings up a good point. > _______________________________________________ > osg-users mailing list > [email protected] > http://openscenegraph.net/mailman/listinfo/osg-users > http://www.openscenegraph.org/ _______________________________________________ osg-users mailing list [email protected] http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/
