## Divide by zero

### Divide by zero

Hello there,
First off, I'm a bit of a newbie, so sorry about this as I'm sure it
has been mentioned on the mailing list before.

I've run into the divide by zero problem when calculating equations in the
database.

The equations are akin to (a + b) / (c + d)
or
[ a + (b /c) ] / (d + e)
where c and d can be minus numbers.

While a procedure along the lines of
DIVIDE (a+b , c+d)
if c+d = 0, set c+d = NULL

is possible, the equations, with multiple divional factors, are likely to cause
a simple procedure akin to this to go really slowly.

Any ideas?

William Knott

--

- -----------------------------------------------------------------------
Every time I visit New York, I'm always hit by the same thing : a yellow cab.

### Divide by zero

>Hello there,
>    First off, I'm a bit of a newbie, so sorry about this as I'm sure it
>has been mentioned on the mailing list before.

>I've run into the divide by zero problem when calculating equations in the
>database.

>The equations are akin to (a + b) / (c + d)
>or
>[ a + (b /c) ] / (d + e)
>where c and d can be minus numbers.

Well, you could always do something like:-

select [...] , (a + b) / (c + d)
from [...]
where [...]
and (c + d) != 0

or perhaps:-

select [...] , (a + b) / (c + d)
from [...]
where [...]
and (c + d) != 0
union
select [...] , 0
from [...]
where [...]
and (c + d) = 0

- this gives a 0 in the "(c + d) = 0" case, whereas perhaps you want a NULL

One time I found myself doing something like this (not for the squeamish!):

select [...] , (a + b) / (c + d + 0.00000001 )
from [...]
where [...]

which gives you a very large number when (c + d) = 0. I forget why this
seemed to be a good idea at the time.

Paul

*************************************************************************
Disclaimer: All opinions expressed in this message are well-reasoned and
insightful; needless to say, they are not those of Informix Software, its
partners or lackeys.  Anyone who says otherwise is itching for a fight.

### Divide by zero

Paul & Company,

I recently called in a bug (or at least an unexpected quirk) in 4GL
(6.01).

I was getting unexpected nulls as a result of calculation.  Very
strange, having shown than none of the numbers involved were NULL.  I
discovered that if you divide by 0 integers, (I think DECIMAL as well)
you get a null result instead of the kick-out you ought to get.

I haven't tried this with an SQL statement.

-- Jake

....
> >I've run into the divide by zero problem when calculating equations in the
> >database.

> >The equations are akin to (a + b) / (c + d)
> >or
> >[ a + (b /c) ] / (d + e)
> >where c and d can be minus numbers.

> Well, you could always do something like:-

... Omitted

### Divide by zero

Quote:>Paul & Company,

>I recently called in a bug (or at least an unexpected quirk) in 4GL
>(6.01).

>I was getting unexpected nulls as a result of calculation.  Very
>strange, having shown than none of the numbers involved were NULL.  I
>discovered that if you divide by 0 integers, (I think DECIMAL as well)
>you get a null result instead of the kick-out you ought to get.

>I haven't tried this with an SQL statement.

>       -- Jake

You need to use either WHENEVER ANYERROR STOP or compile with
c4gl -anyerr ... Check your release notes in
\$INFORMIXDIR/release/4GL*
--
David Williams

I am trying to upsize a large Access application to SQL server 6.5 using the
upsizing wizard and it always comes up with a Divide By Zero error - and
converts nothing - any ideas!!

Julian

4. OLE DB