PDA

View Full Version : Division by 0 problem.



Serge Van Sint Jan
01-28-1995, 03:07 AM
Dear Biomch-L Readers,

Everybody knows the problem of a division with a divisor
equal to ZERO.

When programming, three solutions can be used to avoid an inturruption of
your program with display of inflamed error messages from the system:

1: Test the divisor before each division and if it is equal
to zero skip the division or even abort the current
subroutine.

2: Test the divisor before each division and if it is equal
to zero, add a very small number to the divisor.

3: Systematically add a very small number to ANY divisor.
(In the examples of Matlab, 2.204e-16 is added systematically).

Solution 1 is surely the most honnest. But it is difficult to explain to a user,
who does not care about math, that his data can not be processed
because somewhere "a division by zero" appears.

So, Solution 2 can be used. But the addition of the small number only takes
place for some data and not for the others (because of the "if").

To avoid to disturb the "harmony of the balance" in the data set, Solution
3 may be applied. But is it really scientific to alter numbers with the
only reason that one of them will produce a 0 divide exception?



So, after this (maybe too!) long introduction, my questions are:

1- What is your personal opinion and experience on the subject?
How do you solve the problem when programming and why?

2- Are they any well-defined rules?
Or maybe nobody cares and uses the best solution according to
his own application?


Thank you for any answers! I shall post a summary of the answers later.


___
|. .|
Serge Van Sint Jan (sabbatical) | " |
Department for Mechanical Engineering \=/
The University of New Mexico \|/ | \|/
Albuquerque, USA \ | /
voice: int + 1 505 277 2339 -^-----^-
fax: 1571 |
email: serge@slider.unm.edu |
( )
/ \
/ \
| |
| |
-- --