News for hackers. Stuff that matters.
Re:Zmij: Faster floating point double-to-string conversion by vitaut on Thursday December 18, 2025 @09:23AM (#46313022)
Thank you! The simplicity is mostly thanks to Schubfach although I did simplify it a bit more. Unfortunately the paper makes it appear somewhat complex because of all the talk about generic bases and Java workarounds.
Re:Zmij: Faster floating point double-to-string conversion by adgjlsfhk1 on Thursday December 18, 2025 @10:12AM (#46313537)
I've just started a Julia port and I think it will be even cleaner than the C version (mostly because Julia gives you a first class (U)Int128 and count leading zeros (and also better compile time programming that lets you skip on writing the first table out explicitly).
Re:Zmij: Faster floating point double-to-string conversion by vitaut on Thursday December 18, 2025 @11:40AM (#46314997)
Cool, please share once it is complete.

C++ also provides countl_zero: https://en.cppreference.com/w/cpp/numeric/countl_zero.html. We currently use our own for maximum portability.

I considered computing the table at compile time (you can do it in C++ using constexpr) but decided against it not to add compile-time overhead, however small. The table never changes so I'd rather not make users pay for recomputing it every time.

Re:Zmij: Faster floating point double-to-string conversion by nhatcher on Thursday December 18, 2025 @10:37AM (#46313975)
Oh wow, I would love to see that if you can share it :)
Re:Zmij: Faster floating point double-to-string conversion by adgjlsfhk1 on Thursday December 18, 2025 @10:42AM (#46314057)
Once I finish it, I'll be PRing to the Julia repo (to replace the current Ryu version), and I'll drop a link here.
Re:Zmij: Faster floating point double-to-string conversion by vitaut on Friday December 19, 2025 @10:08AM (#46326666)
I started a section to list implementations in other languages: https://github.com/vitaut/zmij?tab=readme-ov-file#other-lang.... Once yours is complete feel free to submit a PR to add it there.
Re:Zmij: Faster floating point double-to-string conversion by adgjlsfhk1 on Friday December 19, 2025 @11:52PM (#46333706)
Not adding it until complete, but https://github.com/JuliaLang/julia/pull/60439 is the draft.
Re:Zmij: Faster floating point double-to-string conversion by nhatcher on Friday December 19, 2025 @06:37AM (#46324684)
Quick question, if you are still around :).

I have been doing some tests. Is it correct to assume that it converts 1.0 to "0.000000000000001e+15".

Is there a test suite it is passing?

Re:Zmij: Faster floating point double-to-string conversion by vitaut on Friday December 19, 2025 @09:34AM (#46326286)
It converts 1.0 to "1.e-01" which reminds me to remove the trailing decimal point =). dtoa-benchmark tests that the algorithm produces valid results on its dataset.
Re:Zmij: Faster floating point double-to-string conversion by nhatcher on Friday December 19, 2025 @10:54AM (#46327184)
So if I use:

    #include "zmij.h"
    #include <stdio.h>

    int main() {
        char buf[zmij::buffer_size];
        zmij::dtoa(1.0, buf);
        puts(buf);
    }
I get `g++ zmij.cc test.c -o test && ./test` => `0.000000000000001e+15`
Re:Zmij: Faster floating point double-to-string conversion by vitaut on Friday December 19, 2025 @07:16PM (#46332528)
My bad, you are right. The small integer optimization should be switched to a different output method (or disabled since it doesn't provide much value). Thanks for catching this!
Re:Zmij: Faster floating point double-to-string conversion by vitaut on Friday December 19, 2025 @07:23PM (#46332572)
Should be fixed now.
Re:Zmij: Faster floating point double-to-string conversion by dtolnay on Friday December 19, 2025 @12:54PM (#46328766)
"1.e-01" is for 0.1, not 1.0.
Re:Zmij: Faster floating point double-to-string conversion by nhatcher on Friday December 19, 2025 @01:41PM (#46329316)
I assume they meant 1.e+00

That is what Schubfach does

Re:Zmij: Faster floating point double-to-string conversion by vitaut on Friday December 19, 2025 @07:25PM (#46332583)
Yeah, that's what I meant.