In the past topic (1), we talked about floating-point / comma numbers normalized in accordance with the IEEE754 standard. In the same place, denormalized numbers were considered, the artificial introduction of which in the standard led to monstrous software and hardware costs, which slowed down the processes of computer processing of numbers tens and hundreds of times. But, is this normalization really necessary, and is it all the more justified to introduce an exotic class of denormalized numbers into computer arithmetic? Let's try to deal with this issue.
Recall that in the previous article, for simplicity, we introduced the following concepts. The area of machine mantissa (OMM) is the area of machine word into which the number mantissa is written. The field of machine order (OMP) is the area of the machine word in which the order of the characteristic of the number is written. Further, in the text, we will use these concepts.
So, as you know, any number written in its natural form can be represented in an equivalent exponential form:
')
F = M ∙ q ^ (± h)
where M is a number written in its natural form, with the offset point on h positions in one direction or another. The number M in such a record is called the mantissa of a number, and q ^ (± h) is a characteristic of a number with an order ± h. The sign and magnitude of the order of h compensate for the magnitude of the displacement of a point relative to its initial position in the number represented in its natural form
When we set ourselves the task of writing a certain number into a machine word, we first of all care that the machine word contains a number with minimal loss of accuracy. This condition is satisfied by such a record of the number, at which the maximum of significant digits of the number mantissa is recorded in the OMM and, at the same time, no overflow occurs in the WMD.
Suppose that we have a binary number written in exponential form with a mantissa with N digits and a characteristic order equal to h. Consider the case when N≥K., I.e., if the number of significant digits of the mantissa of the number being written is greater than or equal to the number of OMM digits.
For example, suppose we need to write in a machine word in which B = 3, K = 4 is a binary number, represented in its natural form as 11.011. In this number, the number of significant digits exceeds the number of OMM digits. In an exponential form, this number can have various recording options, such as: 11011 • 2 ^ (- 3); 11.011 • 2 ^ 0; 0.0011011 • 2 ^ 4; and so on
In order for the number 11011. • 2 ^ (- 3) to be written into a machine word with a fractional mantissa, it is necessary to shift the point in the mantissa of the number to the left until the OMM appears in the high order digit. For the number of point offsets it is necessary to adjust the order of the characteristics of the mantissa in the WMD. In our case, the point must be shifted to 5 bits to the left. Then the number 5-3 = 2 will be written to the WMD. And in the machine word, thus, the number 0.1101 • 2 ^ 2 will be written. The younger unit did not fit into the OMM bit grid and was lost. Similarly, we will have for the number 11.011 • 2 ^ 0. To write it into our computer word, you need to shift the point two digits to the left and accordingly increase the order also by 2. As a result, the number 0.1101 • 2 ^ 2 will be written in the computer word. To write the number 0.0011011 • 2 ^ 4 into the machine word, the point in it must be shifted two digits to the right, and the order also reduced by 2. As a result, we again get the number 0.1101 • 2 ^ 2 written in the machine word.
In all the considered cases, regardless of the type of the initial record of the number, we got an unambiguous representation of the number in the machine word and therefore there was no need to normalize such numbers.
Now let N <K. A number that satisfies this condition can be written to a machine word in various ways.
For example, in a machine word in which B = 3, K = 4, the number 0.01 can be represented by the following options:
0.1000 • 2 ^ (- 1), 0.0100 • 2 ^ 0, 0.001 • 2 ^ 1, 0.0001 • 2 ^ 2.
So what? Why should we be confused? All these variants of writing the number 0.01 are mathematically equivalent and, being used in mathematical transformations, give the correct result.
Indeed, suppose that in the machine word the number 0.01 is represented as 0.1000 • 2 ^ (- 1). Add this number with the binary number 0.011, which is written in the machine word as 0.11 • 2 ^ (- 1). We get the following result:
0.1000 • 2 ^ (- 1) + 0.11 • 2 ^ (- 1) = 1.01 • 2 ^ (- 1).
Since the leading digit of the number went beyond the OMM bit grid, we must shift the point one digit to the left and increase the order value by 1. As a result, the number 0.1010 • 2 ^ 0 will be written in the machine word.
Suppose now that the binary number 0.01 is represented in the machine word in the form 0.0001 • 2 ^ 2. Add it to the number 0.011, which is now represented in the machine word as 0.0011 • 2 ^ 1. According to the rules of arithmetic, let us sum up the orders of the terms to the same value and add the numbers thus transformed:
0.001 • 2 ^ 1 + 0.0011 • 2 ^ 1 = 0.0101 • 2 ^ 1.
The number obtained as a result of the addition is mathematically equivalent to the previously obtained number 0.1010 • 2 ^ 0 and can be written into a machine word without additional transformations.
Thus, the ambiguity of writing a number in a computer word does not affect the correctness of mathematical transformations in which this number is involved. And since, as a rule, a strictly defined number of digits is allocated for a computer word in a computing device, there are no advantages in writing the above options for representing numbers in a computer word with selected parameters K and B.
From here you can make a very important conclusion. Any normalization of a number is an operation leading to an unproductive use of computational resources.
The only thing to take care of when writing numbers to the machine word is that their mantissa values and orders do not go beyond the limits of the machine word discharge grid. Such a procedure is provided for in any computing device using floating point arithmetic. If such an event is detected, the numbers should be adjusted so that at least the highest bits of the mantissa, the converted number, fit into the OMM bit grid.
Another very important conclusion can be drawn from the above reasoning. The refusal of the procedure of normalization of numbers allows us to explicitly obtain the value of zero and naturally cover a range of small numbers, without artificially introducing a class of denormalized numbers. This makes it possible to significantly simplify the process of writing numbers to a machine word and, as a result, significantly reduce the time for performing mathematical operations.
LITERATURE.
1.
habrahabr.ru/post/2622452.
wiki.mvtom.ru/index.php/Forms_presentation_number_in_Computer3. IEEE Standard for Binary Floating-Point Arithmetic. Copyright 1985 by The Institute of Electrical and Electronics Engineers, Inc. 345 East 47th Street, New York, NY 10017 USA.
4.
www.softelectro.ru/ieee754.html5.
neerc.ifmo.ru/wiki/index.php?title=Representation of real_numbers&printable=yesYuri Spiridonov.