about summary refs log tree commit diff
path: root/library/core/src/fmt/float.rs
AgeCommit message (Collapse)AuthorLines
2025-05-18float: Add `f16` parsing and printingTrevor Gross-0/+36
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-12Reduce FormattingOptions to 64 bits.Mara Bos-3/+3
2025-03-10Limit formatting width and precision to 16 bits.Mara Bos-6/+6
2024-12-05Access members of `FormattingOptions` directly instead of via getters/settersElias Holzmann-3/+3
2024-12-05Formatter: Access members via getter methods wherever possibleElias Holzmann-3/+3
The idea behind this is to make implementing `fmt::FormattingOptions` (as well as any future changes to `std::Formatter`) easier. In theory, this might have a negative performance impact because of the additional function calls. However, I strongly believe that those will be inlined anyway, thereby producing assembly code that has comparable performance.
2024-11-12remove no-longer-needed abs_privateRalf Jung-1/+1
2024-10-15Refactor `floating` macro and nofloat panic messagezlfn-23/+24
2024-07-29Reformat `use` declarations.Nicholas Nethercote-2/+1
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-24Replace `MaybeUninit::uninit_array()` with array repeat expression.Kevin Reid-8/+10
This is possible now that inline const blocks are stable; the idea was even mentioned as an alternative when `uninit_array()` was added: <https://github.com/rust-lang/rust/pull/65580#issuecomment-544200681> > if it’s stabilized soon enough maybe it’s not worth having a > standard library method that will be replaceable with > `let buffer = [MaybeUninit::<T>::uninit(); $N];` Const array repetition and inline const blocks are now stable (in the next release), so that circumstance has come to pass, and we no longer have reason to want `uninit_array()` other than convenience. Therefore, let’s evaluate the inconvenience by not using `uninit_array()` in the standard library, before potentially deleting it entirely.
2024-04-11Add a `Debug` impl and some basic functions to `f16` and `f128`Trevor Gross-0/+16
`compiler_builtins` uses some convenience functions like `is_nan` and `is_sign_positive`. Add these, as well as a temporary implementation for `Debug` that prints the bit representation.
2023-05-15Mark internal functions and traits unsafeLegionMammal978-4/+8
2021-10-20Rollup merge of #86479 - exphp-forks:float-debug-exponential, r=yaahcYuki Okushi-4/+49
Automatic exponential formatting in Debug Context: See [this comment from the libs team](https://github.com/rust-lang/rfcs/pull/2729#issuecomment-853454204) --- Makes `"{:?}"` switch to exponential for floats based on magnitude. The libs team suggested exploring this idea in the discussion thread for RFC rust-lang/rfcs#2729. (**note:** this is **not** an implementation of the RFC; it is an implementation of one of the alternatives) Thresholds chosen were 1e-4 and 1e16. Justification described [here](https://github.com/rust-lang/rfcs/pull/2729#issuecomment-864482954). **This will require a crater run.** --- As mentioned in the commit message of 8731d4dfb47, this behavior will not apply when a precision is supplied, because I wanted to preserve the following existing and useful behavior of `{:.PREC?}` (which recursively applies `{:.PREC}` to floats in a struct): ```rust assert_eq!( format!("{:.2?}", [100.0, 0.000004]), "[100.00, 0.00]", ) ``` I looked around and am not sure where there are any tests that actually use this in the test suite, though? All things considered, I'm surprised that this change did not seem to break even a single existing test in `x.py test --stage 2`. (even when I tried a smaller threshold of 1e6)
2021-06-19Automatic exponential formatting in DebugMichael Lamparski-4/+49
* {:.PREC?} already had legitimately useful behavior (recursive formatting of structs using fixed precision for floats) and I suspect that changes to the output there would be unwelcome. (besides, precision introduces sinister edge cases where a number can be rounded up to one of the thresholds) Thus, the new behavior of Debug is, "dynamically switch to exponential, but only if there's no precision." * This could not be implemented in terms of float_to_decimal_common without repeating the branch on precision, so 'float_to_general_debug' is a new function. The name is '_debug' instead of '_common' because the considerations in the previous bullet make this logic pretty specific to Debug. * 'float_to_decimal_common' is now only used by Display, so I inlined the min_precision argument and renamed the function accordingly.
2021-06-06Move `flt2dec::{Formatted, Part}` to dedicated moduleGary Guo-4/+5
They are used by integer formatting as well and is not exclusive to float.
2021-03-22Preserve signed zero on roundtripJubilee Young-13/+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-02flt2dec: properly handle uninitialized memoryRalf Jung-68/+48
2020-08-30update fixmesDPC-8/+8
2020-08-29rename get_{ref, mut} to assume_init_{ref,mut} in MaybeuninitDPC-8/+8
2020-07-27mv std libs to library/mark-0/+207