Floating Point: The Decimal Coup


Today is March 14.

The civilians call this Pi Day and post circles. We will do something more useful.

We will discuss why computers lie about decimals in a disciplined, standardized, internationally recognized way.

This is not a bug. This is floating-point arithmetic.

I. The Basic Betrayal

Most programmers first meet floating point like this:

console.log(0.1 + 0.2);
// 0.30000000000000004

Then they go through the five stages of numerical grief.

The issue is not that the machine is stupid. The issue is that decimal fractions such as 0.1 do not, in general, have exact finite representations in binary floating-point formats.

You asked for arithmetic. You received approximation with a standard attached.

II. The Standardized Form of the Lie

In 1985, IEEE 754 formalized binary floating-point arithmetic. This was one of the most important truces in computing because it made floating-point behavior more portable and more predictable across hardware and software.

That does not mean it made floating point intuitive.

It made it consistent enough to litigate.

At a high level, a binary floating-point value consists of:

  • sign
  • exponent
  • significand (mantissa, informally)

For the common double / binary64 layout:

FieldBitsRole
Sign1Positive or negative
Exponent11Scale factor with bias
Fraction52Precision payload for significand

This gives you enormous dynamic range. It does not give you exact decimal accounting.

III. Why 0.1 Is Not 0.1

In decimal, 0.1 is simple. In binary, it is a repeating fraction.

The machine stores the nearest representable value in the chosen format. Arithmetic then proceeds on these approximations, with rounding rules applied at each step.

That means:

  • input is approximated
  • operations are rounded
  • output may expose the residue

This is not moral failure. It is finite precision.

IV. What the Standard Actually Bought Us

IEEE 754 did not only define formats. It standardized behaviors that matter in real programs:

  • rounding modes
  • infinities
  • NaNs
  • signed zero
  • exceptional conditions
FeatureWhy it matters
Rounding to nearest, ties to evenDefault behavior that reduces aggregate bias
+inf / -infDefined overflow semantics
NaNPropagates invalid computations without pretending they are valid numbers
Signed zeroMatters in functions, limits, and branch-sensitive numerical behavior

People mock signed zero until a numerical method or branch table depends on it.

Then they become quiet.

V. The Practical Danger

Floating point is fine for:

  • graphics
  • physics approximations
  • scientific work designed around error bounds
  • large parts of systems and application programming

Floating point is dangerous when people use it casually for:

  • money
  • equality comparisons
  • loop termination conditions
  • serialization expectations that assume decimal exactness

This is why “just use a float” is not engineering guidance. It is a confession.

VI. A Better Mental Model

Use tolerance-aware comparisons when the domain permits it:

function nearlyEqual(a, b, epsilon = 1e-12) {
	return Math.abs(a - b) <= epsilon;
}

console.log(nearlyEqual(0.1 + 0.2, 0.3));
// true

But even this is not universal doctrine.

Choosing epsilon badly is just another way to be wrong more politely.

For financial values, fixed-point or decimal representations are usually the adult answer.

VII. The Historical Violence

Floating point has accumulated famous embarrassments because people keep assuming numbers are simpler than they are.

IncidentWhat failedWhy engineers remember it
Pentium FDIV bugIncorrect division lookup entries in hardwareFloating-point mistakes can become reputational and financial disasters
0.1 + 0.2 class of surprisesRepresentation misunderstandingThe beginner’s first lesson in machine arithmetic realism
Financial rounding bugsDomain mismatchApproximation in the wrong problem space becomes liability

The Supreme Leader considers the Pentium FDIV bug an instructive reminder that even the empire of arithmetic can ship errata.

VIII. The Real Story (Suppressed)

Officially, floating point is a numerical representation format.

Unofficially, it is a pact between mathematics and hardware in which both sides agree to stop demanding purity so the machine can finish before the heat death of the universe.

Pi Day encourages citizens to celebrate one irrational number. Floating-point engineering requires living with thousands of tiny rational compromises.

This is why the serious people are less impressed by 3.14159 than by correctly bounded error propagation.

The Decree

Today is March 14, and the appropriate response is not to worship pi in decorative typography.

The appropriate response is to remember:

  • computers represent many decimals approximately
  • standards matter because approximation without rules becomes chaos
  • equality on floats is a loaded weapon
  • domain choice matters more than clever patches

Floating point is not broken. It is a machine compromise with clearly documented terms.

Programmers get hurt when they do not read the treaty.

— Kim Jong Rails, Supreme Leader of the Republic of Derails