The representation of real numbers in floating-point / comma format, which is enshrined in the IEEE754 standard, is a lot of work. Including on Habrahabr. Not being a programmer, the author tried to deal with this beast from the point of view of simple school mathematics. Based not on the formats approved in the standard, but on the natural notions of numbers. It is possible that such a view from the side will be of interest to professional programmers. This is especially true of issues related to denormalized numbers.
1. NATURAL AND EXPONENTIAL FORM FOR RECORDING NUMBERS
It is known from mathematics that any real number F in the positional number system with base q is written on paper as a sequence of numbers. The weight of the number depends on its position in the number. The base of the system q is equal to the number of digits (characters of its alphabet) and determines how many times the values of digits of adjacent digits of a number differ. This record of the number is called natural and looks like this:
F = c_ (L-1,) c_ (L-2) ... c_ (0.) D_ (0) ... d_ (N-2,) d_ (N-1,) (1)
Where c_ (L-1,) c_ (L-2) ... c_0 are the digits of the integer part, and d_ (0) ... d_ (N-2,) d_ (N-1) are digits of the fractional part of a number. A number may consist of an arbitrarily large number of significant digits L of the integer part and N digits of the fractional part.
If the point in the number F represented by expression (1) is moved to h bits to the left, then we get a new number M, which is connected with the original number by the formula, which is an exponential dependence:
')
M = F • q ^ (- h)
The value of F in this case will decrease by h times. So that the number does not change, it is multiplied by the value q ^ h. Thus, the number written in the natural form (1) can be represented in an equivalent exponential form:
F = M • q ^ h
If the point in the number F represented by expression (1) is moved to h bits to the right, then we get the new number M, which is connected with the original number by the formula:
M = F • q ^ h
The value of F in this case will increase by h times. So that the number does not change, it is multiplied by the value q ^ (- h). Thus, for the case under consideration, the number written in the natural form (1) can be represented in the following equivalent exponential form:
F = M • q ^ (- h)
In general, any real number written in the natural form (1) can be written in its equivalent exponential form as follows:
F = M ∙ q ^ (± h) (2)
where M represents the number (1) 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, which is also called an exponent in the literature. 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 (1). Both entries (1) and (4) are the entries of the same number in different ways.
The number (1) has L + N digits. Since in the natural representation of number (1) the number of digits L of the integer part and N digits of the fractional part can have an arbitrarily large value, the number M in (2) can also have an arbitrarily large number of digits. In general, the number of digits of M in (2) can be infinite. For example, when the number is a periodic fraction, or the number is irrational. In practice, we deal with a limited number of digits to represent a real number in a natural form. No matter how many digits of the number we write on the right, sooner or later we must limit the number of digits of the represented number. If only because there will be nowhere to write. As a result, the number is first limited and then rounded to the extreme right digit acceptable for a given task. In this case, of course, the accuracy of the representation of this number is lost. We do not touch on the accuracy of the representation of numbers in mathematics. This issue is devoted to a huge number of works. We only note that the accuracy of the representation of a number is chosen within reasonable limits and therefore the real number is always recorded with a limitation of bit depth. Thus, strictly speaking, it becomes a rational number. In the computer literature, numbers with a fractional part are usually called real numbers. We will also stick to this terminology.
In mathematics, as a rule, the representation of numbers in the exponential form is resorted to when the number written in the natural form (1) has insignificant zeros. To shorten the record and not to write recurring insignificant digits use the record number in the exponential form (2). Then the order of the characteristic h indicates the number of insignificant zeros before or after the point. In a more general case, the number h with a sign, as we saw above, indicates the number of displacements of a point relative to its initial position in the number. In any case, when the number of shifts h is indicated, the reference point is always known, relative to which the separation point in the number is shifted.
2. REPRESENTATION OF NUMBERS IN THE MACHINE WORD
In the computing device for recording the number of limited bit space is allocated. Therefore, the numbers written in the machine word are subject to certain restrictions, which determine the accuracy of the representation of numbers and the range of values they take.
A binary number, represented in exponential form, is recorded in the computer as a machine word, divided into special areas. The structure of a machine word can be schematically represented as follows:

