@@ -28,21 +28,12 @@ pub enum ExponentFormat {
2828 /// Use exponential notation with the exponent having a base of 10 and the
2929 /// exponent sign being `e` or `E`. For example, 1000 would be printed
3030 /// 1e3.
31- ExpDec ,
32- /// Use exponential notation with the exponent having a base of 2 and the
33- /// exponent sign being `p` or `P`. For example, 8 would be printed 1p3.
34- ExpBin ,
31+ ExpDec
3532}
3633
3734/// The number of digits used for emitting the fractional part of a number, if
3835/// any.
3936pub enum SignificantDigits {
40- /// All calculable digits will be printed.
41- ///
42- /// Note that bignums or fractions may cause a surprisingly large number
43- /// of digits to be printed.
44- DigAll ,
45-
4637 /// At most the given number of digits will be printed, truncating any
4738 /// trailing zeroes.
4839 DigMax ( uint ) ,
@@ -53,17 +44,11 @@ pub enum SignificantDigits {
5344
5445/// How to emit the sign of a number.
5546pub enum SignFormat {
56- /// No sign will be printed. The exponent sign will also be emitted.
57- SignNone ,
5847 /// `-` will be printed for negative values, but no sign will be emitted
5948 /// for positive numbers.
60- SignNeg ,
61- /// `+` will be printed for positive values, and `-` will be printed for
62- /// negative values.
63- SignAll ,
49+ SignNeg
6450}
6551
66- static DIGIT_P_RADIX : uint = ( 'p' as uint ) - ( 'a' as uint ) + 11 u;
6752static DIGIT_E_RADIX : uint = ( 'e' as uint ) - ( 'a' as uint ) + 11 u;
6853
6954/**
@@ -111,9 +96,6 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
11196 ExpDec if radix >= DIGIT_E_RADIX // decimal exponent 'e'
11297 => fail ! ( "float_to_str_bytes_common: radix {} incompatible with \
11398 use of 'e' as decimal exponent", radix) ,
114- ExpBin if radix >= DIGIT_P_RADIX // binary exponent 'p'
115- => fail ! ( "float_to_str_bytes_common: radix {} incompatible with \
116- use of 'p' as binary exponent", radix) ,
11799 _ => ( )
118100 }
119101
@@ -123,16 +105,10 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
123105 match num. classify ( ) {
124106 FPNaN => return f ( "NaN" . as_bytes ( ) ) ,
125107 FPInfinite if num > _0 => {
126- return match sign {
127- SignAll => return f ( "+inf" . as_bytes ( ) ) ,
128- _ => return f ( "inf" . as_bytes ( ) ) ,
129- } ;
108+ return f ( "inf" . as_bytes ( ) ) ;
130109 }
131110 FPInfinite if num < _0 => {
132- return match sign {
133- SignNone => return f ( "inf" . as_bytes ( ) ) ,
134- _ => return f ( "-inf" . as_bytes ( ) ) ,
135- } ;
111+ return f ( "-inf" . as_bytes ( ) ) ;
136112 }
137113 _ => { }
138114 }
@@ -147,11 +123,10 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
147123
148124 let ( num, exp) = match exp_format {
149125 ExpNone => ( num, 0i32 ) ,
150- ExpDec | ExpBin if num == _0 => ( num, 0i32 ) ,
151- ExpDec | ExpBin => {
126+ ExpDec if num == _0 => ( num, 0i32 ) ,
127+ ExpDec => {
152128 let ( exp, exp_base) = match exp_format {
153129 ExpDec => ( num. abs ( ) . log10 ( ) . floor ( ) , cast :: < f64 , T > ( 10.0f64 ) . unwrap ( ) ) ,
154- ExpBin => ( num. abs ( ) . log2 ( ) . floor ( ) , cast :: < f64 , T > ( 2.0f64 ) . unwrap ( ) ) ,
155130 ExpNone => fail ! ( "unreachable" ) ,
156131 } ;
157132
@@ -185,21 +160,16 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
185160
186161 // If limited digits, calculate one digit more for rounding.
187162 let ( limit_digits, digit_count, exact) = match digits {
188- DigAll => ( false , 0 u, false ) ,
189- DigMax ( count) => ( true , count+1 , false ) ,
190- DigExact ( count) => ( true , count+1 , true )
163+ DigMax ( count) => ( true , count + 1 , false ) ,
164+ DigExact ( count) => ( true , count + 1 , true )
191165 } ;
192166
193167 // Decide what sign to put in front
194168 match sign {
195- SignNeg | SignAll if neg => {
169+ SignNeg if neg => {
196170 buf[ end] = b'-' ;
197171 end += 1 ;
198172 }
199- SignAll => {
200- buf[ end] = b'+' ;
201- end += 1 ;
202- }
203173 _ => ( )
204174 }
205175
@@ -329,8 +299,6 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
329299 buf[ end] = match exp_format {
330300 ExpDec if exp_upper => 'E' ,
331301 ExpDec if !exp_upper => 'e' ,
332- ExpBin if exp_upper => 'P' ,
333- ExpBin if !exp_upper => 'p' ,
334302 _ => fail ! ( "unreachable" ) ,
335303 } as u8 ;
336304 end += 1 ;
@@ -356,11 +324,6 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
356324 fmt:: write( & mut filler, args)
357325 } , "{:-}" , exp) ;
358326 }
359- SignNone | SignAll => {
360- let _ = format_args ! ( |args| {
361- fmt:: write( & mut filler, args)
362- } , "{}" , exp) ;
363- }
364327 }
365328 }
366329 }
0 commit comments