@@ -32,22 +32,23 @@ fn float_to_decimal_common_exact<T>(fmt: &mut Formatter, num: &T,
32
32
// Don't inline this so callers that call both this and the above won't wind
33
33
// up using the combined stack space of both functions in some cases.
34
34
#[ 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
37
37
where T : flt2dec:: DecodableFloat
38
38
{
39
39
unsafe {
40
40
// enough for f32 and f64
41
41
let mut buf: [ u8 ; flt2dec:: MAX_SIG_DIGITS ] = mem:: uninitialized ( ) ;
42
42
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) ;
45
45
fmt. pad_formatted_parts ( & formatted)
46
46
}
47
47
}
48
48
49
49
// 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
51
52
where T : flt2dec:: DecodableFloat
52
53
{
53
54
let force_sign = fmt. sign_plus ( ) ;
@@ -61,7 +62,7 @@ fn float_to_decimal_common<T>(fmt: &mut Formatter, num: &T, negative_zero: bool)
61
62
if let Some ( precision) = fmt. precision {
62
63
float_to_decimal_common_exact ( fmt, num, sign, precision)
63
64
} else {
64
- float_to_decimal_common_shortest ( fmt, num, sign)
65
+ float_to_decimal_common_shortest ( fmt, num, sign, min_precision )
65
66
}
66
67
}
67
68
@@ -125,14 +126,14 @@ macro_rules! floating {
125
126
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
126
127
impl Debug for $ty {
127
128
fn fmt( & self , fmt: & mut Formatter ) -> Result {
128
- float_to_decimal_common( fmt, self , true )
129
+ float_to_decimal_common( fmt, self , true , 1 )
129
130
}
130
131
}
131
132
132
133
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
133
134
impl Display for $ty {
134
135
fn fmt( & self , fmt: & mut Formatter ) -> Result {
135
- float_to_decimal_common( fmt, self , false )
136
+ float_to_decimal_common( fmt, self , false , 0 )
136
137
}
137
138
}
138
139
0 commit comments