about summary refs log tree commit diff
path: root/library/core/src
diff options
context:
space:
mode:
authorJames Dietz <jamesthespeedy@gmail.com>2023-09-30 16:01:01 -0400
committerJames Dietz <jamesthespeedy@gmail.com>2023-11-11 16:40:22 -0500
commite81964e6f900fbe725ce0fad3c7a29d6536146e9 (patch)
tree70dd22bf5afc02058931c0443ee49fad32d22d3f /library/core/src
parented086d86b8b224f7df2da09cf48ac2a654bf841e (diff)
downloadrust-e81964e6f900fbe725ce0fad3c7a29d6536146e9.tar.gz
rust-e81964e6f900fbe725ce0fad3c7a29d6536146e9.zip
fix rounding issue with exponents in fmt
Diffstat (limited to 'library/core/src')
-rw-r--r--library/core/src/fmt/num.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/library/core/src/fmt/num.rs b/library/core/src/fmt/num.rs
index 4f42f73ebba..a1467384c9c 100644
--- a/library/core/src/fmt/num.rs
+++ b/library/core/src/fmt/num.rs
@@ -334,8 +334,16 @@ macro_rules! impl_Exp {
                     // round up last digit
                     if rem >= 5 {
                         n += 1;
+                        // if the digit is rounded to the next power
+                        // instead adjust the exponent
+                        if n % 10 == 0 {
+                            n /= 10;
+                            exponent += 1;
+                        }
                     }
+                    // n = 100
                 }
+                // assert!(n == 666, "{}\n{}\n{}\n",n, exponent, added_precision);
                 (n, exponent, exponent, added_precision)
             };