Why does a division by zero produce an error or undefined message?

Click For Summary
Division by zero is mathematically undefined because no number multiplied by zero can yield a non-zero result. In computing, attempting to divide by zero typically results in an error or exception, rather than a program crash, as modern operating systems and programming languages handle this scenario with specific error messages. Some calculators may display positive or negative infinity instead, depending on their implementation. The IEEE 754 standard allows for the representation of infinity and NaN (not a number) in floating-point arithmetic, which can lead to different behaviors across systems. Ultimately, division by zero remains a fundamental issue in both mathematics and computer programming, necessitating careful handling to avoid errors.
  • #31
If the divisor is small enough compared to the dividend that the quotient has gotten too big for its register, an "Overflow" (or maybe "Size Error" which covers a few more bases) return-code gets tossed back to the program, instead of the usual "yup, worked fine".

If you've gotten a literal "Divide by Zero" error, that's probably extra code in the software, inserted by a "helpful" compiler/interpreter. The hardware doesn't actually care, and will continue onwards unless you've coded in something to do if an error occurs.
 
Last edited:
Technology news on Phys.org
  • #32
Lots of machine operations produce return-codes that get sent back to the program running on them whether something unusal happened or not. It's up to the programmer to choose to use them.

In the case of a Size-Error for a divide, it doesn't have to be a zero, just any number small enough (compared to the dividend) that the quotient overflows its register.

If you get a literal "Divide By Zero", that's probably some code introduced by the "helpful" compiler/interpreter, as a pre-check.

Doesn't hurt the machine ; it will just keep chugging along either way.
 
  • #33
I just looked it up. IEEE 754, which is the standard most chips use for floating point returns +INF for a/+0 and -a/-0 (where a is a positive number) and -INF for a/-0 and -a/+0. It also have two zeros, +0 amd -0. Dividing either zero by either zero gives NaN.

How the program treats this is, of course, up to the programmer.
 

Similar threads

  • · Replies 47 ·
2
Replies
47
Views
6K
  • · Replies 28 ·
Replies
28
Views
5K
  • · Replies 8 ·
Replies
8
Views
4K
Replies
29
Views
5K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 8 ·
Replies
8
Views
13K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K