Comments (13)
I'm aware of the article. I think we can do better.
from ryu.
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.
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.
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.
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.
@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.
I pushed another commit filling in some of the missing pieces.
from ryu.
@ulfjack please consider using of SWAR techniques for parsing the decimal representation, like here: sirthias/borer#114
from ryu.
@vinniefalco posted on the PR: "How about 0.X1E1000 where X is a thousand zeroes"
Looks like you found a bug!
from ryu.
We were able to fix our number parser:
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.
@vinniefalco
ICYMI: https://www.exploringbinary.com/17-digits-gets-you-there-once-youve-found-your-way/
from ryu.
Well.... it would have been nice to read that before I struggled to write the code !!!
from ryu.
@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)
- Instructions for porting to C# HOT 3
- A DecimalFloatingPoint struct in the public side of the API HOT 1
- Buffer overflow possible with d2fixed() and friends
- Julia implementation HOT 1
- Not getting the shortest decimal representation of 0.3 HOT 9
- Outdated Documentation HOT 1
- Questions on Ryu algorithm
- Remove the "static inline" declarator HOT 3
- Add a prefix to exported names HOT 6
- C implementation that accommodates 10-byte and 16-byte floating point data types HOT 7
- question: is there a standard for 'shortest'? HOT 1
- question about ryu support in gcc? ( pure-'C' ) HOT 1
- Honest output request HOT 2
- optimized ryu version for 'long doubles'? ( real 80-bit figures, not 'fake-long' ) - enhancement proposal -
- Wondering if anyone has a generic_decimal_to_binary implementation? HOT 2
- generic_128's long_double_to_fd128 is silently incorrect on most platforms. long double users beware
- travis ci never completes its checks HOT 3
- Clarification on lower bound of `compute_shortest`. HOT 4
- Ryu: Question about Step 0 in section 3.4 of the PLDI paper
- Specify STATIC in add_library
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ryu.