]> git.lizzy.rs Git - rust.git/commit - src/tools/rust-analyzer
Rollup merge of #86479 - exphp-forks:float-debug-exponential, r=yaahc
authorYuki Okushi <jtitor@2k36.org>
Tue, 19 Oct 2021 19:35:10 +0000 (04:35 +0900)
committerGitHub <noreply@github.com>
Tue, 19 Oct 2021 19:35:10 +0000 (04:35 +0900)
commitca6798ab073c4f2358f2577e7258108099f29144
tree32f4e71f7579abd2cc56f7b991f3a8c80e966336
parent1af55d19c7a9189374d89472f97dc119659bb67e
parent8731d4dfb479914a91f650f4f124528e332e8128
Rollup merge of #86479 - exphp-forks:float-debug-exponential, r=yaahc

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)
library/core/src/fmt/float.rs
library/core/src/num/f32.rs
library/core/src/num/f64.rs