[Haskell-cafe] rounding errors with real numbers.
Matthias Fischmann
fis at wiwi.hu-berlin.de
Thu Mar 2 12:42:54 EST 2006
> cancellation happens for instance here: 1 + 1e-50 - 1 == 0
the function again (in the wasteful original form, for clarity).
where do you think cancellation may take place? isn't what you call
canellation a generic rounding error?
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
normInterval :: [Double] -> Double -> Double -> [Double]
normInterval ps lower upper = repair (map (\ x -> (x - oldLower) * stretch + lower) ps)
where
oldLower = head ps
oldUpper = last ps
stretch = (upper - lower) / (oldUpper - oldLower)
-- fix rounding error:
repair [i] = [upper]
repair (h:t) = h : repair t
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >>(x-oldLower)*a + (oldUpper-x)*b
i got this into my head though. neat. thanks! i will rewrite the
function right now.
cheers,
matthias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20060302/4550cd23/attachment.bin
More information about the Haskell-Cafe
mailing list