@@ -68,6 +68,8 @@ mod traits;
6868#[ cfg( not( zmij_no_select_unpredictable) ) ]
6969use core:: hint;
7070use core:: mem:: { self , MaybeUninit } ;
71+ #[ cfg( test) ]
72+ use core:: ops:: Index ;
7173use core:: ptr;
7274use core:: slice;
7375use core:: str;
@@ -170,9 +172,27 @@ impl FloatTraits for f64 {
170172 }
171173}
172174
175+ struct Pow10SignificandsTable ( [ ( u64 , u64 ) ; 617 ] ) ;
176+
177+ impl Pow10SignificandsTable {
178+ unsafe fn get_unchecked ( & self , dec_exp : i32 ) -> & ( u64 , u64 ) {
179+ const DEC_EXP_MIN : i32 = -292 ;
180+ unsafe { self . 0 . get_unchecked ( ( dec_exp - DEC_EXP_MIN ) as usize ) }
181+ }
182+ }
183+
184+ #[ cfg( test) ]
185+ impl Index < i32 > for Pow10SignificandsTable {
186+ type Output = ( u64 , u64 ) ;
187+ fn index ( & self , dec_exp : i32 ) -> & Self :: Output {
188+ const DEC_EXP_MIN : i32 = -292 ;
189+ & self . 0 [ ( dec_exp - DEC_EXP_MIN ) as usize ]
190+ }
191+ }
192+
173193// 128-bit significands of powers of 10 rounded down.
174194// Generated using 192-bit arithmetic method by Dougall Johnson.
175- static POW10_SIGNIFICANDS : [ ( u64 , u64 ) ; 617 ] = {
195+ static POW10_SIGNIFICANDS : Pow10SignificandsTable = {
176196 let mut data = [ ( 0 , 0 ) ; 617 ] ;
177197
178198 struct uint192 {
@@ -218,11 +238,9 @@ static POW10_SIGNIFICANDS: [(u64, u64); 617] = {
218238 i += 1 ;
219239 }
220240
221- data
241+ Pow10SignificandsTable ( data)
222242} ;
223243
224- const DEC_EXP_MIN : i32 = -292 ;
225-
226244#[ cfg_attr( feature = "no-panic" , no_panic) ]
227245fn count_trailing_nonzeros ( x : u64 ) -> usize {
228246 // We count the number of bytes until there are only zeros left.
@@ -537,8 +555,7 @@ where
537555 let num_bits = mem:: size_of :: < UInt > ( ) as i32 * 8 ;
538556 if regular && !subnormal {
539557 let exp_shift = compute_exp_shift ( bin_exp, dec_exp) ;
540- let ( pow10_hi, pow10_lo) =
541- * unsafe { POW10_SIGNIFICANDS . get_unchecked ( ( -dec_exp - DEC_EXP_MIN ) as usize ) } ;
558+ let ( pow10_hi, pow10_lo) = * unsafe { POW10_SIGNIFICANDS . get_unchecked ( -dec_exp) } ;
542559
543560 let integral; // integral part of bin_sig * pow10
544561 let fractional; // fractional part of bin_sig * pow10
@@ -608,8 +625,7 @@ where
608625
609626 dec_exp = compute_dec_exp ( bin_exp, regular) ;
610627 let exp_shift = compute_exp_shift ( bin_exp, dec_exp) ;
611- let ( mut pow10_hi, mut pow10_lo) =
612- * unsafe { POW10_SIGNIFICANDS . get_unchecked ( ( -dec_exp - DEC_EXP_MIN ) as usize ) } ;
628+ let ( mut pow10_hi, mut pow10_lo) = * unsafe { POW10_SIGNIFICANDS . get_unchecked ( -dec_exp) } ;
613629
614630 // Fallback to Schubfach to guarantee correctness in boundary cases. This
615631 // requires switching to strict overestimates of powers of 10.
0 commit comments