[Haskell-cafe] rounding errors with real numbers.
Henning Thielemann
lemming at henning-thielemann.de
Mon Feb 27 09:11:35 EST 2006
On Sun, 26 Feb 2006, Matthias Fischmann wrote:
> I think this is the well-known issue of using real numbers in decimal
> representation on a machine that thinks binary, but I don't know what
> to do with it, and some of you maybe do.
>
> I want to shift+stretch a list of doubles into a given interval.
> example:
>
> | x1 = [2, 3, 4, 5, 10]
> | y1 = normInterval x1 0 1
> | => y1 = [0.0,0.125,0.25,0.375,1.0]
>
> The function that does this looks something like this:
>
> | normInterval :: [Double] -> Double -> Double -> [Double]
> | normInterval ps lower upper = map (\ x -> (x - oldLower) * stretch + lower) ps
Is there --------------------------------------------------------------^
a cancellation problem?
Maybe you should use a kind of convex combination, that is
(x-oldLower)*a + (oldUpper-x)*b
More information about the Haskell-Cafe
mailing list