@@ -32,22 +32,23 @@ fn float_to_decimal_common_exact<T>(fmt: &mut Formatter, num: &T,
3232// Don't inline this so callers that call both this and the above won't wind
3333// up using the combined stack space of both functions in some cases.
3434#[ inline( never) ]
35- fn float_to_decimal_common_shortest < T > ( fmt : & mut Formatter ,
36- num : & T , sign : flt2dec:: Sign ) -> Result
35+ fn float_to_decimal_common_shortest < T > ( fmt : & mut Formatter , num : & T ,
36+ sign : flt2dec:: Sign , precision : usize ) -> Result
3737 where T : flt2dec:: DecodableFloat
3838{
3939 unsafe {
4040 // enough for f32 and f64
4141 let mut buf: [ u8 ; flt2dec:: MAX_SIG_DIGITS ] = mem:: uninitialized ( ) ;
4242 let mut parts: [ flt2dec:: Part ; 4 ] = mem:: uninitialized ( ) ;
43- let formatted = flt2dec:: to_shortest_str ( flt2dec:: strategy:: grisu:: format_shortest,
44- * num , sign, 0 , false , & mut buf, & mut parts) ;
43+ let formatted = flt2dec:: to_shortest_str ( flt2dec:: strategy:: grisu:: format_shortest, * num ,
44+ sign, precision , false , & mut buf, & mut parts) ;
4545 fmt. pad_formatted_parts ( & formatted)
4646 }
4747}
4848
4949// Common code of floating point Debug and Display.
50- fn float_to_decimal_common < T > ( fmt : & mut Formatter , num : & T , negative_zero : bool ) -> Result
50+ fn float_to_decimal_common < T > ( fmt : & mut Formatter , num : & T ,
51+ negative_zero : bool , min_precision : usize ) -> Result
5152 where T : flt2dec:: DecodableFloat
5253{
5354 let force_sign = fmt. sign_plus ( ) ;
@@ -61,7 +62,7 @@ fn float_to_decimal_common<T>(fmt: &mut Formatter, num: &T, negative_zero: bool)
6162 if let Some ( precision) = fmt. precision {
6263 float_to_decimal_common_exact ( fmt, num, sign, precision)
6364 } else {
64- float_to_decimal_common_shortest ( fmt, num, sign)
65+ float_to_decimal_common_shortest ( fmt, num, sign, min_precision )
6566 }
6667}
6768
@@ -125,14 +126,14 @@ macro_rules! floating {
125126 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
126127 impl Debug for $ty {
127128 fn fmt( & self , fmt: & mut Formatter ) -> Result {
128- float_to_decimal_common( fmt, self , true )
129+ float_to_decimal_common( fmt, self , true , 1 )
129130 }
130131 }
131132
132133 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
133134 impl Display for $ty {
134135 fn fmt( & self , fmt: & mut Formatter ) -> Result {
135- float_to_decimal_common( fmt, self , false )
136+ float_to_decimal_common( fmt, self , false , 0 )
136137 }
137138 }
138139
0 commit comments