RE: Suggestion for 2.5

new topic     » topic index » view thread      » older message » newer message

Hello there,

rforno at tutopia.com wrote:
> Rob:
> When crunching numbers, sometimes one gets a "division by zero" error. 
> In
> such cases, perhaps the useful thing to do is assign "infinite" to the
> result (I mean the IEEE standard infinite), so that if you use he result 
> as
> a divisor, the new result will be zero. The following are the results 
> for
> zero division I propose:
> 1 / 0 = inf
> -1 / 0 = -inf
> 0 / 0 = 1
> inf / 0 = inf
> -inf / 0 = -inf
> inf / inf = 1
> -inf / inf = -1
> inf / -inf = -1
> -inf / -inf = 1
> 1 / inf = 0
> -1 / inf = 0
> 1 / -inf = 0
> -1 / -inf = 0
> 
> and the logical results for addition, subtraction and multiplication.
> Please correct me if I'm wrong: I think you are checking for a zero 
> divisor
> *before* you perform the actual division, and so this proposal wont add 
> any
> overhead in the case of a divisor being zero. I don't know how are you
> handling the case of infinite IEEE numbers. In any case, I'd avoid 
> getting a
> nan (not a number) result.
> In order to be alerted of an error as soon as possible, like Eu does 
> now, it
> would be useful to enable or not this variation by means of a *with* or
> *without* option, lets say: without zero_division.
> Regards.
> 
> 
Usually your math package has to check for these forms because
sometimes you cant truely determine the value from a division
like this.  A good example is in the math library i had posted
a while back, in the file "MathLib.e", function "Angle()"
which i'll repeat here for convenience:

global function Angle(sequence X)
  --full range trig function!
  atom x,y,Ang

  CalculationEnumeration=CalculationEnumeration+1
  x=X[1] y=X[2]

    if x=0 then
      if y=0 then
        SetMathLibErrorMessage("Indeterminate Angle() domain {0,0}")
        Ang=0
      else
        if y<0 then
          Ang=-PPi/2
        else
          Ang=PPi/2
        end if
      end if
    else
      Ang=arctan(y/x)
      if x<0 then
        if y<0 then
          Ang=Ang-PPi
        else
          Ang=Ang+PPi
        end if
      end if
    end if
    return Ang
end function


Good luck with it,
Al

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu