What is Floating Point?

A floating-point number is a numeric representation of a number that belongs to a specific subset of rational numbers. It is used in computers to approximate any arbitrary real number. Specifically, this real number is obtained by multiplying an integer or fixed-point number (that is, the mantissa) by an integer power of a base (usually 2 in a computer). This representation is similar to the scientific notation of base 10.

Floating point

(Rational number)

Floating point numbers are

Introduction to floating point numbers

Author: concreteHAM
What is a floating point number? Without further ado, here we are going to discuss the normalized probability distribution of the leading digits of an arbitrary base floating point number.
A very in-depth discussion was made in the second volume of "The Art of Computer Programming", from which I refined the main points.

Floating point instance

E.g:
2.345 E 67
Floating point
This is a decimal normalized floating point number with a leading number of 2.
As far as there is only one "random" floating-point number, it is meaningless to discuss its distribution. What we want to discuss is the leading number distribution of floating-point results produced by a series of operations performed on multiple "random" numbers.
Suppose now that there is a huge set of floating point numbers, and each floating point number in the logarithmic set is multiplied by 2. There is a decimal floating point number F whose leading digit is 1. Then the possible value range of its base is 1.000 ... 1.999 , Multiply by a number 2, then its base becomes 2.000 3.999, it is obvious that the number of floating-point numbers whose leading number is 1 before multiplying by 2 is the same as the number of floating-point numbers whose leading number is 2 and 3. . With this we analyze next.
For a floating-point number in B, the range of its leading digit x is 0 <x <b. Let f (x) be the probability density function of the leading digits of the above data set (Note: is the density function), then it is in the leading The probability between the numbers u and v (0 <u <v <b) is:
[u, v] f (x) dx
As stated earlier, for a sufficiently small increment x, f (x) must satisfy such a formula:
fx = x * f (x) x
because:
fx is the probability within f micro-segment. According to the previous description, fx probability is equal to f (1 * x) * (x * x)
It is clear:
f (x) = f / x
Integrate between [1, b] on both sides. The left side of the equal sign must be 1, and the right side is equal to fln (b):
1 = fln (b)
Obtain: f = 1 / ln (b) brought into :
f (x) = 1 / (x * ln (b))
Then use the formula to get:
[u, v] 1 / (x * ln (b)) dx
= ln (v / u) / ln (b)
This is the probability distribution function for finding the leading numbers.
For example, when b = decimal, the probability that the leading digit is 1 is:
= ln ((1 + 1) / 1) / ln
0.301
The probability that the leading number is 9 is:
= ln ((9 + 1) / 9) / ln
0.0458
The following is a test program (Mathematica software):
T [n_, b _]: = Block [{res = {}, ran, i, a},
For [i = 1, i <b, i ++;
res = Append [res, 0]
];
For [i = 0, i <n, i ++;
ran = Random [] * Random [] * Random []; Fully shuffle floating point numbers
ran = Log [b, ran];
a = Floor [b ^ (ran-Floor [ran])]; remove leading digits
res [[a]] ++ Statistics on the number of leading digits
];
Return [res]
]
Execute T [100000,10], test 100000 floating point numbers in decimal, and get a distribution:
{30149,18821,13317,9674,7688,6256,5306,4655,4134}
Quite close to the theoretical value.

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?