Skip to content

Commit cedaa61

Browse files
committed
content(blogpost): new rant about ====
1 parent 266b9d3 commit cedaa61

File tree

8 files changed

+185
-94
lines changed

8 files changed

+185
-94
lines changed
30.7 KB
Loading
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Behold, A New Operator `====`
2+
3+
## About
4+
5+
When `0.1 + 0.2` in JavaScript yields `0.30000000000000004`, it highlights a **common aspect of computer arithmetic**,
6+
not a bug. This occurs because JavaScript, like most languages, uses the **IEEE 754 standard** for floating-point numbers,
7+
which relies on **binary (base-2) representation**.
8+
9+
**Decimal fractions** like 0.1 and 0.2 **cannot be perfectly represented as finite binary fractions**; they become infinitely repeating.
10+
When these are stored in a **finite number of bits**, a **tiny truncation error** is introduced. This **slight imprecision**
11+
in each number **accumulates during addition**, resulting in a sum that's marginally off from the **exact mathematical total**.
12+
13+
### Solutions
14+
15+
For scenarios requiring **precise decimal arithmetic** (e.g., financial applications), direct floating-point calculations
16+
can be problematic. Consider these approaches:
17+
18+
1. **Rounding:** Use `toFixed()` to round results to a desired decimal precision. Remember to convert the string output
19+
back to a number if needed.
20+
```javascript
21+
parseFloat((0.1 + 0.2).toFixed(1)); // 0.3
22+
```
23+
2. **Integer Arithmetic:** **Scale numbers to integers** before calculations and then scale the final result back down.
24+
```javascript
25+
(0.1 * 10 + 0.2 * 10) / 10; // 0.3
26+
```
27+
3. **Specialized Libraries:** For **advanced precision**, utilize libraries like `Big.js` or `Decimal.js`.
28+
29+
This behavior is a **fundamental consequence of binary representation in computing**, not a flaw in JavaScript,
30+
and **understanding it is key** to handling numerical precision effectively.
31+
32+
## Introducing the `====` Operator: For When `===` Just Isn't Enough
33+
34+
Sometimes, **strict equality** (`===`) feels like it's trying *too hard* to be precise, yet still falls short of our
35+
deepest desires for perfect, unyielding truth. For those moments, when you need to compare not just value and type,
36+
but also the very **essence** of existence, I propose the **Quadruple Equals Operator (`====`)**!
37+
38+
What does `====` do? Well, it's simple:
39+
40+
* `0.1 + 0.2 ==== 0.3` would _(theoretically)_ return `true`. Because in a world where `====` exists, numbers just *know* what they're supposed to be.
41+
* `"hello" ==== "hello"` would, naturally, be `true`.
42+
* `[] ==== []` might still be `false`, because even `====` respects the **existential uniqueness** of array instances. But I am working on it. ¯\\\_(ツ)\_/¯
43+
* The `====` operator is so powerful, it can detect **deep existential equality**, ensuring that not only values and types match,
44+
but also their **historical context**, their **developer's intent**, and their **cosmic vibrational frequency**.
45+
46+
Alas, `====` is a mere dream, a **mythical beast** in the JavaScript ecosystem, born from the frustration of floating-point arithmetic.
47+
For now, we'll have to stick to our practical solutions. But one can dream of a world where `0.1 + 0.2 ==== 0.3` just *makes sense*.

