dy <<= 1;
dx <<= 1;
That’s some C++ code I found, what does it do to the variables, and what is that operator called?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That shifts
dyanddx1 bit to the left.It’s equivalent to (unless dy and dx have operator =<< overloaded)
If
dxanddyare integral types, it’s equivalent to multipication by 2.Note that it is undefined behavior to left-shift a negative number.
This is an ugly hack by programmers who think this is more efficient than just multiplying by 2 (which is not, but it is a lot less readable).