@@ -125,8 +125,18 @@ countDigits v0 = go 1 (fromIntegral v0 :: Word64)
125125 | v < 10 = k
126126 | v < 100 = k + 1
127127 | v < 1000 = k + 2
128− | v < 10000 = k + 3
129− | otherwise = go (k+4) (v `quot` 10000)
128+ | v < 1000000000000 =
129+ k + if v < 100000000
130+ then if v < 1000000
131+ then if v < 10000
132+ then 3
133+ else 4 + fin v 100000
134+ else 6 + fin v 10000000
135+ else if v < 10000000000
136+ then 8 + fin v 1000000000
137+ else 10 + fin v 100000000000
138+ | otherwise = go (k + 12) (v `quot` 1000000000000)
139+ fin v n = if v >= n then 1 else 0
130140
131141hexadecimal :: Integral a => a -> Builder
132142{-# SPECIALIZE hexadecimal :: Int -> Builder #-}