-
-
Notifications
You must be signed in to change notification settings - Fork 413
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
Use correct exponential representation for rational values #493
Conversation
Codecov Report
@@ Coverage Diff @@
## master #493 +/- ##
==========================================
+ Coverage 68.19% 69.81% +1.62%
==========================================
Files 172 172
Lines 10573 10757 +184
==========================================
+ Hits 7210 7510 +300
+ Misses 3363 3247 -116
Continue to review full report at Codecov.
|
Hmmm. I'm fine with having this for the time being, what we had before was not spec compliant at all. And in the future we can improve it. I think we should add more tests for this to see how spec compliant it is. What do you think? @Razican @jasonwilliams |
This Ryu thing looks really interesting, though. It looks like the original author of Grisu3 (which seems to be used for fast conversion in V8) even said Ryu is faster than Grisu3: I'd really be interested in implementing this algorithm. EDIT: There is already a crate: https://crates.io/crates/ryu-ecmascript EDIT2: |
Excelent research from @Tropid. I think this is important. The stringification of numbers must be compliant with https://tc39.es/ecma262/#sec-numeric-types-number-tostring. This will likely also solve #449. How much work do you think you need @Tropid ? |
1916e2a
to
064c736
Compare
@croraf sorry, I forgot to reply after we talked about it in the Discord chat. I just updated the pull request. It now uses the ryu algorithm to print the numbers. I forked the dtolnay/ryu project/crate and adjusted it for ECMAScript formatting. This draft PR adds a dependency to my fork. I'd suggest for Boa to fork this project itself and cherry-pick my changes or something like that, so that the repository is accessible by Boa and can be updated regularly. @HalidOdat What are your opinions on that? |
Good job! @Tropid. I agree, we may also want to publish this to crates.io, since What do you think @Razican @jasonwilliams |
Let's do this :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me :)
The error is giving is due to a missing |
This Pull Request addresses #413
It changes the following:
This is a pretty simple way to deal with the problem at hand. It just uses Rusts exponential formatting for values that require the scientific notation. It has a few problems, though:
.replace("e", "+e")
)I looked at various documents regarding converting doubles to decimal representation. There is V8s implementation (as linked in the Issue) which seems to use different algorithms based on the number (see
DoubleToAscii()
here: https://chromium.googlesource.com/v8/v8/+/refs/heads/master/src/numbers/dtoa.cc). The other algorithm is calledBignumDtoa
in V8.Rust itself uses a combination of the Grisu and the Dragon families of algorithms (see https://github.com/rust-lang/rust/blob/master/src/libcore/num/flt2dec/mod.rs#L49).
Also there seems to be a new algorithm which may yield better results:
I see three options to continue this issue:
This is a rather simple/easy to understand solution. It has a rather advanced implementation (Rust std/core library). It needs not much maintenance as it uses the std library. It's probably good enough for the first time/most use cases.
Also we can later replace it with more advanced algorithms.
Implement
BignumDtoa
from V8. This seems to be the general purpose function to format any double (V8 tries faster methods before falling back to this one).(Re-)Implement the full amount of different algorithms
This seems rather complicated (at least to me) and difficult to maintain/tweak the performance to reach at least the same as the std implementation.
I'd be glad to hear some more input on this topic.