Skip to content

Instantly share code, notes, and snippets.

@jfager
Created Apr 10, 2011
Embed
What would you like to do?
Full precision summation based on http://code.activestate.com/recipes/393090/
-- Full precision summation based on http://code.activestate.com/recipes/393090/
msum :: [Double] -> Double
msum [] = 0
msum (x:xs) = sum $ foldl' (\ps x' -> reverse (partials x' ps)) [x] xs
partials :: Double -> [Double] -> [Double]
partials x = foldl' (\acc p -> case hilo x p of (hi, 0) -> hi:acc
(hi, lo) -> hi:lo:acc) []
hilo :: Double -> Double -> (Double, Double)
hilo x y | abs x < abs y = hilo y x
| otherwise = (hi, lo) where hi = x + y
lo = y - (hi - x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment