11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 4: Performing Logical Operations 53This comparison is true if f1 and f3 are within some small delta from eachother, which should still be true even if you take some small round-off errorinto account.Short circuits and C++The& & and || perform what is called short-circuit evaluation. Consider thefollowing:condition1 && condition2If condition1 is not true, the result is not true, no matter what the valueof condition2. (For example, condition2 could be true or false withoutchanging the result.) The same situation occurs in the following:condition1 || condition2If condition1 is true, the result is true, no matter what the value ofcondition2.To save time, C++ (wisely) cuts to the chase and evaluates condition1 first.C++ does not evaluate condition2 if condition1 is false (in the case of &&) or condition1 is true (in the case of ||). This is known as short circuitevaluation.Expressing Binary NumbersC++ variables are stored internally as so-called binary numbers. Binary numbersare stored as a sequence of 1 and 0 values known as bits. Most of thetime, you don’t really need to deal with which particular bits you use to representnumbers. Sometimes, however, it’s actually practical and convenientto tinker with numbers at the bit level — so C++ provides a set of operatorsfor that purpose.Fortunately, you won’t have to deal too often with C++ variables at the bitlevel, so it’s pretty safe to consider the remainder of this chapter a DeepTechie excursion.The so-called bitwise logical operators operate on their arguments at the bitlevel. To understand how they work, let’s first examine how computers storevariables.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!