Floating point (float, double, etc) (last update: 2012-09-20, created: 2012-09-20) back to the list ↑

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.01.010653532170.0000000000000000000000000000000000000000000014013
1.02.083886081.0000001192092896
2.03.041943042.0000002384185791
10.011.0104857610.000000953674316
100.0101.0131072100.00000762939453
1000.01001.0163841000.0000610351562
10000.010001.0102410000.0009765625
100000.0100001.0128100000.0078125
1000000.01000001.0161000000.0625
10000000.010000001.0110000001.0*
100000000.0...0100000008.0*
1000000000.0...01000000064.0*
10000000000.0...010000001024.0*
100000006144.0**...0100000014336.0*
1000000061440.0**...01000000126976.0*
10000000876544.0**...010000001925120.0*
100000000376832.0**...0100000008765440.0*
1000000054099968.0**...01000000121208832.0*
10000000272564224.0**...010000001346306048.0*
100000007020609540.0**...0100000015610544130.0*
1000000053026226200.0**...01000000121745702900.0*
10000001080018076000.0**...010000002179529703000.0*
100000002004087730000.0**...0100000010800180760000.0*
1000000020040877300000.0**...01000000090409621500000.0*
10000000904096215000000.0**...010000002029996122000000.0*
100000006789162340000000.0**...0100000015796361590000000.0*
1000000013848427900000000.0**...01000000085906021900000000.0*
10000000714945031000000000.0**...010000001867866535000000000.0*
100000002537764290000000000.0**...0100000011761136330000000000.0*
1000000062271131000000000000.0**...01000000136058107300000000000.0*
10000000622711310000000000000.0**...010000001803302931000000000000.0*
100000001504746620000000000000.0**...0100000010949479590000000000000.0*
1000000015047466200000000000000.0**...01000000090605329900000000000000.0*
10000000452706117000000000000000.0**...010000001057169027000000000000000.0*
100000003318135350000000000000000.0**...0100000012989541910000000000000000.0*
1000000071866979700000000000000000.0**...01000000149238232200000000000000000.0*
10000000409184788000000000000000000.0**...010000001028154807000000000000000000.0*
100000004091847880000000000000000000.0**...0100000013995368190000000000000000000.0*
1000000040918478800000000000000000000.0**...01000000120146641300000000000000000000.0*
10000000567641113000000000000000000000.0**...010000001201466413000000000000000000000.0*
100000006944061730000000000000000000000.0**...0100000017085266530000000000000000000000.0*

* denotes floats that have reached the boundary, where no fractional value can be encoded.
** marks a point where 10K can no longer be represented as float, and the given value is the closest that gets to a 10K value.
【 design & art by Xa / Gynvael Coldwind 】 【 logo font (birdman regular) by utopiafonts / Dale Harris 】