{"id":3232,"date":"2026-05-11T16:39:54","date_gmt":"2026-05-11T14:39:54","guid":{"rendered":"https:\/\/geekosas.com\/?p=3232"},"modified":"2026-05-23T12:47:48","modified_gmt":"2026-05-23T10:47:48","slug":"hasta-cuanto-sabe-contar-el-ordenador-2","status":"publish","type":"post","link":"https:\/\/geekosas.com\/index.php\/2026\/05\/11\/hasta-cuanto-sabe-contar-el-ordenador-2\/","title":{"rendered":"How well can a computer count?"},"content":{"rendered":"<p>My 2-year-old son knows how to count up to 10; after that he starts to \u201cimprovise,\u201d so I can say he knows how to count up to 10.<\/p>\n<p>With computers it is similar: if you repeatedly add 1 to a number, eventually the PC will make a mistake. Yes, the computer can make mistakes; in fact, there is an entire field dedicated to bounding errors in PC calculations, called numerical error.<\/p>\n<p>To understand how a computer can make mistakes, first we have to distinguish how it understands numbers. There are 2 ways: integers and floats, decimals or floating-point numbers. Like all data on a PC, both are stored as sequences of bits, 0 or 1, and they differ in how the bits are interpreted.<\/p>\n<p>For the first case, integers, it is quite simple, but it will help us understand float types.<\/p>\n<h4>Integer<\/h4>\n<p>Integers come in different sizes depending on the number of bits used to store them. For example, a 4-bit integer would write numbers as follows:<\/p>\n<blockquote>\n<p>0=0000<br \/>\n1=0001<br \/>\n2=0010<br \/>\n3=0011<br \/>\n4=0100<br \/>\n5=0101<br \/>\n6=0110<br \/>\n7=0111  <\/p>\n<\/blockquote>\n<p>With 4 bits, we can count only up to 7 because the last bit is used to denote the sign of the number, positive or negative. Thus, negative numbers would be written as follows:<\/p>\n<blockquote>\n<p>-1=1000<br \/>\n-2=1001<br \/>\n-3=1010<br \/>\n-4=1011<br \/>\n-5=1100<br \/>\n-6=1101<br \/>\n-7=1110<br \/>\n-8=1111  <\/p>\n<\/blockquote>\n<p>In general, we can say that for an integer with <code class=\"katex-inline\">n<\/code> bits, we can represent numbers up to <code class=\"katex-inline\">2^{n-1}-1<\/code> for the positive case and <code class=\"katex-inline\">2^{n-1}<\/code> for the negative case.<\/p>\n<p>PC integers can have different sizes, generally 32, 64, or 128 bits, where the maximum sizes are the following:<\/p>\n<p>32 bit: <code class=\"katex-inline\">2^{31}-1<\/code> = 2,147,483,647<br \/>\n64 bit: <code class=\"katex-inline\">2^{63}-1<\/code> = 9,223,372,036,854,775,807<br \/>\n128 bit: <code class=\"katex-inline\">2^{127}-1<\/code> = 170,141,183,460,469,231,731,687,303,715,884,105,727  <\/p>\n<p>Now, what happens when we exceed this number? Well, it depends on the programming language.<\/p>\n<h5>Python<\/h5>\n<p>Python 3.x is a special case: it handles integers in another way, so it has no limit. This makes it considerably slower, but it can calculate them as long as it wants, at least that is what I got in my results.<\/p>\n<pre><code class=\"language-python\">>&gt;&gt; n = (2**1000)\n>&gt;&gt; print(n)\n10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376\n>&gt;&gt; type(n)\n&lt;class &#039;int&#039;&gt;<\/code><\/pre>\n<p>The above is quite convenient, but it makes it slow. That is why Python has the NumPy library, which works the way the CPU works natively, obtaining faster calculations. The first interesting thing is that when a 32-bit integer exceeds its maximum size, it becomes a 64-bit one.<\/p>\n<pre><code class=\"language-python\">>&gt;&gt; n = np.int32(2**31-1)\n>&gt;&gt; print(n)\n2147483647\n>&gt;&gt; type(n)\n&lt;class &#039;numpy.int32&#039;&gt;\n>&gt;&gt; print(n+1)\n2147483648\n>&gt;&gt; type(n + 1)\n&lt;class &#039;numpy.int64&#039;&gt;<\/code><\/pre>\n<p>If we force <code>n+1<\/code> to be 32-bit, the counter starts from the most negative number that can be represented:<\/p>\n<pre><code class=\"language-python\">>&gt;&gt; np.int32(n + 1)\n-2147483648<\/code><\/pre>\n<p>The above happens because in binary 2147483647 = 011111111111111111111111111111111, so when adding 1, the result is 1000000000000000000000000000000, which is -2147483648.<\/p>\n<p>On the other hand, the largest int in NumPy is 64-bit. What will it do if it cannot increase its size? Will it switch to another integer type with greater capacity or start from the negative side?<\/p>\n<pre><code class=\"language-python\">>&gt;&gt; n = np.int64(2**63-1)\n>&gt;&gt; print(n)\n9223372036854775807\n>&gt;&gt; type(n)\n&lt;class &#039;numpy.int64&#039;&gt;\n>&gt;&gt; print(n+1)\n-9223372036854775808\n>&gt;&gt; type(n + 1)\n&lt;class &#039;numpy.int64&#039;&gt;<\/code><\/pre>\n<p>Clearly, it starts from the negative side because the largest integer implemented in NumPy is the 64-bit one.<\/p>\n<h5>R<\/h5>\n<p>In R, integers are 32-bit by default. There are libraries for working with 64-bit integers, but they are not native. We can see that R will warn us that the maximum was exceeded, so we can be calm knowing there will be no strange behavior.<\/p>\n<pre><code class=\"language-R\">> n = 2147483647L\n> n+1L\n[1] NA\nWarning message:\nIn n + 1L : NAs produced by integer overflow<\/code><\/pre>\n<h5>Julia<\/h5>\n<p>Julia makes the same mistake as Python, without warning that it will make an error.<\/p>\n<pre><code class=\"language-julia\">julia&gt; n = Int32(2147483647)\n2147483647\n\njulia&gt; n + Int32(1)\n-2147483648<\/code><\/pre>\n<p>Finally, Julia can handle integers of up to 128 bits, allowing them to count up to: 170,141,183,460,469,231,731,687,303,715,884,105,727; after that, it will return to the negative side.<\/p>\n<h4>Floats or floating point<\/h4>\n<p>In general, the PC uses floats instead of integers, but the previous explanation helps us understand this case.<\/p>\n<p>Here things get a bit more complex. Imagine you have a very, very long number. It does not make much sense to use all the digits; only the last ones will be significant or relevant. That is why scientific notation exists, where, for example, 123,456,789,012,345,678,901,234,567,890 is written as <code class=\"katex-inline\">1.23456 * 10^{29}<\/code>, discarding the non-significant numbers. The PC does the same thing to store float-type numbers, but in binary.<\/p>\n<p>In general, the PC uses 64-bit floats called doubles, but for this exercise we will use 32-bit floats, or singles. In a 32-bit float, out of the 32 bits, 24 are used to write the significant digits, while the remaining 8 are used for the exponent in scientific notation.<\/p>\n<p>Theoretically, the largest number that a 32-bit float can store is on the order of <code class=\"katex-inline\">2^{2^{7}-1} = 2^{127} \\sim 10^{38}<\/code>, but the question is not what the largest number is; it is how far the PC can count.<\/p>\n<p>When we count, we add 1 to a number until we no longer know how to calculate the next number. At what point, when adding 1 to a float, will it return an incorrect result?<\/p>\n<p>Let\u2019s answer the question using Julia, which has excellent data type handling. To do this, we will count from 0 using a 64-bit integer and a 32-bit float. When they produce different results in some addition, it means the float made a mistake, so it cannot count any further.<\/p>\n<p>This happens because adding 1 to a very large number ends up being insignificant.<\/p>\n<pre><code class=\"language-julia\">julia&gt; float = Float32(0)\n0.0f0\n\njulia&gt; int = Int64(0)\n0\n\njulia&gt; while int == float\n           float = float + 1\n           int = int + 1\n       end\n\njulia&gt; Int64(float)\n16777216\n\njulia&gt; int\n16777217<\/code><\/pre>\n<p>Exactly at 16,777,216, when adding 1, the 1 is so insignificant that the result of the sum will be the same previous number, so it will stop counting and get stuck at: 16,777,216.<\/p>\n<p>In Python it is the same story, but it takes a loooong time:<\/p>\n<pre><code class=\"language-python\">>&gt;&gt; i = np.int64(0)\n>&gt;&gt; f = np.float32(0)\n>&gt;&gt; while i == f:\n...   i = i + np.int64(1)\n...   f = f + np.float32(1)\n... \n>&gt;&gt; print(i)\n16777217\n>&gt;&gt; print(f)\n16777216.0<\/code><\/pre>\n<p>This number, 16,777,216, corresponds to <code class=\"katex-inline\">2^24<\/code>, where 24 is precisely the number of bits used to store the significant digits.<\/p>\n<p>It does not look like such a large number, but the PC actually uses double-precision floats, that is, 64-bit floats, which use 12 bits for the exponent and 56 for the significant digits. So, extrapolating this experiment, the largest number would be <code>$$ 2^52$$ = 4,503,599,627,370,495<\/code><\/p>\n<p>What will happen in Excel when adding 1 to that number?<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2021\/10\/image-1634520143885.png?ssl=1\" alt=\"file\" \/><\/p>\n<p>Well, we can see that Excel made a mistake, so be careful if you start counting wheat grains to obtain the chess license, because with Excel you will not be able to count the number of grains you will need. If you did not understand the joke, you can watch this video: <a href=\"https:\/\/www.youtube.com\/watch?v=ziWYaYjJ8zk\">https:\/\/www.youtube.com\/watch?v=ziWYaYjJ8zk<\/a><\/p>\n<p>Regards, I hope you liked it.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>My 2-year-old son knows how to count up to 10; after that he starts to \u201cimprovise,\u201d so I can say he knows how to count <a class=\"mh-excerpt-more\" href=\"https:\/\/geekosas.com\/index.php\/2026\/05\/11\/hasta-cuanto-sabe-contar-el-ordenador-2\/\" title=\"How well can a computer count?\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":3011,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-3232","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sin-categoria"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2021\/10\/vocab-10256-counting.jpg?fit=800%2C460&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8vjqF-Q8","jetpack-related-posts":[{"id":3330,"url":"https:\/\/geekosas.com\/index.php\/2018\/05\/23\/elastic-computing-for-begginers-spanish-video\/","url_meta":{"origin":3232,"position":0},"title":"Elastic Computing for Begginers (Spanish video)","author":"Daniel Fischer","date":"2018-05-23","format":false,"excerpt":"I made a video showing how to use a template of an EC2 Instance (Virtual PC) for Data Science\/Analytics in AWS using elastic computing. The AMI image was built by me and is based on Arch, so you can always have the latest version of everything. On the other hand,\u2026","rel":"","context":"In &quot;Sin categor\u00eda&quot;","block_context":{"text":"Sin categor\u00eda","link":"https:\/\/geekosas.com\/index.php\/category\/sin-categoria\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/12\/onedrive-illo3.jpg?fit=1200%2C675&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/12\/onedrive-illo3.jpg?fit=1200%2C675&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/12\/onedrive-illo3.jpg?fit=1200%2C675&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/12\/onedrive-illo3.jpg?fit=1200%2C675&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2018\/12\/onedrive-illo3.jpg?fit=1200%2C675&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3252,"url":"https:\/\/geekosas.com\/index.php\/2015\/04\/23\/wireless-music-receiver\/","url_meta":{"origin":3232,"position":1},"title":"Wireless Music Receiver","author":"Daniel Fischer","date":"2015-04-23","format":false,"excerpt":"The purpose of this blog has always been to teach about my various geek inventions, gadgets I buy, tricks to get the most out of some technology, or simply to teach you about something few people know about, such as: how to choose a bicycle or how to read headphone\u2026","rel":"","context":"In &quot;Sin categor\u00eda&quot;","block_context":{"text":"Sin categor\u00eda","link":"https:\/\/geekosas.com\/index.php\/category\/sin-categoria\/"},"img":{"alt_text":"icon","src":"https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2015\/01\/descarga-300x298.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3266,"url":"https:\/\/geekosas.com\/index.php\/2016\/05\/23\/about-linux\/","url_meta":{"origin":3232,"position":2},"title":"About Linux","author":"Daniel Fischer","date":"2016-05-23","format":false,"excerpt":"If one morning you wake up with the inspiration to discover something new and you click the Random Article button on Wikipedia, with a probability of 1\/1,233,000 you will land on the article about Linux. If you want to wait for that event, you can keep trying; if not, you\u2026","rel":"","context":"In &quot;Sin categor\u00eda&quot;","block_context":{"text":"Sin categor\u00eda","link":"https:\/\/geekosas.com\/index.php\/category\/sin-categoria\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/04\/linux.png?fit=387%2C442&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3337,"url":"https:\/\/geekosas.com\/index.php\/2019\/05\/23\/r-and-super-powerful-pcs\/","url_meta":{"origin":3232,"position":3},"title":"R and super-powerful PCs","author":"Daniel Fischer","date":"2019-05-23","format":false,"excerpt":"R and Python are very popular lately, but have you asked yourself if you are getting the most out of these languages? In fact, you probably have a super\u2011powerful PC to work with them. Well, the truth is that if you are entering the world of Analytics, you might not\u2026","rel":"","context":"In &quot;Sin categor\u00eda&quot;","block_context":{"text":"Sin categor\u00eda","link":"https:\/\/geekosas.com\/index.php\/category\/sin-categoria\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2019\/02\/2922898-a.jpg?fit=350%2C350&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3257,"url":"https:\/\/geekosas.com\/index.php\/2016\/05\/23\/what-are-neural-networks\/","url_meta":{"origin":3232,"position":4},"title":"What are neural networks?","author":"Daniel Fischer","date":"2016-05-23","format":false,"excerpt":"Many have heard at some point about neural networks or \"artificial intelligence,\" and we have to be honest: when someone uses those words, it sounds like a total computing Einstein straight out of Terminator 2. Basically, neural networks are applied when the developer has absolutely no idea how to approach\u2026","rel":"","context":"In &quot;Sin categor\u00eda&quot;","block_context":{"text":"Sin categor\u00eda","link":"https:\/\/geekosas.com\/index.php\/category\/sin-categoria\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/03\/ai.jpg?fit=608%2C211&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/03\/ai.jpg?fit=608%2C211&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/geekosas.com\/wp-content\/uploads\/2016\/03\/ai.jpg?fit=608%2C211&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3304,"url":"https:\/\/geekosas.com\/index.php\/2017\/05\/23\/r-vs-ms-open-r-2\/","url_meta":{"origin":3232,"position":5},"title":"R vs MS open R","author":"Daniel Fischer","date":"2017-05-23","format":false,"excerpt":"Microsoft has realized the power of R, so it has integrated it into its systems, including Power BI and SQL Server 2017. Microsoft released a free version of R with some improvements, including native SQL Server connection, package versioning in MRAN (Microsoft Cran), and optimizations in the linear algebra package.\u2026","rel":"","context":"In &quot;Sin categor\u00eda&quot;","block_context":{"text":"Sin categor\u00eda","link":"https:\/\/geekosas.com\/index.php\/category\/sin-categoria\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2017\/10\/lm-1024x932.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2017\/10\/lm-1024x932.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2017\/10\/lm-1024x932.png?resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.geekosas.com\/wp-content\/uploads\/2017\/10\/lm-1024x932.png?resize=700%2C400 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/posts\/3232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/comments?post=3232"}],"version-history":[{"count":2,"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/posts\/3232\/revisions"}],"predecessor-version":[{"id":3234,"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/posts\/3232\/revisions\/3234"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/media\/3011"}],"wp:attachment":[{"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/media?parent=3232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/categories?post=3232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekosas.com\/index.php\/wp-json\/wp\/v2\/tags?post=3232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}