Is float normalization necessary?
In the previous topic (1), we talked about floating point / comma numbers normalized in accordance with the IEEE754 standard. Denormalized numbers were also considered there, the artificial introduction of which in the standard led to monstrous software and hardware costs that slowed down the processes of computer processing of numbers tens and hundreds of times. But, is this normalization really needed, and is it even 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 of presentation, we introduced the following concepts. The machine mantissa area (OMM) is the area of the machine word into which the mantissa of the number is written. The domain of machine order (OMP) is the area of a machine word into which the order of characterization of a 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 its exponential equivalent:
F = M ∙ q ^ (± h)
where M is a number written in its natural form, with a displaced point at h positions in one direction or another. The number M in such a notation is called the mantissa of the number, and q ^ (± h) is the characteristic of the number with the order of ± h. The sign and magnitude of order h compensate for the displacement of a point relative to its original position in a natural number.
When we set ourselves the task of writing a certain number in a machine word, we first of all take care that the number with minimal loss of accuracy. This condition is satisfied by such a record of the number at which the maximum significant digits of the mantissa of the number are recorded in the OMM and, at the same time, overflow does not occur in the OMP.
Suppose that we have some binary number written in exponential form with a mantissa having N digits and a characteristic order of h. Consider the case where N≥K., I.e., if the number of significant digits of the mantissa of the recorded number is greater than or equal to the number of OMM bits.
For example, let us need to write in a machine word in which B = 3, K = 4 a binary number, presented in natural form as 11.011. In this number, the number of significant digits exceeds the number of OMM bits. In 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 in the machine word with a fractional mantissa, it is necessary to shift the point in the mantissa of the number to the left until one appears in the high order OMM. 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 5 bits to the left. In WMD then the number 5-3 = 2 will be written. And in the machine word, thus, the number 0.1101 • 2 ^ 2 will be written. The junior unit did not fit in the OMM discharge grid and was lost. Similarly, we will have for the number 11.011 • 2 ^ 0. To write it in our machine word, it is necessary to shift the point by 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 machine word. To write the number 0.0011011 • 2 ^ 4 into the machine word,
In all the cases considered, 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 satisfying this condition can be written in 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 this confuse us? All these options for writing the number 0.01 are mathematically equivalent and, being used in mathematical transformations, give the correct result.
Indeed, suppose that in a 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 boundaries of the OMM discharge 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 as 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, we reduce the orders of the terms to the same value and add the numbers transformed in this way:
0.001 • 2 ^ 1 + 0.0011 • 2 ^ 1 = 0.0101 • 2 ^ 1.
The number obtained as a result of 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 machine word does not affect the correctness of the mathematical transformations in which this number is involved. And since, as a rule, a strictly defined number of bits is assigned to a machine word in a computing device, there are no advantages in writing the above options for representing numbers in a machine word with the selected parameters K and B.
From this, a very important conclusion can be drawn. Any normalization of a number is an operation leading to an unproductive use of computing resources.
The only thing to take care of when writing numbers to a machine word is to ensure that their mantissa and order values do not go beyond the bit grid of the machine word. 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 discharge grid.
Another very important conclusion can be drawn from the above reasoning. The rejection of the procedure for normalizing numbers allows you to explicitly get the value of zero and naturally cover the range of small numbers, without artificially introducing a class of denormalized numbers. This allows you to significantly simplify the process of writing numbers to a machine word and, as a result, significantly reduce the time it takes to perform mathematical operations.
LITERATURE.
1. habrahabr.ru/post/262245
2. wiki.mvtom.ru/index.php/Formy_predstavleniya_chisel_v_EVM
3. 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.html
5. neerc.ifmo.ru/wiki/index.php?title=Presentation_of_natural_numbers&printable=yes
Yuri Spiridonov.
Recall that in the previous article, for simplicity of presentation, we introduced the following concepts. The machine mantissa area (OMM) is the area of the machine word into which the mantissa of the number is written. The domain of machine order (OMP) is the area of a machine word into which the order of characterization of a 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 its exponential equivalent:
F = M ∙ q ^ (± h)
where M is a number written in its natural form, with a displaced point at h positions in one direction or another. The number M in such a notation is called the mantissa of the number, and q ^ (± h) is the characteristic of the number with the order of ± h. The sign and magnitude of order h compensate for the displacement of a point relative to its original position in a natural number.
When we set ourselves the task of writing a certain number in a machine word, we first of all take care that the number with minimal loss of accuracy. This condition is satisfied by such a record of the number at which the maximum significant digits of the mantissa of the number are recorded in the OMM and, at the same time, overflow does not occur in the OMP.
Suppose that we have some binary number written in exponential form with a mantissa having N digits and a characteristic order of h. Consider the case where N≥K., I.e., if the number of significant digits of the mantissa of the recorded number is greater than or equal to the number of OMM bits.
For example, let us need to write in a machine word in which B = 3, K = 4 a binary number, presented in natural form as 11.011. In this number, the number of significant digits exceeds the number of OMM bits. In 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 in the machine word with a fractional mantissa, it is necessary to shift the point in the mantissa of the number to the left until one appears in the high order OMM. 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 5 bits to the left. In WMD then the number 5-3 = 2 will be written. And in the machine word, thus, the number 0.1101 • 2 ^ 2 will be written. The junior unit did not fit in the OMM discharge grid and was lost. Similarly, we will have for the number 11.011 • 2 ^ 0. To write it in our machine word, it is necessary to shift the point by 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 machine word. To write the number 0.0011011 • 2 ^ 4 into the machine word,
In all the cases considered, 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 satisfying this condition can be written in 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 this confuse us? All these options for writing the number 0.01 are mathematically equivalent and, being used in mathematical transformations, give the correct result.
Indeed, suppose that in a 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 boundaries of the OMM discharge 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 as 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, we reduce the orders of the terms to the same value and add the numbers transformed in this way:
0.001 • 2 ^ 1 + 0.0011 • 2 ^ 1 = 0.0101 • 2 ^ 1.
The number obtained as a result of 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 machine word does not affect the correctness of the mathematical transformations in which this number is involved. And since, as a rule, a strictly defined number of bits is assigned to a machine word in a computing device, there are no advantages in writing the above options for representing numbers in a machine word with the selected parameters K and B.
From this, a very important conclusion can be drawn. Any normalization of a number is an operation leading to an unproductive use of computing resources.
The only thing to take care of when writing numbers to a machine word is to ensure that their mantissa and order values do not go beyond the bit grid of the machine word. 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 discharge grid.
Another very important conclusion can be drawn from the above reasoning. The rejection of the procedure for normalizing numbers allows you to explicitly get the value of zero and naturally cover the range of small numbers, without artificially introducing a class of denormalized numbers. This allows you to significantly simplify the process of writing numbers to a machine word and, as a result, significantly reduce the time it takes to perform mathematical operations.
LITERATURE.
1. habrahabr.ru/post/262245
2. wiki.mvtom.ru/index.php/Formy_predstavleniya_chisel_v_EVM
3. 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.html
5. neerc.ifmo.ru/wiki/index.php?title=Presentation_of_natural_numbers&printable=yes
Yuri Spiridonov.