How an Error in Cult Classic Game Doom Sparked New Appreciation for Pi

https://www.profitableratecpm.com/f4ffsdxe?key=39b1ebce72f3758345b2155c98e6709c

Everyone makes mistakes, and sometimes those mistakes can lead to surprising discoveries. In the early 1990s, while programming the computer game Doom, game developer John Carmack set the value of pi (π) by hand and, in true nerd fashion, wrote the number down to the ninth decimal place from memory: 3.141592657.

Do you notice anything strange about this number? The last number is wrong. The number should instead be 3.141592654. (Pi is often truncated without rounding, in which case the ninth decimal place would be filled with 3, but it is rounded to 4 because the next digit is 5.)

Fortunately, this error has little impact on the game. In Doom, one of the first first-person shooter games with three-dimensional graphics, you play as a space marine who, due to a failed teleportation experiment, ends up on a moon of Mars, where he fights demons and zombies. The game has a great story but terrible graphics. This is not due to an incorrect pi value, but rather the lack of computing power available in the 1990s.


On supporting science journalism

If you enjoy this article, please consider supporting our award-winning journalism by subscription. By purchasing a subscription, you are helping to ensure the future of impactful stories about the discoveries and ideas shaping our world today.


Still, the error inspired American engineer Luke Gotszling to study the possible consequences of incorrectly programming Pi on a larger scale in the game – an idea he presented at a hacker conference in 2022.

When Pi makes a mistake in a video game

Since Doom is an open source computer game, you can download the code and modify it. That’s exactly what Gotszling did, testing what would happen if he changed the programmed values ​​of pi.

The results can make the viewer a little nauseous. When Gotszling set π = 3, for example, the pixelated world of Doom became distorted, with walls and pillars moving in unexpected ways. Nonetheless, the game was playable.

When pi was set to the value of Euler’s number, 2.718…, the strangeness intensified. When a player moved directly in the game world, surrounding objects moved to different sides. Enemies might appear out of nowhere and disappear again. “With enough intoxication, you can recreate this,” Gotszling joked in his presentation.

Things got really bad when he set a value of π2 for pi. The walls were shattering and disappearing. Invisible obstacles block the player’s movements. The game wasn’t particularly fun in this state.

Pi is not always 3.14159…

Why is pi so powerful? To answer this question, we need to think more deeply about the consequences of changing pi.

Originally, pi was defined as the ratio of the circumference of a circle to its diameter. In our everyday world, we assume circles are round. But in the narrower mathematical sense, a circle is defined by all points equidistant from a common center. In a flat, two-dimensional world, where distances are defined as the shortest straight lines, a circle is round. This means that the value of pi can change.

For example, imagine you are in downtown Manhattan. If you want to know which places are exactly one kilometer away from you, the shape you can create will no longer be round. That’s because you can’t walk through walls. Instead, you must follow the checkerboard layout of the streets. A circle has a square shape in the “Manhattan metric”, as it is called in mathematical jargon. And if you define pi in this context as the ratio of circumference to diameter, the number takes on completely different values: in the Manhattan metric, pi is exactly 4.

The graph compares the circumference and diameter of a circle to an approximation of a circle composed of lines zigzagging along a square grid. The labels show how pi is calculated in each case by dividing the circumference by the diameter.

If you look closely, the value of pi in our world is not exactly 3.14159…. Instead, the circumference-to-diameter ratio takes on a different value and, even worse, that value varies!

If you stand at the North Pole and look at all the places exactly 1,000 kilometers away from you, for example, those points form a circle on the surface of a sphere, but its circumference is smaller than that of a circle on a flat surface, thanks to the curvature of the Earth. The closer we get to the equator, the stronger this effect becomes and the corresponding value of pi deviates more and more from the usual 3.14159….

A transparent sphere has a black dot on top and a red circle tracing a line of latitude. A blue curved line connects the point to a point at the edge of the circle. An accompanying figure shows an identical red circle with a black dot in the middle and a straightened version of the blue line, which starts at the black dot and ends outside the circle.

The new value of pi is therefore not constant but depends on the radius of the circle. And this is not only the case when considering a spherical surface. Any type of curved surface gives varying values ​​for pi.

Mathematicians call these curved worlds “non-Euclidean” geometries. (More than 2,000 years ago, the scholar Euclid laid out the rules of geometry that most of us learned in school – ideas that only apply on a flat world.)

Create a trippy vision of destiny

The original landscape Gotszling created while tweaking Doom’s source code is something else entirely. To understand this, we have to go back to the 1990s: a time when each arithmetic operation consumed enormous amounts of resources. To meet this challenge, programmers worked to determine possible calculations in advance and store them in “lookup tables.”

When developing 3D graphics for a computer game, trigonometric functions such as sine, cosine and tangent play an important role. They can be used to describe how objects move in space over time. To save processing power, Doom developers calculated important values ​​of trigonometric functions for different angles in advance and stored them in lookup tables. And that’s where pi comes in: multiply an angle in degrees by pi to get the corresponding value in radians, which the computer uses.

Thus, if Gotszling used a value of pi that was too small, the angles would be incorrectly converted. Because developers only store a finite number of angles, he created lookup tables with values ​​that no longer include full rotations: instead of describing an environment in which an object only reappears in the same location after a 360-degree rotation, it happens after a significantly smaller angle. So, in extreme situations, objects suddenly disappear or reappear out of nowhere.

The Doom world Gotszling created is incredibly strange. Still, it’s a good way to get people thinking about math and the value, in every sense of the word, of pi. A small mistake by a game developer sparked a much larger experiment into the strange circle number.

This article was originally published in Spektrum der Wissenschaft and has been reproduced with permission.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button