about summary refs log tree commit diff
path: root/library/core/src/num/flt2dec
AgeCommit message (Collapse)AuthorLines
2025-07-20flt2dec: use fill instead of loopMarijn Schouten-11/+7
2025-05-18float: Add `f16` parsing and printingTrevor Gross-0/+7
Use the existing Lemire (decimal -> float) and Dragon / Grisu algorithms (float -> decimal) to add support for `f16`. This allows updating the implementation for `Display` to the expected behavior for `Display` (currently it prints the a hex bitwise representation), matching other floats, and adds a `FromStr` implementation. In order to avoid crashes when compiling with Cranelift or on targets where f16 is not well supported, a fallback is used if `cfg(target_has_reliable_f16)` is not true.
2025-03-31Refactor `diy_float`Tobias Decking-4/+4
2025-01-11Add inherent versions of MaybeUninit methods for slicesltdk-34/+34
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-4/+4
2024-08-03Remove unnecessary constants from flt2dec dragonChristopher Swenson-23/+26
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 ```
2024-07-29Reformat `use` declarations.Nicholas Nethercote-4/+1
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2023-04-25Add shortcut for Grisu3 algorithm.mazong1123-0/+16
Check requested digit length and the fractional or integral parts of the number. Falls back earlier without trying the Grisu algorithm if the specific condition meets. Fix #110129
2022-10-11Fix inconsistent rounding of 0.5 when formatted to 0 decimal placesAndrew Tribick-1/+1
2022-09-25Remove unused variable.Camille GILLOT-4/+0
2021-07-17Changed dec2flt to use the Eisel-Lemire algorithm.Alex Huszagh-1/+1
Implementation is based off fast-float-rust, with a few notable changes. - Some unsafe methods have been removed. - Safe methods with inherently unsafe functionality have been removed. - All unsafe functionality is documented and provably safe. - Extensive documentation has been added for simpler maintenance. - Inline annotations on internal routines has been removed. - Fixed Python errors in src/etc/test-float-parse/runtests.py. - Updated test-float-parse to be a library, to avoid missing rand dependency. - Added regression tests for #31109 and #31407 in core tests. - Added regression tests for #31109 and #31407 in ui tests. - Use the existing slice primitive to simplify shared dec2flt methods - Remove Miri ignores from dec2flt, due to faster parsing times. - resolves #85198 - resolves #85214 - resolves #85234 - fixes #31407 - fixes #31109 - fixes #53015 - resolves #68396 - closes https://github.com/aldanor/fast-float-rust/issues/15
2021-07-04Auto merge of #86048 - nbdd0121:no_floating_point, r=Amanieubors-101/+1
core: add unstable no_fp_fmt_parse to disable float formatting code In some projects (e.g. kernel), floating point is forbidden. They can disable hardware floating point support and use `+soft-float` to avoid fp instructions from being generated, but as libcore contains the formatting code for `f32` and `f64`, some fp intrinsics are depended. One could define stubs for these intrinsics that just panic [1], but it means that if any formatting functions are accidentally used, mistake can only be caught during the runtime rather than during compile-time or link-time, and they consume a lot of space without LTO. This patch provides an unstable cfg `no_fp_fmt_parse` to disable these. A panicking stub is still provided for the `Debug` implementation (unfortunately) because there are some SIMD types that use `#[derive(Debug)]`. [1]: https://lkml.org/lkml/2021/4/14/1028
2021-06-23Use HTTPS links where possibleSmitty-1/+1
2021-06-06Move `flt2dec::{Formatted, Part}` to dedicated moduleGary Guo-101/+1
They are used by integer formatting as well and is not exclusive to float.
2021-03-22Preserve signed zero on roundtripJubilee Young-26/+6
This commit removes the previous mechanism of differentiating between "Debug" and "Display" formattings for the sign of -0 so as to comply with the IEEE 754 standard's requirements on external character sequences preserving various attributes of a floating point representation. In addition, numerous tests are fixed.
2020-09-05rename MaybeUninit slice methodsRalf Jung-43/+69
first_ptr -> slice_as_ptr first_ptr_mut -> slice_as_mut_ptr slice_get_ref -> slice_assume_init_ref slice_get_mut -> slice_assume_init_mut
2020-09-02flt2dec: properly handle uninitialized memoryRalf Jung-143/+221
2020-07-27mv std libs to library/mark-0/+1955