Pour obtenir une clé
d'essai remplissez le formulaire ci-dessous
Demandez des tariffs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
USD
EUR
RUB
* En cliquant sur ce bouton, vous acceptez notre politique de confidentialité

Free PVS-Studio license for Microsoft MVP specialists
To get the licence for your open-source project, please fill out this form
** En cliquant sur ce bouton, vous acceptez notre politique de confidentialité.

I am interested to try it on the platforms:
** En cliquant sur ce bouton, vous acceptez notre politique de confidentialité.

Votre message a été envoyé.

Nous vous répondrons à


Si vous n'avez toujours pas reçu de réponse, vérifiez votre dossier
Spam/Junk et cliquez sur le bouton "Not Spam".
De cette façon, vous ne manquerez la réponse de notre équipe.

>
>
>
Division by Zero

Division by Zero

15 Jul 2013

Definition

Division by zero is a logic software bug that in most cases causes a run-time error when a number is divided by zero.

Program Behavior

Whether or not this run-time error occurs depends on a number of factors: the language of the program and its development platform and the types of dividends.

According to section 5.6 of the C++ language standard, if operators "/" and "%" have 0 as the second operand, undefined behavior occurs.

When trying to divide a number by an integer zero on a processor of the x86 and x86_64 processor families, a hardware exception is generated (by vector 0); accordingly, a C/C++ program compiled into machine code will crash when executing this operation.

At the same time, if the zero-variable is a real one, then, according to the IEEE 754 standard, the result is a real number "plus infinity" or "minus infinity" (the standard also specifies that zero is a signed number) in case of a non-zero numerator, and a "NaN" (not a number) in case of the 0/0 indetermination (the Microsoft Visual C++ compiler returns the "indeterminate" number specific to the x86 platform).

Note that the variable does not necessarily have to contain zero: it may occur as a result of rounding of values, which is called an arithmetic underflow, when the result of a rounding operation is a number whose value is under machine precision. The result in this case is assumed as equal to 0.

Tracking Zero Divide Errors

Divide-by-zero bugs can be tracked by some compilers (for instance, Microsoft Visual C++) and static analyzers.

One should be especially attentive when dividing a number by a variable which serves as a loop iterator, for one may easily forget that it should at some point go through the zero value. Static analyzers use a special diagnostic to check that (the V609 diagnostic in the PVS-Studio).

References

Comments (0)

Next comments
Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter