<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Maths - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Maths - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 27 Jul 2026 04:22:22 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/maths/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ What is a Floating-Point Arithmetic Problem? ]]>
                </title>
                <description>
                    <![CDATA[ Have you ever worked with numbers like 1/3, where the result is 0.33333… and continues forever? As humans, we naturally round off such numbers, but have you ever wondered how computers handle them? In this article, you’ll explore how computers manage... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-a-floating-point-arithmetic-problem/</link>
                <guid isPermaLink="false">671a576a1d53cf0b6813a51c</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Maths ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Mathematics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ float ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Syeda Maham Fahim ]]>
                </dc:creator>
                <pubDate>Thu, 24 Oct 2024 14:19:22 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1729588035734/9824633d-727a-49ce-9080-0fa3a7b18ed6.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Have you ever worked with numbers like 1/3, where the result is 0.33333… and continues forever? As humans, we naturally round off such numbers, but have you ever wondered how computers handle them?</p>
<p>In this article, you’ll explore how computers manage continuous values, including the concept of precision errors. We’ll examine the floating-point arithmetic problem, a universal issue that affects many programming languages. We’ll focus specifically on how JavaScript addresses this challenge.</p>
<p>Additionally, you’ll learn how binary operations work behind the scenes, the threshold at which JavaScript truncates numbers based on the IEEE 754 standard, and introduce <code>BigInt</code> as a solution for accurately handling larger numbers without precision loss.</p>
<p>First, let's consider an example. Can you guess the output of this operation?</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(<span class="hljs-number">0.1</span> + <span class="hljs-number">0.2</span>);
</code></pre>
<p>You may think the answer is 0.3, right? But no, the actual output is:</p>
<pre><code class="lang-javascript">Output: <span class="hljs-number">0.30000000000000004</span>
</code></pre>
<p>You must be wondering why this is happening. Why so many extra zeros, and why does it end with a 4?</p>
<p>The answer is simple: the numbers 0.1 and 0.2 cannot be precisely represented in JavaScript (that is, "exactly" or "accurately.")</p>
<p>It sounds simple, right? But the explanation is a bit more complex.</p>
<p>So, what do you think—bug or feature?</p>
<p>Well, it’s not a bug. It’s actually a fundamental issue with how computers handle numbers, specifically floating-point numbers.</p>
<h2 id="heading-why-does-this-happen">Why Does This Happen?</h2>
<p>Let’s understand this with basic math.</p>
<p>The fraction 1/3 is represented in decimal by 0.33333... and it never ends. This means that 3 repeats itself infinitely. We can’t write it down exactly, so we approximate it to something like 0.333 or 0.333333 to save time and space.</p>
<p>Similarly, in a computer, we also have to approximate because 1/3 or 0.3333... would be a very large number and take up infinite space (which we don’t have).</p>
<p>This leads to what we call the floating-point arithmetic problem.</p>
<h2 id="heading-floating-point-arithmetic-problem">Floating-Point Arithmetic Problem</h2>
<p>In simple terms, floating-point numbers are numbers that cannot be written down exactly, so we approximate them. In a computer, this kind of approximation can lead to small precision errors, which we call the floating-point arithmetic problem.</p>
<h2 id="heading-binary-explanation">Binary Explanation</h2>
<p>Now that we've covered the simple explanation, let’s also understand this in binary terms. JavaScript handles everything in binary behind the scenes.</p>
<p>Binary is a number system that only uses two digits: 0 and 1.</p>
<h3 id="heading-why-cant-01-and-02-be-represented-exactly-in-binary">Why Can’t 0.1 and 0.2 Be Represented Exactly in Binary?</h3>
<p>The core issue is that not all decimal numbers can be perfectly represented as binary fractions.</p>
<p>Let’s take 0.1 as an example:</p>
<p>When you try to represent 0.1 in binary, you’ll find out that it can’t be expressed as a finite binary fraction. Instead, it becomes a repeating fraction, much like how 1/3 in decimal becomes 0.333..., repeating forever.</p>
<p>In binary, 0.1 becomes:</p>
<pre><code class="lang-plaintext">0.0001100110011001100110011001100110011... (repeating infinitely)
</code></pre>
<p>Since computers have limited memory, they can’t store this infinite sequence exactly. Instead, they have to cut off the number at some point, which introduces a small rounding error. This is why 0.1 in binary is only an approximation of the actual value.</p>
<p>Like 0.1, 0.2 can’t be exactly represented in binary. It becomes:</p>
<pre><code class="lang-plaintext">0.00110011001100110011001100110011... (repeating infinitely)
</code></pre>
<p>Again, the computer truncates (cutting off part of a number to fit a limit or remove extra digits) this infinite binary sequence, leading to a small error in representation.</p>
<p>So, what happens when we add 0.1 + 0.2? When you add 0.1 + 0.2 in JavaScript, the binary approximations for 0.1 and 0.2 are added together. But since both values are only approximations, the result is also an approximation.</p>
<p>Instead of getting exactly 0.3, you get something close to this:</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(<span class="hljs-number">0.1</span> + <span class="hljs-number">0.2</span>); <span class="hljs-comment">// Output: 0.30000000000000004</span>
</code></pre>
<p>This slight error occurs because neither 0.1 nor 0.2 can be represented exactly in binary, so the final result has a small rounding error.</p>
<h2 id="heading-how-does-javascript-truncate-the-number">How Does JavaScript Truncate the Number?</h2>
<p>Now, the question arises: how does JavaScript know when to truncate the value?</p>
<p><strong>( Truncation</strong> means cutting off or shortening a number by removing extra digits beyond a certain point. <strong>)</strong></p>
<p>There’s a maximum and minimum limit for it.</p>
<p>To handle this in the computer world, we have a standard that defines how floating-point numbers are stored and calculated.</p>
<h2 id="heading-ieee-754-standard">IEEE 754 Standard</h2>
<p>JavaScript uses the IEEE 754 standard to handle floating-point arithmetic.</p>
<p>The standard defines safe integer limits for the <code>Number</code> type in JavaScript without precision loss:</p>
<ul>
<li><p><strong>Maximum Safe Integer:</strong> 2^53 - 1 or 9007199254740991</p>
</li>
<li><p><strong>Minimum Safe Integer:</strong> -(2^53 - 1) or -9007199254740991</p>
</li>
</ul>
<p>Beyond these limits, JavaScript cannot accurately represent integers due to the way floating-point arithmetic works.</p>
<p>For this reason, JavaScript provides two constants to represent these limits:</p>
<ul>
<li><p><code>Number.MAX_SAFE_INTEGER</code></p>
</li>
<li><p><code>Number.MIN_SAFE_INTEGER</code></p>
</li>
</ul>
<h3 id="heading-what-if-i-need-a-bigger-number">What If I Need a Bigger Number?</h3>
<p>If you need to work with numbers larger than the Maximum Safe Integer (like those used in cryptography or finance), JavaScript has a solution: BigInt.</p>
<h3 id="heading-enter-bigint">Enter BigInt</h3>
<p><code>BigInt</code> is a built-in object that allows you to work with whole numbers beyond the safe integer limit. It enables you to represent numbers larger than 9007199254740991, so you don't need to worry about precision errors here!</p>
<p>To use <code>BigInt</code>, simply append an <code>n</code> to the end of an integer literal:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> bigNumber = <span class="hljs-number">1234567890123456789012345678901234567890n</span>;
</code></pre>
<p>Alternatively, you can use the <code>BigInt</code> constructor:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> bigNumber = BigInt(<span class="hljs-string">"1234567890123456789012345678901234567890"</span>);
</code></pre>
<h4 id="heading-operations-with-bigint">Operations with BigInt</h4>
<p>You can perform arithmetic operations with <code>BigInt</code>, like addition, subtraction, multiplication, and even exponentiation. However, there’s a catch: you can’t mix <code>BigInt</code> with regular <code>Number</code> types in arithmetic operations without explicitly converting between them.</p>
<p>For example, this won’t work:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> result = bigNumber + <span class="hljs-number">5</span>; <span class="hljs-comment">// Error: cannot mix BigInt and other types</span>
</code></pre>
<p>You would need to convert the <code>Number</code> to <code>BigInt</code> first:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> result = bigNumber + BigInt(<span class="hljs-number">5</span>); <span class="hljs-comment">// Now it works!</span>
</code></pre>
<h3 id="heading-where-do-we-use-bigint">Where Do We Use BigInt?</h3>
<p><code>BigInt</code> is particularly useful in areas requiring precision, such as:</p>
<ul>
<li><p>Cryptographic algorithms</p>
</li>
<li><p>Handling large datasets</p>
</li>
<li><p>Financial calculations requiring exactness</p>
</li>
</ul>
<h3 id="heading-in-summary">In Summary</h3>
<ul>
<li><p>The safe integer limit in JavaScript ensures accurate number representation for integers between -(2^53 - 1) and 2^53 - 1.</p>
</li>
<li><p>Precision errors occur due to floating-point arithmetic when handling certain numbers (like 0.1 + 0.2).</p>
</li>
<li><p>If you need numbers bigger than the safe limit, <code>BigInt</code> is your friend. But remember, mixing <code>BigInt</code> and <code>Number</code> types require explicit conversions.</p>
</li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Best Gitter channels: Mathematics ]]>
                </title>
                <description>
                    <![CDATA[ By Gitter Many programmers claim that they don’t use much mathematics in their daily work — or some of them even admit they struggled with it in high school. But knowing math will surely broaden your horizons as an engineer, and will make building so... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/best-gitter-channels-mathematics-2cceab3a94b4/</link>
                <guid isPermaLink="false">66c3459b42d4db64acf4cbeb</guid>
                
                    <category>
                        <![CDATA[ Advanced Mathematics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Mathematics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Maths ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 07 Sep 2016 10:19:44 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*Mt_I3oPXSF4f7rD8GroPQw.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Gitter</p>
<p>Many programmers claim that they don’t use much mathematics in their daily work — or some of them even admit they struggled with it in high school.</p>
<p>But knowing math will surely broaden your horizons as an engineer, and will make building software more satisfying.</p>
<p>If you’re looking to revive or build your math skills, these Gitter communities are a good place to start. Check out the list below and don’t hesitate to join the conversation.</p>
<ul>
<li><a target="_blank" href="https://gitter.im/sagemath/cloud"><strong>sagemath/cloud</strong></a> <strong>— SageMathCloud</strong> is a web-based <a target="_blank" href="https://en.wikipedia.org/wiki/Cloud_computing">cloud computing</a> and <a target="_blank" href="https://en.wikipedia.org/wiki/Learning_management_system">course management</a> platform for computational mathematics. The goal of the SageMath Cloud project is to create a viable way to do computational mathematics collaboratively online.</li>
<li><a target="_blank" href="https://gitter.im/mikera/vectorz-clj?"><strong>mikera/vectorz-clj</strong></a> <strong>—</strong> Fast matrix and vector maths library for Clojure — as a core.matrix implementation.</li>
<li><a target="_blank" href="https://gitter.im/ChrisRackauckas/DifferentialEquations.jl"><strong>ChrisRackauckas/DifferentialEquations.jl</strong></a> <strong>—</strong> Julia suite for high-performance solvers of differential equations.</li>
<li><a target="_blank" href="https://gitter.im/rsvp/randomsys"><strong>rsvp/randomsys</strong></a> <strong>—</strong> Algorithmic study of random systems. Reliable and unbiased random numbers are needed for a range of applications from numerical modeling to cryptographic communications. ANU researchers are generating true random numbers from a physical quantum source by splitting a beam of light into two beams and then measuring the power in each beam. Because light is quantised, the light intensity in each beam fluctuates about the mean. Those fluctuations, due ultimately to the quantum vacuum, can be converted into a source of random numbers.</li>
<li><a target="_blank" href="https://gitter.im/funcool/cats"><strong>funcool/cats</strong></a> <strong>—</strong> Category Theory and Algebraic abstractions for Clojure and ClojureScript. <a target="_blank" href="http://funcool.github.io/cats/latest/">http://funcool.github.io/cats/latest/</a></li>
<li><a target="_blank" href="https://gitter.im/non/algebra"><strong>non/algebra</strong></a> — Experimental project to lay out basic algebra type classes.</li>
<li><a target="_blank" href="https://gitter.im/JuliaODE/ODE.jl"><strong>JuliaODE/ODE.jl</strong></a> <strong>—</strong> Various basic Ordinary Differential Equation solvers implemented in Julia.</li>
<li><a target="_blank" href="https://gitter.im/Axelrod-Python/Axelrod"><strong>Axelrod-Python/Axelrod</strong></a> <strong>—</strong> A <a target="_blank" href="http://axelrod.readthedocs.org/">research tool</a> to run Iterated Prisoner’s Dilemma tournaments.</li>
<li><a target="_blank" href="https://gitter.im/sympy/sympy"><strong>sympy/sympy</strong></a> — A computer algebra system written in pure Python. <a target="_blank" href="http://sympy.org/">http://sympy.org/</a></li>
<li><a target="_blank" href="https://gitter.im/boostorg/geometry"><strong>boostorg/geometry</strong></a> — <a target="_blank" href="http://boost.org/libs/geometry">Boost.Geometry</a>, part of collection of the <a target="_blank" href="http://github.com/boostorg">Boost C++ Libraries</a>, defines concepts, primitives and algorithms for solving geometry problems.</li>
<li><a target="_blank" href="https://gitter.im/samyak-268/Linear-Algebra"><strong>samyak-268/Linear-Algebra</strong></a> <strong>—</strong> This library hosts C++ implementation of some of the routines which are most frequently encountered in Linear Algebra.</li>
<li><a target="_blank" href="https://gitter.im/mattheath/base62"><strong>mattheath/base62</strong></a> <strong>—</strong> Base62 encoding for arbitrary precision integers.</li>
</ul>
<p>Did we miss something? Do you want us to feature your channel? Drop us a line in the <a target="_blank" href="https://gitter.im/gitterHQ/gitter">Gitter HQ</a> and we will add it to the list.</p>
<p>You can also easily <a target="_blank" href="https://gitter.im/home#createroom">start your own channel here.</a></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
