[Haskell-cafe] rounding errors with real numbers.
haskell at list.mightyreason.com
Sun Feb 26 08:00:54 EST 2006
Your solution works, but is slightly wasteful with (repair) traversing
the whole list again. Here is a slightly more efficient expression:
-- Precondition: The first parameter (xs) is sorted (ascending) :
-- assert (all (zipWith (<=) (xs, tail xs)))
-- low' < high'
-- low < high
normInterval :: [Double] -> Double -> Double -> [Double]
normInterval xs low high = let low' = head xs; high' = last xs;
scale = (high-low)/(high'-low')
middle = init (tail xs)
in (low : [scale*(x-low')+low) | x <-middle])++[high]
More information about the Haskell-Cafe