@@ -1,3 +1,5 @@
2-- Module: Data.Text.Internal.Builder.RealFloat.Functions
4-- Module: Data.Text.Internal.Builder.RealFloat.Functions
3-- Copyright: (c) The University of Glasgow 1994-2002
5-- Copyright: (c) The University of Glasgow 1994-2002
@@ -13,6 +15,30 @@ module Data.Text.Internal.Builder.RealFloat.Functions
15roundTo :: Int -> [Int] -> (Int,[Int])
17roundTo :: Int -> [Int] -> (Int,[Int])
19+#if MIN_VERSION_base(4,6,0)
25+ _ -> error "roundTo: bad Value"
29+ f n _ [] = (0, replicate n 0)
30+ f 0 e (x:xs) | x == b2 && e && all (== 0) xs = (0, []) -- Round to even when at exactly half the base
31+ | otherwise = (if x >= b2 then 1 else 0, [])
33+ | i' == base = (1,0:ds)
34+ | otherwise = (0,i':ds)
36+ (c,ds) = f (n-1) (even i) xs
16roundTo d is =
42roundTo d is =
17 case f d is of
43 case f d is of
18 x@(0,_) -> x
44 x@(0,_) -> x
@@ -27,3 +53,5 @@ roundTo d is =
28 (c,ds) = f (n-1) xs
54 (c,ds) = f (n-1) xs
29 i' = c + i
55 i' = c + i