Introduction to Game Programming with C++ (Wordware Game Developers Library)

1.8 Fractions-Incomplete Measure

When counting discrete units, every natural number, such as 1, 2, 3, 4, etc., is known by its ratio to 1. For example, 2 is twice as large as 1, 3 is three times 1, 4 is four times greater than 1, and so on. By way of ratio, the relationship between any two quantities can be expressed in terms of how much larger the first is to the second quantity, and how much smaller the second is to the first quantity. In this section, fractions are used to measure continuous data and to express amounts that are less than a whole discrete unit. Consider the following number line:

Figure 1.3

The line has been split into a number of divisions, and we will now consider 1 and any other number in a continuous way as opposed to a discrete way. Each division along the line is the same length: 1, 2, 3, and so on. There is a point, however, that is halfway to 1-this point is less than 1 and is therefore some lower value between 0 and 1. Likewise, I might not choose a point halfway but a quarter of the way along, or perhaps a third. In all cases, it is possible to subdivide the space between any two numbers and break it into smaller pieces that are not themselves a complete unit. To express this measurement we use fractions.

Fractions are commonly called vulgar fractions or common fractions. Each fraction has two terms that correspond to the terms of a ratio and are separated by a horizontal line (called a vinculum). There is a number on the top (numerator) and a number below (denominator). Fractions come in three forms: proper fractions, mixed numbers, and improper fractions. The following sections discuss these forms.

1.8.1 Unit and Reciprocal Fractions

Unit fractions are called the reciprocal of a number because they are the opposite. For example, the reciprocal of 2 is ½, the reciprocal of 4 is ¼, and so on. The reciprocal of any number then means making that number the denominator of a fraction and making the numerator 1. In short, a unit fraction is a fraction that has a numerator of 1.

Note 

Division by a number, say 2, is the same as multiplication by its reciprocal. So 10 ÷ 2 is the same as 10 × ½.

It is also important to remember that a fraction's ratio to 1 is the same as the numerator's ratio to the denominator. In terms of a part and parts of numbers as discussed earlier, it can be useful to see unit fractions as follows in terms of their relationship to 1:

There are also proper fractions such as ⅔ and ¾ where the numerator is greater than 1. These are named according to the ratio between the numerator and denominator, just like any other fraction. ¼ is one fourth part, or one quarter. ¾ is therefore three of them-¼ + ¼ + ¼-and this is three fourth parts, or three quarters. More specifically, it is three fourth parts of 1.

1.8.2 Fractions and Whole Numbers

If the reciprocal of 2 is ½, then the reciprocal of ½ must be 2. For this reason, any number can be expressed as a fraction as itself over a denominator of 1. For example, 2/1 is the reciprocal of ½ (the numerator and denominator are swapped). This makes sense since 1 divides into 2 twice. This is because of the ratio of the numerator to the denominator: 1 is half of 2 and 2 is two times 1. Here are some reciprocals:

Alternatively, a whole number can be written as an improper fraction of any denominator by multiplying itself by the denominator and writing the product as the numerator. For example, 2 can be expressed as a fraction over a denominator of 8 as follows:

Note 

A whole number, such as −1, 0, 1, 2, and so on, is called an integer.

1.8.3 Complements

Proper fractions represent a number less than 1, and this means their numerator is less than their denominator. Fractions are therefore a part of 1, as we have seen. ½ is one half of 1, ¾ is three fourths of 1, and so any proper fraction can be considered some part of 1. If, given a proper fraction, you are asked to find its complement, then it means you need to find a second fraction which, when added to the first, will equal 1. In other words, if two fractions are added and their sum is 1, they are said to be complements because they are two parts of a whole.

½ + ? = 1 (One half plus what number equals 1?)

The complement of ½ is ½ because two halves make one whole item. 1 is two times ½; therefore two halves equal 1.

Note 

Another way of asking for the complement of a fraction is to ask a subtraction question: 1 − ½ = ½.

1.8.4 Equivalents

It was stated earlier that when each term of a ratio is multiplied by the same number the result is an equivalent ratio; that is to say, the same ratio. 3: 15 multiplied by 3 is 9: 45; both of these are the same ratio and both these ratios can be reduced to lowest terms in the ratio 1: 5.

This idea of equivalents also applies to fractions since fractions represent the ratio between the numerator and the denominator. Consider the pie chart below. It is divided into eight equal segments, and therefore any fraction of this pie can be represented as a numerator over 8 (the denominator). Since there are eight equal divisions, if I eat one slice then I have eaten ⅛, and there are ⅞ (seven eighths) remaining. Notice also how these two fractions (⅛ and ⅞) are comxsplements; if they were added together they would equal 1.

Figure 1.4

In the context of the pie with eight equal pieces, the following two fractions are equivalent; that is, they represent the same value. We know this because the numerators and denominators of both fractions are in the same ratio: 4/8 and ½.

In each of these fractions, the denominator is twice as much as the numerator, and the numerator is half the denominator. Thus, 4 is to 8 as 1 is to 2, and because of this each fraction is in the same ratio when related to 1. Both fractions, then, are half of 1.

The fraction 4/8 is not expressed in its lowest terms, while ½ is the same fraction but expressed in lowest terms. The method of reducing a fraction to its lowest terms is the same as that for reducing a ratio to its lowest terms; this is the theory of the common divisor, as demonstrated previously. This process involves finding a number that both terms can be divided by because, just as multiplying both terms by the same number results in an equivalent fraction, so does dividing both terms by the same number. Like a ratio, a fraction is said to be in its lowest terms when the numerator and denominator have no common divisors except 1. The following fraction has been reduced several times.

1.8.5 Comparing Fractions

It is useful to compare fractions and determine which is smaller and which is larger, and there are a number of ways to do so.

Note 

The lowest common multiple of two numbers is the first multiple of both numbers that coincide. For example, here are some multiples of 3 and 5:

  • 3, 6, 9, 12, 15

  • 5, 10, 15

Here, the LCM of 3 and 5 is 15 because it is the first multiple that both 3 and 5 have in common. In short, to find the LCM between any two numbers, cycle through the multiples of the larger number (including the larger number itself) and see where its multiples coincide with multiples of the smaller number.

When calculating the LCM, if the given numbers are in their lowest terms (in other words, they can be divided by no common number except 1), then their LCM is their product. 3 and 5 are in their lowest terms, and their LCM is also the product of 3 and 5 (3 × 5 = 15).

For example, let's compare ½ and ¾. First, we need to find a common denominator.

The denominators are 2 and 4.4 is a multiple of 2. Therefore, 4 is the LCM.

Make an equivalent fraction of ½ such that it shares the denominator of 4. Both the numerator and denominator must be multiplied by the same number to make an equivalent fraction. This number must be 2, because 2 × 2 = 4. So:

Now we can compare the fractions 2/4 and ¾.¾ is the larger number.

1.8.6 Adding and Subtracting Fractions

Just as any whole numbers can be added and subtracted, so can fractions. In order to add or subtract a fraction with the same denominator, add or subtract only the numerators, leaving the denominators the same. Any two fractions with different denominators must be made into equivalent fractions with equal denominators using the LCM, as demonstrated in the previous section.

For example:

Note 

Adding mixed numbers follows the same rule. Add the two whole numbers and then add the fractions.

1.8.7 Multiplying and Dividing Fractions

Fractions can also be multiplied and divided. There are several kinds of multiplication and division operations on fractions, which are described here.

Категории