📜 ⬆️ ⬇️

Division by zero or a clear example of why internal interrupts in the kernel are needed

A vivid example of what for the core of every modern device, ranging from a calculator to super powerful servers and PCs, is an interruption in case of absurd commands.



Dividing by zero is an absurd process that you cannot and should not perform. A simple but still not perfect answer explains that if you divide something by zero, the process approaches infinity.
')
What do you get when you try to divide, for example, the number 20 by 0 using a modern PC or phone? For those who do not know - below are screenshots with an example.





To the question why we get such a result, there is a simple answer. In any operating system, there is an instruction to protect against such problems. Also in the core of the device there are internal interrupts, just in case of such commands. But I think many will be interested to know what will happen if you remove such interruptions?

Having tried to divide by 0 on a mechanical calculator, you will see a terrible agony in trying to solve an absurd mathematical problem. As shown in the video, where a "certified" mathematician tries to divide by zero on a mechanical calculator called Facit ESA-01.



Sure - funny, but this is also a small illustration of how mechanical computers work. The machines use a series of gears and gears of different sizes that rotate together while the differential relationship between the mechanisms helps track the actual math. This 1953 video demonstrates in great detail the main principle of a mechanical calculator.



When the mechanical calculator works, it uses a similar mechanical process. Dividing by any number is a sequential subtraction. As an example, let's divide twenty by four:

  1. 20 - 4 = 16
  2. 16 - 4 = 12
  3. 12 - 4 = 8
  4. 8 - 4 = 4
  5. 4 - 4 = 0


Five steps to get to zero, so the answer is five. It's simple!

Of course, if you use the same process when dividing by zero, it becomes cyclical, because the sequence for 20 when dividing by zero:

  1. 20 - 0 = 20
  2. 20 - 0 = 20
  3. 20 - 0 = 20
  4. 20 - 0 = 20
  5. 20 - 0 = 20


And so on, until the very end of time.

Without a detailed examination of the "entrails" of Facit ESA-01, it is difficult to say what is going on inside it in this situation. But you can be sure that the main reason for the endless processing is the attempt of the machine to execute an infinite sequence of commands one by one. And so in a circle.

A computer without a programmed interrupt will always do what you order, even if this process takes forever.

Source: https://habr.com/ru/post/392435/


All Articles