IEEE-754 32-bit float, x86
Number of floats
There are
2,139,095,039 positive float numbers.
To compare, there are 2,147,483,647 positive int numbers.
So that's 8,388,608 representable positive values less in floats than in ints.
Floats are symmetrical, so there is the exact same number of negative floats.
There are two zeroes - positive and negative.
Code used to calculate the number of positive floats:
#include <stdio.h>
#include <math.h>
#include <float.h>
int
main(void) {
float f = 0.0f;
unsigned int cnt = 0;
for(;;) {
f = nextafterf(f, INFINITY);
if(f == HUGE_VAL) break;
cnt++;
}
printf("There are %u positive numbers\n", cnt);
return 0;
}
Float values vs decimal integer boundaries
Number of floats between decimal boundaries (these values were printed using printf's %f from msvcrt, so they probably are not accurate; TODO: think of something better):
From |
To (From+1) |
Number of representable values between [From,To) |
Next representable value after From |
0.0 | 1.0 | 1065353217 | 0.0000000000000000000000000000000000000000000014013 |
|
1.0 | 2.0 | 8388608 | 1.0000001192092896 |
|
2.0 | 3.0 | 4194304 | 2.0000002384185791 |
|
10.0 | 11.0 | 1048576 | 10.000000953674316 |
|
100.0 | 101.0 | 131072 | 100.00000762939453 |
|
1000.0 | 1001.0 | 16384 | 1000.0000610351562 |
|
10000.0 | 10001.0 | 1024 | 10000.0009765625 |
|
100000.0 | 100001.0 | 128 | 100000.0078125 |
|
1000000.0 | 1000001.0 | 16 | 1000000.0625 |
|
10000000.0 | 10000001.0 | 1 | 10000001.0* |
100000000.0 | ... | 0 | 100000008.0* |
1000000000.0 | ... | 0 | 1000000064.0* |
10000000000.0 | ... | 0 | 10000001024.0* |
100000006144.0** | ... | 0 | 100000014336.0* |
1000000061440.0** | ... | 0 | 1000000126976.0* |
10000000876544.0** | ... | 0 | 10000001925120.0* |
100000000376832.0** | ... | 0 | 100000008765440.0* |
1000000054099968.0** | ... | 0 | 1000000121208832.0* |
10000000272564224.0** | ... | 0 | 10000001346306048.0* |
100000007020609540.0** | ... | 0 | 100000015610544130.0* |
1000000053026226200.0** | ... | 0 | 1000000121745702900.0* |
10000001080018076000.0** | ... | 0 | 10000002179529703000.0* |
100000002004087730000.0** | ... | 0 | 100000010800180760000.0* |
1000000020040877300000.0** | ... | 0 | 1000000090409621500000.0* |
10000000904096215000000.0** | ... | 0 | 10000002029996122000000.0* |
100000006789162340000000.0** | ... | 0 | 100000015796361590000000.0* |
1000000013848427900000000.0** | ... | 0 | 1000000085906021900000000.0* |
10000000714945031000000000.0** | ... | 0 | 10000001867866535000000000.0* |
100000002537764290000000000.0** | ... | 0 | 100000011761136330000000000.0* |
1000000062271131000000000000.0** | ... | 0 | 1000000136058107300000000000.0* |
10000000622711310000000000000.0** | ... | 0 | 10000001803302931000000000000.0* |
100000001504746620000000000000.0** | ... | 0 | 100000010949479590000000000000.0* |
1000000015047466200000000000000.0** | ... | 0 | 1000000090605329900000000000000.0* |
10000000452706117000000000000000.0** | ... | 0 | 10000001057169027000000000000000.0* |
100000003318135350000000000000000.0** | ... | 0 | 100000012989541910000000000000000.0* |
1000000071866979700000000000000000.0** | ... | 0 | 1000000149238232200000000000000000.0* |
10000000409184788000000000000000000.0** | ... | 0 | 10000001028154807000000000000000000.0* |
100000004091847880000000000000000000.0** | ... | 0 | 100000013995368190000000000000000000.0* |
1000000040918478800000000000000000000.0** | ... | 0 | 1000000120146641300000000000000000000.0* |
10000000567641113000000000000000000000.0** | ... | 0 | 10000001201466413000000000000000000000.0* |
100000006944061730000000000000000000000.0** | ... | 0 | 100000017085266530000000000000000000000.0* |
* denotes floats that have reached the boundary, where no fractional value can be encoded.
** marks a point where 10
K can no longer be represented as float, and the given value is the closest that gets to a 10
K value.