Skip to content
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

Honest output request #211

Closed
user45643 opened this issue May 4, 2022 · 2 comments
Closed

Honest output request #211

user45643 opened this issue May 4, 2022 · 2 comments

Comments

@user45643
Copy link

Amazing work. Lots more people would love to use it, it just needs a tiny polish. If I may say my piece..

The readme.md states "...The stored value is exactly 0.300000011920928955078125. However, this floating point number is also the closest number to the decimal number 0.3, so that is what Ryu outputs."

But it doesn't actually do that. Does it?
That "0.3" output that you quoted is what most potential users want. But your code doesn't do that. "3E-1"

Consider: The people at the following link want to use your code: but they don't because it doesn't actually do what your readme said: "https://discuss.python.org/t/faster-float-string-conversion-ryu/2466/4". They are unable to use your code as a drop in replacement for dtoa, because your code does not output the non-scientific format prefered for reasonable exponents.

Consider: It looks like your issue #199 user is also disapointed and either uses a seperate c++ specific tool to try and fudge the output (defeating the purpose of ryu being faster than dtoa), or they went away disapointed: "#199" "Not getting the shortest decimal representation of 0.3". I am a C user, so I cannot do that fudge.

Methinks you are starting to get quite a lot of issues raised that indirectly stem from your code outputting scientific notation for exponents close to 0.

Solution? It would be nice, if possible, if your could add a f2s_nonscientific() function. I would really love a function that can be passed a threshold for the range of exponents to print traditionally before switching to scientific notation. Or a function that gives the same output as dtoa, but faster, to popularise your superior work. That's why we are here.

The other option would be to remove the sadly false claim from the readme.md

@newbie-02
Copy link

hello @user45643,

  1. mostly solved.
  2. I nearly overlooked your question reg. the 'not very clear' subject,
  3. I had similar problems like you to find a way from theory and benchmarks to practical use,
    ( I want to use it for gnumeric as the 'go_dtoa' used there ( in the goffice library, adopted from Rich Felkers 'musl' ), has some shortcomings )
  4. spotting that 'make' in the ryu/ryu subdir sets me free from hassles with bazel, after some time I checked that it's two distinct parts,
    a.) calculating the needed value,
    b.) producing appropriate output,
  5. It's not too difficult a task to adapt the output. tried how far I can and think / hope success.
    I provide attached a tar archive ryu.tar.gz
    with:
    A. a patched 'generic128.c',
    B. a patched 'd2s.c',
    C. a little test program 'convert_long_double_to_string.c',
    D. a little test program 'convert_double_to_string.c',
    E. a build and use hint 'dm_build.txt',
    which manage to produce 'gnumeric style' output, '0' for '0', 'decimal' for [ 1E-4 .. 1E17 ) ( .. 1E21 for long ) e.g. the requested '0.3', and 'scientific' with min. two exp. digits for the rest of values,
    just set free in the ryu/ryu subdir, fire make and the test compilations acc. dm_build.txt,
    I tried to provide enough comments that changes for other format wishes are easy.
    feel free to check, use, spread but look to stick to Ulf Adams licensing.
    as my coding skills are limited I'd really really really appreciate any tests, review, feedback, comments, improvements!!!,
    IMHO Ulf has done a outstanding great job, and it deserves being spreaded.
    Test status here:
    I checked gnumerics 'shortest' output produced with go_dtoa and '"!" GNM_FORMAT_G' against the patched ryu in a sheet with 1 meg random values multiple times, the values match in every case, the strings are still different for some few values with questionable precision, e.g gnumeric says 79630192461941888 is a good and accurate decimal representation for a bin value, while ryu says 79630192461941890 is accurate enough as we get back the FP-value from less decimal digits, and I say pretending 17 digit accuracy in a range with at max 16 digits precision ( the ganularity of doubles is 16 here! ) is fake and thus 79630192461941890 is better, even that doesn't have a '10' accuracy but is needed for roundtripping, and I think 7.963019246194189E+16 would be best.

known shortcomings:

  • above point which might be discussed,
  • f2s not yet covered / touched as I don't need it, shouldn't be difficult, most in d2s was solved with a copy from generic128,
  • urgently!!! seeking a performance optimized solution for 80-bit long doubles, generic is significantly slow, see issue #212.

@ulfjack
Copy link
Owner

ulfjack commented Feb 19, 2024

Thanks! The code here isn't necessarily fit for direct consumption, and may need additional work to get the output you want. Note that libstdc++ uses the algorithm from here to generate the output you want (I think) from the to_chars method. If you can use that, that might be preferable.

@ulfjack ulfjack closed this as completed Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants