ekmett / intervals

Interval Arithmetic
http://hackage.haskell.org/package/intervals
BSD 2-Clause "Simplified" License
27 stars 13 forks source link

I believe we have `(/)` wrong for `divPositive` and `divNegative` #19

Open ekmett opened 10 years ago

ekmett commented 10 years ago

This came up when writing Numeric.Rounded.Interval in rounded.

The right definition probably looks like:

x / y@(I a b)
   | 0 `notElem` y = divNonZero x y
   | iz && sz  = ...
   | iz        = divPositive x b
   |       sz  = divNegative x a
   | otherwise = divZero x
dmcclean commented 10 years ago

Instead of this, with swapped b's and a's?

    | iz       = divPositive x a
    |       sz = divNegative x b

Could be. I have a bad sinus problem that is making it hard to think. :)

Accordingly, this may be wrong, but couldn't

| iz && sz  = whole -- instead of Exception.throw DivideByZero
ekmett commented 10 years ago

I tripped over that while starting to adapt the interval logic to work in rounded.

Having the result of dividing by zero be everything is rather non-standard. We may want to adopt the practices of something like the boost interval arithmetic library where division by zero is concerned.