nim-lang / needed-libraries

This repository contains a list a needed libraries.
112 stars 5 forks source link

Fast and accurate float to string conversion (ryu) #104

Closed disruptek closed 3 years ago

disruptek commented 5 years ago

I've long been enamored with this one.

https://github.com/ulfjack/ryu

simonkrauter commented 5 years ago

A talk explaining Ryū: https://www.youtube.com/watch?v=kw-U6smcLzk

awr1 commented 5 years ago

Wouldn't it be more ideal if the standard lib used ryu itself or is the possibility that that would break something too great?

disruptek commented 5 years ago

Don't you think a first implementation should be confined to a library so everyone can A/B it against stdlib and discover bugs, pain points, or regressions? Even an impure version would be a useful starting point.

awr1 commented 5 years ago

I mean, you're right, I was just wondering if the ultimate goal here was to upgrade the standard lib

disruptek commented 5 years ago

I mean, you're right; the goal would be fast and accurate float conversion by default. :smile:

disruptek commented 5 years ago

I looked into this a bit and nim appears to simply sprintf under the covers. Visual C++ is getting (already has?) a Ryu implementation of std::to_chars as per https://twitter.com/StephanTLavavej/status/1031841243326754817 but AFAIK there is no such love for Clang or GCC. The right thing to do is probably to start with a wrapper and then let this eventually get implemented in the backends. The wrapper could be smart enough to use the compiler's implementation when known to exist, so that there is no penalty for code using the deprecated wrapper... Thoughts?

Araq commented 5 years ago

Thumbs up from me, a stdlib patch will be accepted.

disruptek commented 5 years ago

IIRC, the creator mentioned that the algo for Ryu is only like 100 lines, though I looked at the source and it seemed quite a bit more extensive. If no one else wants it, I'll try to contribute; t'd be a fun first project. I'd guess that we'd want to land somewhere between the state-of-the-art C implementation and a 100 line paper implementation in terms of complexity. :wink:

timotheecour commented 3 years ago

we now have dragonbox (refs https://github.com/nim-lang/Nim/pull/18139), we should close this ( I don't have permissions to close)