From 367d9e59f92f8f81b773d611c7ada4d058dd0b87 Mon Sep 17 00:00:00 2001 From: devrelu <100027958+devrelu@users.noreply.github.com> Date: Sat, 21 Nov 2026 21:16:02 +0900 Subject: [PATCH 1/2] Append bytes to result before loop in mod.rs --- src/pretty/to_fixed/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pretty/to_fixed/mod.rs b/src/pretty/to_fixed/mod.rs index e1f9187..61b0243 100644 --- a/src/pretty/to_fixed/mod.rs +++ b/src/pretty/to_fixed/mod.rs @@ -558,7 +558,8 @@ pub unsafe fn format64_to_fixed(f: f64, fraction_digits: u8, result: *mut u8) -> let mut round_up = false; - for i in 0..blocks { + result.append_bytes(b'0', 9 * min_block as usize); + for i in min_block as u32..blocks { let p: isize = POW10_OFFSET_2[idx] as isize + i as isize - min_block as isize; debug_assert!(p >= 0); let p = p as usize; From 9576e2118f432d1b51bad2d1b28bff8b80254756 Mon Sep 17 00:00:00 2001 From: devrelu <100027958+devrelu@users.noreply.github.com> Date: Sat, 21 Nov 2026 21:19:44 +0900 Subject: [PATCH 2/2] Update minimum exponent constants and add tests --- tests/to_fixed.rs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/tests/to_fixed.rs b/tests/to_fixed.rs index a8867b0..8e613fd 100644 --- a/tests/to_fixed.rs +++ b/tests/to_fixed.rs @@ -340,7 +340,8 @@ fn test_max_exponent_boundry_and_full_mantissa() { ); } -const MIN_EXPONENT: u16 = 0b010_1001_0011; +const MIN_EXPONENT_ZERO_MANTISSA: u16 = 0b010_1011_0001; +const MIN_EXPONENT_FULL_MANTISSA: u16 = 0b010_1011_0000; #[test] fn test_min_exponent_boundry_zero_mantissa() { @@ -348,7 +349,7 @@ fn test_min_exponent_boundry_zero_mantissa() { let expected = "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; - for exponent in 0..=MIN_EXPONENT { + for exponent in 0..=MIN_EXPONENT_ZERO_MANTISSA { assert_eq!( pretty_to_fixed(f64_from_parts(false, exponent, m), 100), expected @@ -356,7 +357,10 @@ fn test_min_exponent_boundry_zero_mantissa() { } assert_ne!( - pretty_to_fixed(f64_from_parts(false, MIN_EXPONENT + 1, m), 100), + pretty_to_fixed( + f64_from_parts(false, MIN_EXPONENT_ZERO_MANTISSA + 1, m), + 100 + ), expected ); } @@ -367,7 +371,7 @@ fn test_min_exponent_boundry_full_mantissa() { let expected = "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; - for exponent in 0..=MIN_EXPONENT { + for exponent in 0..=MIN_EXPONENT_FULL_MANTISSA { assert_eq!( pretty_to_fixed(f64_from_parts(false, exponent, m), 100), expected @@ -375,11 +379,30 @@ fn test_min_exponent_boundry_full_mantissa() { } assert_ne!( - pretty_to_fixed(f64_from_parts(false, MIN_EXPONENT + 1, m), 100), + pretty_to_fixed( + f64_from_parts(false, MIN_EXPONENT_FULL_MANTISSA + 1, m), + 100 + ), expected ); } +#[test] +fn test_leading_zero_blocks() { + assert_eq!( + pretty_to_fixed(1e-17, 40), + "0.0000000000000000100000000000000007154242" + ); + assert_eq!( + pretty_to_fixed(3.386680864129311e-41, 96), + "0.000000000000000000000000000000000000000033866808641293112412157561681710000260256078959410848719" + ); + assert_eq!( + pretty_to_fixed(2.0717877721678957e-18, 59), + "0.00000000000000000207178777216789569372363572982679877745972" + ); +} + // Regression test for https://github.com/boa-dev/ryu-js/issues/55 // Rounding carry that propagates through all integer digits must not // read out-of-bounds before the buffer start.