Skip to content

Instantly share code, notes, and snippets.

@foxpy
Last active April 21, 2021 03:45
Show Gist options
  • Save foxpy/8916aa6fc1f7928a0d64ed6073c5692c to your computer and use it in GitHub Desktop.
Save foxpy/8916aa6fc1f7928a0d64ed6073c5692c to your computer and use it in GitHub Desktop.
floats
; cat demo.c
#include <stdio.h>
int main(void) {
double d = 0.00000001337;
for (int i = 0; i < 100; ++i) {
printf("%02d: %130.100f\n", i, d);
d *= 2.0;
}
}
; cc demo.c
; ./a.out
00: 0.0000000133699999999999999455536708273944990210679861775133758783340454101562500000000000000000000000
01: 0.0000000267399999999999998911073416547889980421359723550267517566680908203125000000000000000000000000
02: 0.0000000534799999999999997822146833095779960842719447100535035133361816406250000000000000000000000000
03: 0.0000001069599999999999995644293666191559921685438894201070070266723632812500000000000000000000000000
04: 0.0000002139199999999999991288587332383119843370877788402140140533447265625000000000000000000000000000
05: 0.0000004278399999999999982577174664766239686741755576804280281066894531250000000000000000000000000000
06: 0.0000008556799999999999965154349329532479373483511153608560562133789062500000000000000000000000000000
07: 0.0000017113599999999999930308698659064958746967022307217121124267578125000000000000000000000000000000
08: 0.0000034227199999999999860617397318129917493934044614434242248535156250000000000000000000000000000000
09: 0.0000068454399999999999721234794636259834987868089228868484497070312500000000000000000000000000000000
10: 0.0000136908799999999999442469589272519669975736178457736968994140625000000000000000000000000000000000
11: 0.0000273817599999999998884939178545039339951472356915473937988281250000000000000000000000000000000000
12: 0.0000547635199999999997769878357090078679902944713830947875976562500000000000000000000000000000000000
13: 0.0001095270399999999995539756714180157359805889427661895751953125000000000000000000000000000000000000
14: 0.0002190540799999999991079513428360314719611778855323791503906250000000000000000000000000000000000000
15: 0.0004381081599999999982159026856720629439223557710647583007812500000000000000000000000000000000000000
16: 0.0008762163199999999964318053713441258878447115421295166015625000000000000000000000000000000000000000
17: 0.0017524326399999999928636107426882517756894230842590332031250000000000000000000000000000000000000000
18: 0.0035048652799999999857272214853765035513788461685180664062500000000000000000000000000000000000000000
19: 0.0070097305599999999714544429707530071027576923370361328125000000000000000000000000000000000000000000
20: 0.0140194611199999999429088859415060142055153846740722656250000000000000000000000000000000000000000000
21: 0.0280389222399999998858177718830120284110307693481445312500000000000000000000000000000000000000000000
22: 0.0560778444799999997716355437660240568220615386962890625000000000000000000000000000000000000000000000
23: 0.1121556889599999995432710875320481136441230773925781250000000000000000000000000000000000000000000000
24: 0.2243113779199999990865421750640962272882461547851562500000000000000000000000000000000000000000000000
25: 0.4486227558399999981730843501281924545764923095703125000000000000000000000000000000000000000000000000
26: 0.8972455116799999963461687002563849091529846191406250000000000000000000000000000000000000000000000000
27: 1.7944910233599999926923374005127698183059692382812500000000000000000000000000000000000000000000000000
28: 3.5889820467199999853846748010255396366119384765625000000000000000000000000000000000000000000000000000
29: 7.1779640934399999707693496020510792732238769531250000000000000000000000000000000000000000000000000000
30: 14.3559281868799999415386992041021585464477539062500000000000000000000000000000000000000000000000000000
31: 28.7118563737599998830773984082043170928955078125000000000000000000000000000000000000000000000000000000
32: 57.4237127475199997661547968164086341857910156250000000000000000000000000000000000000000000000000000000
33: 114.8474254950399995323095936328172683715820312500000000000000000000000000000000000000000000000000000000
34: 229.6948509900799990646191872656345367431640625000000000000000000000000000000000000000000000000000000000
35: 459.3897019801599981292383745312690734863281250000000000000000000000000000000000000000000000000000000000
36: 918.7794039603199962584767490625381469726562500000000000000000000000000000000000000000000000000000000000
37: 1837.5588079206399925169534981250762939453125000000000000000000000000000000000000000000000000000000000000
38: 3675.1176158412799850339069962501525878906250000000000000000000000000000000000000000000000000000000000000
39: 7350.2352316825599700678139925003051757812500000000000000000000000000000000000000000000000000000000000000
40: 14700.4704633651199401356279850006103515625000000000000000000000000000000000000000000000000000000000000000
41: 29400.9409267302398802712559700012207031250000000000000000000000000000000000000000000000000000000000000000
42: 58801.8818534604797605425119400024414062500000000000000000000000000000000000000000000000000000000000000000
43: 117603.7637069209595210850238800048828125000000000000000000000000000000000000000000000000000000000000000000
44: 235207.5274138419190421700477600097656250000000000000000000000000000000000000000000000000000000000000000000
45: 470415.0548276838380843400955200195312500000000000000000000000000000000000000000000000000000000000000000000
46: 940830.1096553676761686801910400390625000000000000000000000000000000000000000000000000000000000000000000000
47: 1881660.2193107353523373603820800781250000000000000000000000000000000000000000000000000000000000000000000000
48: 3763320.4386214707046747207641601562500000000000000000000000000000000000000000000000000000000000000000000000
49: 7526640.8772429414093494415283203125000000000000000000000000000000000000000000000000000000000000000000000000
50: 15053281.7544858828186988830566406250000000000000000000000000000000000000000000000000000000000000000000000000
51: 30106563.5089717656373977661132812500000000000000000000000000000000000000000000000000000000000000000000000000
52: 60213127.0179435312747955322265625000000000000000000000000000000000000000000000000000000000000000000000000000
53: 120426254.0358870625495910644531250000000000000000000000000000000000000000000000000000000000000000000000000000
54: 240852508.0717741250991821289062500000000000000000000000000000000000000000000000000000000000000000000000000000
55: 481705016.1435482501983642578125000000000000000000000000000000000000000000000000000000000000000000000000000000
56: 963410032.2870965003967285156250000000000000000000000000000000000000000000000000000000000000000000000000000000
57: 1926820064.5741930007934570312500000000000000000000000000000000000000000000000000000000000000000000000000000000
58: 3853640129.1483860015869140625000000000000000000000000000000000000000000000000000000000000000000000000000000000
59: 7707280258.2967720031738281250000000000000000000000000000000000000000000000000000000000000000000000000000000000
60: 15414560516.5935440063476562500000000000000000000000000000000000000000000000000000000000000000000000000000000000
61: 30829121033.1870880126953125000000000000000000000000000000000000000000000000000000000000000000000000000000000000
62: 61658242066.3741760253906250000000000000000000000000000000000000000000000000000000000000000000000000000000000000
63: 123316484132.7483520507812500000000000000000000000000000000000000000000000000000000000000000000000000000000000000
64: 246632968265.4967041015625000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
65: 493265936530.9934082031250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
66: 986531873061.9868164062500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
67: 1973063746123.9736328125000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
68: 3946127492247.9472656250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
69: 7892254984495.8945312500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
70: 15784509968991.7890625000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
71: 31569019937983.5781250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
72: 63138039875967.1562500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
73: 126276079751934.3125000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
74: 252552159503868.6250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
75: 505104319007737.2500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
76: 1010208638015474.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
77: 2020417276030949.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
78: 4040834552061898.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
79: 8081669104123796.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
80: 16163338208247592.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
81: 32326676416495184.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
82: 64653352832990368.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
83: 129306705665980736.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
84: 258613411331961472.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
85: 517226822663922944.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
86: 1034453645327845888.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
87: 2068907290655691776.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
88: 4137814581311383552.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
89: 8275629162622767104.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
90: 16551258325245534208.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
91: 33102516650491068416.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
92: 66205033300982136832.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
93: 132410066601964273664.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
94: 264820133203928547328.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
95: 529640266407857094656.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
96: 1059280532815714189312.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
97: 2118561065631428378624.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
98: 4237122131262856757248.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
99: 8474244262525713514496.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment