Open meooow25 opened 1 year ago
This is currently covered by Data.ByteString.Lex.Fractional
, but I don't see fundamental reasons why not have it in bytestring
proper.
Checking it out, Data.ByteString.Lex.Fractional
provides no way to parse "NaN"
and "Infinity"
, which are supported by read
. It also appears to sacrifice precision (for speed?) but makes no mention of it in the docs.
ghci> :m + Data.Maybe Data.ByteString.Lex.Fractional Data.ByteString.Char8
ghci> readbslex :: String -> Double; readbslex = fst . fromJust . readExponential . pack
ghci> readbslex "12.3e-2" == readbslex "123e-3"
False
ghci> readDbl :: String -> Double; readDbl = read
ghci> readDbl "12.3e-2" == readDbl "123e-3"
True
If we have this function in bytestring
I feel it would be best to match read
's behavior (and not just use bytestring-lexing
's implementation).
Makes sense to me. @clyring what do you think?
Sorry for the slow response. I would be happy to add these functions with correct rounding behavior. I'm not too fussed about matching read
's behavior in other respects.
We have
readInt
andreadInteger
but noreadDouble
. Of course, the implementation will be more complex compared toreadInt
, but I would like to see it unless there is some good reason to not have it.