Git Product home page Git Product logo

Comments (13)

ulfjack avatar ulfjack commented on June 28, 2024 2

I'm aware of the article. I think we can do better.

from ryu.

ulfjack avatar ulfjack commented on June 28, 2024 1

I have pushed some code to the https://github.com/ulfjack/ryu/tree/parsing branch. There are still big holes in the code, but that's the general shape. Note that it can only handle up to ~18 decimal digits (which is fine for input that was formatted as shortest), and I need to double-check that the tables have enough bits for this usage.

from ryu.

ulfjack avatar ulfjack commented on June 28, 2024 1

I pushed a couple of fixes to the branch. Before it can be merged, I need to figure out error handling, make it work on Mac/Win, and double-check that the bit widths are ok. More tests would also be good, but IMO not a blocker for merging into master.

from ryu.

vinniefalco avatar vinniefalco commented on June 28, 2024 1

The JSON implementation seems to work (i.e. passes tests) but it only implements the "fast path" conversion. Which means it can be off by one bit for some strings. And note that it is not officially part of Boost yet, and is still being worked on.

from ryu.

ulfjack avatar ulfjack commented on June 28, 2024

If you know your input is the "shortest" format of a floating-point value of a given width, then there is in fact a fast algorithm to parse these values. I have some code for that. I'll need to do a bit of work in order to commit it here, but it shouldn't be much (famous last words).

from ryu.

plokhotnyuk avatar plokhotnyuk commented on June 28, 2024

@ulfjack There is an amazing library for Rust that parses float/double values precisely and fast

I've ported the moderate path from it to our library for Scala

from ryu.

ulfjack avatar ulfjack commented on June 28, 2024

I pushed another commit filling in some of the missing pieces.

from ryu.

plokhotnyuk avatar plokhotnyuk commented on June 28, 2024

@ulfjack please consider using of SWAR techniques for parsing the decimal representation, like here: sirthias/borer#114

from ryu.

ulfjack avatar ulfjack commented on June 28, 2024

@vinniefalco posted on the PR: "How about 0.X1E1000 where X is a thousand zeroes"

Looks like you found a bug!

from ryu.

vinniefalco avatar vinniefalco commented on June 28, 2024

We were able to fix our number parser:

https://github.com/vinniefalco/json/blob/5aae31dc74d055d84a7f13e438d80cdf6005c670/include/boost/json/detail/impl/number.ipp#L155

However, it fails to produce the same result as stod for some cases. It is off by just one bit in those cases, which I guess is what all of this complicated looking code in s2d.c is for, which is to identify the cases where it needs to round up or down by one bit to find the nearest double? And this is all because converting from a base 10 exponent to a base 2 exponent is lossy?

from ryu.

plokhotnyuk avatar plokhotnyuk commented on June 28, 2024

@vinniefalco
ICYMI: https://www.exploringbinary.com/17-digits-gets-you-there-once-youve-found-your-way/

from ryu.

vinniefalco avatar vinniefalco commented on June 28, 2024

Well.... it would have been nice to read that before I struggled to write the code !!!

from ryu.

nickaleks avatar nickaleks commented on June 28, 2024

@vinniefalco @ulfjack I am currently looking at fast string-to-double conversion, and reading this discussion it's not clear whether current ryu implementation is correct, or whether json implementation is good to use. Can one of those solutions be used yet?

from ryu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.