In this word, K digits are assigned to record the mantissa M, R digits for recording the order h of the characteristic and one digit for the sign S of the number and z the sign of the order. The machine space allocated for the record of the mantissa of a number will be called the area of the machine mantissa (OMM), and the number recorded in this area is the machine mantissa. Similarly, the space allocated in the machine for recording the order of the characteristic will be called the area of machine order (OMP) characteristic, and the number written in this area will be called machine order. If the OMM explicitly contains a point, then the numbers represented in this format are called fixed-point numbers. Next, we will consider the numbers written in exponential form (2). Numbers represented in this format are also called floating point numbers.
3. NORMALIZATION OF NUMBERS
As noted above, when converting a number written in its natural form to an exponential form, a point in the number of the form (1) can be shifted to an arbitrary number of digits to the right or left. And so that the value of the number does not change, the order of the characteristics of the exponential number must be adjusted by the number of displacements. Obviously, this results in a multiplicity of representations of the same number, written in exponential form.
Take the binary number 0.001001 and write it exponentially in a machine word, in which the OMM has 3 digits. In the case when it is assumed that the machine mantissa is represented in the form of a regular fraction, we will have the following options for writing this number: 0.1001 • 2 ^ (- 2) = 0.100 • 2 ^ (- 2) = 0.010 • 2 ^ (- 1) = 0.001 • 2 ^ 0. In all these cases, the low order of the recorded number was lost because it went beyond the limits of the OMM bit grid. So, we got a record of the same number of different options.
There is an ambiguity in the representation of numbers in a machine word. We must indicate to the machine the selection criteria for which one preference is given to one or another form of writing numbers in a machine word. Writing an exponential number in a format in which the mantissa of a number is represented uniquely is called normalization.
At present, two variants of the normalization of numbers are most often considered. In the first version [1], before writing to a machine word, the number is represented as a binary fractional number, in which the unit is immediately after the point. With such a normalization, the binary mantissa in the form of a regular fraction lies in the range of 0.1≤M <1. Another variant of the normalization is as follows. The actual number before writing to the machine word is reduced to the form in which the mantissa is a mixed fraction, in which a significant digit is necessarily present in the low order of the integer part. For a binary number, this digit is one. This normalization option is enshrined in the IEEE754 standard.
4. VALID NUMBERS IN THE REPRESENTATION OF IEEE754 STANDARD
Currently, in computer arithmetic, for operating with real numbers, the IEEE754 standard is widely used [2]. This standard introduced the class of normalized numbers, which allows to solve two problems. One of them is an ambiguous representation of floating-point numbers. And the second problem is getting the ability to represent numbers in a wide range of values. To solve these problems, it was suggested, before writing a real number into the machine word, to bring it to a normalized form.
Consider the features of the representation of real floating-point numbers in the IEEE754 standard.
In accordance with the standard, all numbers in a machine word are represented in a normalized form. To do this, they are converted to the form:
F = s ∙ 2 ^ (± h) ∙ 1.M
Here 1.M is the mantissa consisting of one in the integer part and the number M, which is recorded in OMM immediately after the unit. The values of the mantissa in normalized numbers are in the interval:
1 ≤ 1.M <2,
and the values of the orders of the characteristics of numbers lie in the range - (B-1) ≤ h ≤ B. Here B is the maximum number that can be written into the OMP of a computer word.
The binary normalized number in a machine word with a K-bit OMM is schematically as follows:

The arrangement of digits for the sign of order z and the sign of the number S in the computer word can be arbitrary. This does not affect the character of representable numbers. As can be seen from this figure, the K-th digit in the mantissa of the normalized number is always equal to one. This digit is present in the virtual word virtually. In fact, it is not in the bit grid. Nevertheless, a virtual unit is always taken into account when representing numbers and when performing mathematical operations on them. It is assumed that in the normalized number the point in the mantissa is located to the right of the unit.
In the standard, in order to save on the sign of order, an offset representation of the orders of the characteristics of the numbers written in the machine word is used. For simplicity, the values of the order of the characteristics we present hereinafter without offset.
With a normalized representation of numbers, a problem immediately arises due to the absence of zero. In normalized numbers, zero is outside the range of the mantissa values. This circumstance does not allow to obtain a zero result of calculations. With mathematical operations on normalized numbers in a computer, zero is not explicitly obtained, but its sign is obtained.
And the second problem that arises during the normalization of numbers is the limitation of the range of representation of small numbers, due to the fact that the values of the mantissa of normalized numbers do not exceed unity. This forced the authors of the standard to introduce a class of denormalized numbers, which significantly complicated the algorithms for working with such numbers.
The minimum normalized number that can be written to a machine word looks schematically as follows:

This number, taking into account the position of the implicit unit, can be represented by the following expression:
| F_min | = S 2 ^ (- ) (1 + 0) = S 2 ^ (- )
Where B is the maximum number recorded in the WMD. The number 2 ^ (- ) in the standard is considered a special number, which is taken as ± 0. The sign at zero takes its value in accordance with the value of the sign S of the number. Further, for simplicity, we will consider only positive numbers.
The minimum positive normalized number in the standard is the number of the form:

Thus, the minimum normalized number in the standard is represented by the formula:
| F_min | = 2 ^ (- (B-1))
The equality of the order of the characteristic number (-B) in the standard is reserved for the sign of a special case. The step with which the values of the normalized numbers change is ξ = 2 ^ (- B)
The maximum positive normalized number in the standard is represented as

This number can be written as an expression:
| F_max | = 2 ^ B • (2-2 ^ (- K))
Calculate the range of representable numbers normalized by the standard:
| F_max | / | F_min | = 2 ^ B • (2-2 ^ (- )) / 2 ^ (- + 1) = 2 ^ (2) • (1-2 ^ (- ( + 1))) ≈ 2 ^ 2
As we see, the range of representable normalized numbers is mainly determined by the range of numbers that can be written into the WMD.
Note also that even when K = 1, when the mantissa of a number contains only one digit, choosing the appropriate value B can be written down either a very large or a very small number. Figuratively speaking, the mantissa in the number presented in an exponential form, by analogy with a geographical map, determines the number of objects that we consider, and the coefficient q ^ (± h) is a scale factor determining the distance between these objects. With an increase in the scale factor q ^ (± h), with a limited area of the map (OMM bit depth), smaller objects (numbers) become distinguishable, and the number of distinguishable objects (numbers) decreases. In the decimal number system, often, to describe the quantitative characteristics of physical objects, instead of the coefficient q ^ (± h), the prefixes nano, micro, miles, kilo, mega, etc. are used.
In order to expand the range of representable numbers in the direction of values close to zero, the standard introduces a class of denormalized numbers. Denormalized numbers are numbers that are determined by the formula:
F_den = 2 ^ (- (B-1)) • (M • 2 ^ (- K))
In this expression, M is an integer in the range 1≤ M≤ (2 ^ (K-1)). A mantissa (M • 2 ^ (- K)) is a fractional number that lies in the range
2 ^ (- ) ≤ (M • 2 ^ (- )) <1 -2 ^ (- ) (3)
As this shows, there is no implicit unit in the expression for denormalized numbers. At the moment when the characteristic of the normalized number becomes equal to 2 ^ (- B) (a special case), further transformations are carried out as if the characteristic of the number is equal to 2 ^ (- (B-1)). And the values of the fractional mantissa are in the range (3). This allows you to go from the field of normalized numbers to the field of denormalized numbers smoothly, without a jump. In the domain of denormalized numbers, the step of changing numbers becomes ξ = 2 ^ (- (B-1 + K)). When the value of the mantissa of the denormalized number becomes zero, the number is considered to be machine zero.
A denormalized positive number in a machine word schematically looks like this:

The minimum positive denormalized number in a machine word looks like:

The formula for the minimum denormalized number is as follows:
F_ (den min) = 2 ^ (- (B-1 + K)) = 2 ^ (- (B + K-1))
The maximum positive denormalized number looks in the machine word schematically as follows:

The formula for calculating the maximum denormalized number is:
F_ (den max) = 2 ^ (- (B-1)) (1 - ^ (- K))
The range of denormalized numbers that can be represented in the standard is:
F_ (den max) / F_ (den min) = 2 ^ (B-1) (1-2 ^ (- K)) / 2 ^ (- (B + K-1)) = 2 ^ (2B-2) (2 ^ K-1)
Below, for example, is a table in which the conversion of a sequence of numbers before writing them into a machine word is presented, in accordance with the IEEE754 standard. It is assumed that OMM consists of K = 2 digits, plus an implicit unit. In the WMD, you can write the maximum number B = 2. The minimum number from which the counting of the normalized numbers begins is | F_min | = 2 ^ (- 2 + 1) = 2 ^ (- 1) = 0.1. In the table, this area is represented by numbers on a white background. From line 1 to line 3, on a gray background, the table shows the region of denormalized numbers for which F_ (den min) = 2 ^ (- (2 + 2-1)) = 2 ^ (- 3). The change step for these numbers is ξ = 0.001.

In the 1st column of the table the steps of changing the number from the minimum to the maximum are numbered. Column 2 contains the numbers that are formed with each new step. The x symbol here means an arbitrary digit, zero or one. Numbers designated as x do not participate in the formation of the mantissa of a machine word. Column 3 shows the mantissa of the number, after its normalization. Column 4 presents the order values of the characteristics of numbers after their normalization. Column 5 presents the machine order values of the characteristics of numbers written to the machine word. Column 6 represents the denormalized numbers that are written to the OMM. In column 7 the unique denormalized numbers are numbered, which are written in a machine word. And in column 8 the unique normalized numbers are numbered.
As follows from the values of the numbers written in the machine word in the table, the range of representable binary normalized numbers is 1.11 • 2 ^ 2 / 1.0 • 2 ^ (- 1) = 7 / 0.5 = 14. At the same time, the range of the normalized and denormalized numbers taken together will be 1.11 · 2 ^ 2 / 0.01 · 2 ^ (- 1) = 7 / 0.125 = 56. It is seen that the range of representable numbers, defined as the ratio of the maximum representable number to the minimum does not coincide with the number of representable numbers.
Looking at the table, you can see that while the machine order is equal to the minimum value (h = -1), an increase of 1 in the value of the mantissa leads to an increase in the number written in the machine word also by 1. After the number in p. 2 becomes the binary number is 0.111, the next increment of 1 gives the number 1.000, which does not fit into the OMM bit grid. Therefore, we shift the point in the mantissa of the number by one digit to the left and increase the machine order by one. Further, the change in machine numbers occurs with a double step value. With each increase in the number h by one, the distance between the adjacent values of machine numbers is doubled.
LITERATURE
1.
wiki.mvtom.ru/index.php/Forms_presentation_number_in_Computer2. 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.
3.
www.softelectro.ru/ieee754.html4.
neerc.ifmo.ru/wiki/index.php?title=Representation of real_numbers&printable=yes