public/posts/posts.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
[
2+
{
3+
"slug": "floating-point-precision-in-javascript",
4+
"title": "4 Equals For Complete Equalness",
5+
"date": "2025-11-21",
6+
"updated": "2025-11-21",
7+
"description": "Dive into the quirky world of JavaScript's floating-point math, where 0.1 + 0.2 isn't always 0.3. Discover why and then ponder the mythical `====` operator, designed for complete equalness beyond your wildest dreams!",
8+
"tags": ["javascript", "floating-point", "precision", "ieee-754", "programming"],
9+
"category": "rant",
10+
"filename": "floating-point-precision-in-javascript.txt",
11+
"authors": ["fezcode"],
12+
"image": "/images/defaults/mohammad-rahmani-8qEB0fTe9Vw-unsplash.jpg"
13+
},
214
{
315
"slug": "kaprekars-routine",
416
"title": "Kaprekar's Routine: A Curious Number Game",

public/rss.xml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,34 @@
99
<link>https://fezcode.com</link>
1010
</image>
1111
<generator>RSS for Node</generator>
12-
<lastBuildDate>Tue, 18 Nov 2025 00:23:58 GMT</lastBuildDate>
12+
<lastBuildDate>Fri, 21 Nov 2025 11:24:30 GMT</lastBuildDate>
1313
<atom:link href="https://fezcode.com/rss.xml" rel="self" type="application/rss+xml"/>
14-
<pubDate>Tue, 18 Nov 2025 00:23:58 GMT</pubDate>
14+
<pubDate>Fri, 21 Nov 2025 11:24:29 GMT</pubDate>
1515
<copyright><![CDATA[2025 Ahmed Samil Bulbul]]></copyright>
1616
<language><![CDATA[en]]></language>
1717
<managingEditor><![CDATA[samil.bulbul@gmail.com (Ahmed Samil Bulbul)]]></managingEditor>
1818
<webMaster><![CDATA[samil.bulbul@gmail.com (Ahmed Samil Bulbul)]]></webMaster>
1919
<ttl>60</ttl>
20+
<item>
21+
<title><![CDATA[Kaprekar's Routine: A Curious Number Game]]></title>
22+
<description><![CDATA[[object Object]]]></description>
23+
<link>https://fezcode.com/#/blog/kaprekars-routine</link>
24+
<guid isPermaLink="false">https://fezcode.com/#/blog/kaprekars-routine</guid>
25+
<dc:creator><![CDATA[Ahmed Samil Bulbul]]></dc:creator>
26+
<pubDate>Tue, 18 Nov 2025 00:00:00 GMT</pubDate>
27+
<content:encoded><![CDATA[<p>Have you ever played with numbers and found a surprising pattern? One such fascinating pattern is hidden within <strong>Kaprekar&#39;s Routine</strong>, named after the Indian mathematician D.R. Kaprekar. It&#39;s a simple game that, for most four-digit numbers, always leads to the same result: <strong>6174</strong>.</p>
28+
<p><a href="https://fezcode.com/#/blog/kaprekars-routine">Read more...</a></p>]]></content:encoded>
29+
</item>
30+
<item>
31+
<title><![CDATA[The Inevitable Dance of Entropy: A Rant on Chaos]]></title>
32+
<description><![CDATA[[object Object]]]></description>
33+
<link>https://fezcode.com/#/blog/chaos-theory-philosophical-rant</link>
34+
<guid isPermaLink="false">https://fezcode.com/#/blog/chaos-theory-philosophical-rant</guid>
35+
<dc:creator><![CDATA[Ahmed Samil Bulbul]]></dc:creator>
36+
<pubDate>Tue, 18 Nov 2025 00:00:00 GMT</pubDate>
37+
<content:encoded><![CDATA[<p>Oh, to be human! To crave <strong>order</strong>, to meticulously <strong>plan</strong>, to believe that if we just gather enough data, analyze enough variables, we can <strong>predict the future</strong>. What a <em>glorious, self-deceiving delusion</em>. Because lurking beneath our carefully constructed narratives of cause and effect, there&#39;s a mischievous, undeniable truth: <strong>Chaos Theory</strong>.</p>
38+
<p><a href="https://fezcode.com/#/blog/chaos-theory-philosophical-rant">Read more...</a></p>]]></content:encoded>
39+
</item>
2040
<item>
2141
<title><![CDATA[Minimum Number of Steps to Make Two Strings Anagram]]></title>
2242
<description><![CDATA[[object Object]]]></description>
@@ -94,7 +114,7 @@
94114
<guid isPermaLink="false">https://fezcode.com/#/blog/find-minimum-in-rotated-sorted-array</guid>
95115
<dc:creator><![CDATA[Ahmed Samil Bulbul]]></dc:creator>
96116
<pubDate>Sat, 08 Nov 2025 00:00:00 GMT</pubDate>
97-
<content:encoded><![CDATA[<h1>Find Minimum in Rotated Sorted Array</h1>
117+
<content:encoded><![CDATA[<h2>Problem Description</h2>
98118
<p><a href="https://fezcode.com/#/blog/find-minimum-in-rotated-sorted-array">Read more...</a></p>]]></content:encoded>
99119
</item>
100120
<item>

0 commit comments

Comments
 (0)