@@ -28,21 +28,12 @@ pub enum ExponentFormat {
28
28
/// Use exponential notation with the exponent having a base of 10 and the
29
29
/// exponent sign being `e` or `E`. For example, 1000 would be printed
30
30
/// 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
35
32
}
36
33
37
34
/// The number of digits used for emitting the fractional part of a number, if
38
35
/// any.
39
36
pub 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
-
46
37
/// At most the given number of digits will be printed, truncating any
47
38
/// trailing zeroes.
48
39
DigMax ( uint ) ,
@@ -53,17 +44,11 @@ pub enum SignificantDigits {
53
44
54
45
/// How to emit the sign of a number.
55
46
pub enum SignFormat {
56
- /// No sign will be printed. The exponent sign will also be emitted.
57
- SignNone ,
58
47
/// `-` will be printed for negative values, but no sign will be emitted
59
48
/// for positive numbers.
60
- SignNeg ,
61
- /// `+` will be printed for positive values, and `-` will be printed for
62
- /// negative values.
63
- SignAll ,
49
+ SignNeg
64
50
}
65
51
66
- static DIGIT_P_RADIX : uint = ( 'p' as uint ) - ( 'a' as uint ) + 11 u;
67
52
static DIGIT_E_RADIX : uint = ( 'e' as uint ) - ( 'a' as uint ) + 11 u;
68
53
69
54
/**
@@ -111,9 +96,6 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
111
96
ExpDec if radix >= DIGIT_E_RADIX // decimal exponent 'e'
112
97
=> fail ! ( "float_to_str_bytes_common: radix {} incompatible with \
113
98
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) ,
117
99
_ => ( )
118
100
}
119
101
@@ -123,16 +105,10 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
123
105
match num. classify ( ) {
124
106
FPNaN => return f ( "NaN" . as_bytes ( ) ) ,
125
107
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 ( ) ) ;
130
109
}
131
110
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 ( ) ) ;
136
112
}
137
113
_ => { }
138
114
}
@@ -147,11 +123,10 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
147
123
148
124
let ( num, exp) = match exp_format {
149
125
ExpNone => ( num, 0i32 ) ,
150
- ExpDec | ExpBin if num == _0 => ( num, 0i32 ) ,
151
- ExpDec | ExpBin => {
126
+ ExpDec if num == _0 => ( num, 0i32 ) ,
127
+ ExpDec => {
152
128
let ( exp, exp_base) = match exp_format {
153
129
ExpDec => ( num. abs ( ) . log10 ( ) . floor ( ) , cast :: < f64 , T > ( 10.0f64 ) . unwrap ( ) ) ,
154
- ExpBin => ( num. abs ( ) . log2 ( ) . floor ( ) , cast :: < f64 , T > ( 2.0f64 ) . unwrap ( ) ) ,
155
130
ExpNone => fail ! ( "unreachable" ) ,
156
131
} ;
157
132
@@ -185,21 +160,16 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
185
160
186
161
// If limited digits, calculate one digit more for rounding.
187
162
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 )
191
165
} ;
192
166
193
167
// Decide what sign to put in front
194
168
match sign {
195
- SignNeg | SignAll if neg => {
169
+ SignNeg if neg => {
196
170
buf[ end] = b'-' ;
197
171
end += 1 ;
198
172
}
199
- SignAll => {
200
- buf[ end] = b'+' ;
201
- end += 1 ;
202
- }
203
173
_ => ( )
204
174
}
205
175
@@ -329,8 +299,6 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
329
299
buf[ end] = match exp_format {
330
300
ExpDec if exp_upper => 'E' ,
331
301
ExpDec if !exp_upper => 'e' ,
332
- ExpBin if exp_upper => 'P' ,
333
- ExpBin if !exp_upper => 'p' ,
334
302
_ => fail ! ( "unreachable" ) ,
335
303
} as u8 ;
336
304
end += 1 ;
@@ -356,11 +324,6 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
356
324
fmt:: write( & mut filler, args)
357
325
} , "{:-}" , exp) ;
358
326
}
359
- SignNone | SignAll => {
360
- let _ = format_args ! ( |args| {
361
- fmt:: write( & mut filler, args)
362
- } , "{}" , exp) ;
363
- }
364
327
}
365
328
}
366
329
}
0 commit comments