- res = fixedResolution fa
- (i,d) = divMod a res
- -- enough digits to be unambiguous
- digits = ceiling (logBase 10 (fromInteger res) :: Double)
- maxnum = 10 ^ digits
- fracNum = div (d * maxnum) res
+ res = resolution fa
+ (i,d) = divMod a res
+ -- enough digits to be unambiguous
+ digits = ceiling (logBase 10 (fromInteger res) :: Double)
+ maxnum = 10 ^ digits
+ fracNum = div (d * maxnum) res
+
+readsFixed :: (HasResolution a) => ReadS (Fixed a)
+readsFixed = readsSigned
+ where readsSigned ('-' : xs) = [ (negate x, rest)
+ | (x, rest) <- readsUnsigned xs ]
+ readsSigned xs = readsUnsigned xs
+ readsUnsigned xs = case span isDigit xs of
+ ([], _) -> []
+ (is, xs') ->
+ let i = fromInteger (read is)
+ in case xs' of
+ '.' : xs'' ->
+ case span isDigit xs'' of
+ ([], _) -> []
+ (js, xs''') ->
+ let j = fromInteger (read js)
+ l = genericLength js :: Integer
+ in [(i + (j / (10 ^ l)), xs''')]
+ _ -> [(i, xs')]