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

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
32 replies · 8K views
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:
Physics news on Phys.org
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.
 
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.
 
Reply
  • Informative
Likes   Reactions: hmmm27