]> git.lizzy.rs Git - rust.git/commit
Automatic exponential formatting in Debug
authorMichael Lamparski <diagonaldevice@gmail.com>
Sat, 19 Jun 2021 19:50:29 +0000 (15:50 -0400)
committerMichael Lamparski <diagonaldevice@gmail.com>
Sun, 20 Jun 2021 00:53:26 +0000 (20:53 -0400)
commit8731d4dfb479914a91f650f4f124528e332e8128
tree3c9d8f12fb1f49e9984643adcf5b067b3b069434
parent312b894cc12240a3fcc645474c3daa14f7d568ea
Automatic exponential formatting in Debug

* {:.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.
library/core/src/fmt/float.rs
library/core/src/num/f32.rs
library/core/src/num/f64.rs
library/core/tests/fmt/float.rs