Re: Divide by zero
Posted in 1996
In article <558kgp$mac@cssun.mathcs.emory.edu>, William Knott <knottw@cork.cig.mot.com> wrote: >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 instead. 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.