Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data.ByteString.Char8.readDouble? #598

Open
meooow25 opened this issue Jun 24, 2023 · 4 comments
Open

Data.ByteString.Char8.readDouble? #598

meooow25 opened this issue Jun 24, 2023 · 4 comments

Comments

@meooow25
Copy link
Contributor

We have readInt and readInteger but no readDouble. Of course, the implementation will be more complex compared to readInt, but I would like to see it unless there is some good reason to not have it.

@Bodigrim
Copy link
Contributor

This is currently covered by Data.ByteString.Lex.Fractional, but I don't see fundamental reasons why not have it in bytestring proper.

@meooow25
Copy link
Contributor Author

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).

@Bodigrim
Copy link
Contributor

Makes sense to me. @clyring what do you think?

@clyring
Copy link
Member

clyring commented Jul 5, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants