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

Remove unnecessary constants from flt2dec dragon #128609

Merged
merged 1 commit into from
Aug 5, 2024

Commits on Aug 3, 2024

  1. Remove unnecessary constants from flt2dec dragon

    The "dragon" `flt2dec` algorithm uses multi-precision multiplication by
    (sometimes large) powers of 10. It has precomputed some values to help
    with these calculations.
    
    BUT:
    
    * There is no need to store powers of 10 and 2 * powers of 10: it is
      trivial to compute the second from the first.
    * We can save a chunk of memory by storing powers of 5 instead of powers
      of 10 for the large powers (and just shifting by 2 as appropriate).
    * This also slightly speeds up the routines (by ~1-3%) since the
      intermediate products are smaller and the shift is cheap.
    
    In this PR, we remove the unnecessary constants and do the necessary
    adjustments.
    
    Relevant benchmarks before (on my Threadripper 3970X, x86_64-unknown-linux-gnu):
    
    ```
    num::flt2dec::bench_big_shortest                      137.92/iter   +/- 2.24
    num::flt2dec::strategy::dragon::bench_big_exact_12   2135.28/iter  +/- 38.90
    num::flt2dec::strategy::dragon::bench_big_exact_3     904.95/iter  +/- 10.58
    num::flt2dec::strategy::dragon::bench_big_exact_inf 47230.33/iter +/- 320.84
    num::flt2dec::strategy::dragon::bench_big_shortest   3915.05/iter  +/- 51.37
    ```
    
    and after:
    
    ```
    num::flt2dec::bench_big_shortest                      137.40/iter   +/- 2.03
    num::flt2dec::strategy::dragon::bench_big_exact_12   2101.10/iter  +/- 25.63
    num::flt2dec::strategy::dragon::bench_big_exact_3     873.86/iter   +/- 4.20
    num::flt2dec::strategy::dragon::bench_big_exact_inf 47468.19/iter +/- 374.45
    num::flt2dec::strategy::dragon::bench_big_shortest   3877.01/iter  +/- 45.74
    ```
    swenson committed Aug 3, 2024
    Configuration menu
    Copy the full SHA
    36a8059 View commit details
    Browse the repository at this point in the history