File tree Expand file tree Collapse file tree 3 files changed +15
-15
lines changed Expand file tree Collapse file tree 3 files changed +15
-15
lines changed Original file line number Diff line number Diff line change @@ -84,32 +84,32 @@ pub fn is_integer(v: f64) -> bool {
84
84
}
85
85
86
86
#[ derive( Debug ) ]
87
- pub enum FloatFormatCase {
87
+ pub enum Case {
88
88
Lower ,
89
89
Upper ,
90
90
}
91
91
92
- fn format_nan ( case : FloatFormatCase ) -> String {
92
+ fn format_nan ( case : Case ) -> String {
93
93
let nan = match case {
94
- FloatFormatCase :: Lower => "nan" ,
95
- FloatFormatCase :: Upper => "NAN" ,
94
+ Case :: Lower => "nan" ,
95
+ Case :: Upper => "NAN" ,
96
96
} ;
97
97
98
98
nan. to_string ( )
99
99
}
100
100
101
- fn format_inf ( case : FloatFormatCase ) -> String {
101
+ fn format_inf ( case : Case ) -> String {
102
102
let inf = match case {
103
- FloatFormatCase :: Lower => "inf" ,
104
- FloatFormatCase :: Upper => "INF" ,
103
+ Case :: Lower => "inf" ,
104
+ Case :: Upper => "INF" ,
105
105
} ;
106
106
107
107
inf. to_string ( )
108
108
}
109
109
110
110
// Formats floats into Python style exponent notation, by first formatting in Rust style
111
111
// exponent notation (`1.0000e0`), then convert to Python style (`1.0000e+00`).
112
- pub fn format_float_as_exponent ( precision : usize , magnitude : f64 , case : FloatFormatCase ) -> String {
112
+ pub fn format_exponent ( precision : usize , magnitude : f64 , case : Case ) -> String {
113
113
match magnitude {
114
114
magnitude if magnitude. is_finite ( ) => {
115
115
let r_exp = format ! ( "{:.*e}" , precision, magnitude) ;
Original file line number Diff line number Diff line change @@ -329,11 +329,11 @@ impl CFormatSpec {
329
329
}
330
330
CFormatType :: Float ( CFloatType :: Exponent ( case) ) => {
331
331
let case = match case {
332
- CFormatCase :: Lowercase => float_ops:: FloatFormatCase :: Lower ,
333
- CFormatCase :: Uppercase => float_ops:: FloatFormatCase :: Upper ,
332
+ CFormatCase :: Lowercase => float_ops:: Case :: Lower ,
333
+ CFormatCase :: Uppercase => float_ops:: Case :: Upper ,
334
334
} ;
335
335
let magnitude = num. abs ( ) ;
336
- float_ops:: format_float_as_exponent ( precision, magnitude, case)
336
+ float_ops:: format_exponent ( precision, magnitude, case)
337
337
}
338
338
CFormatType :: Float ( CFloatType :: General ( case) ) => {
339
339
let precision = if precision == 0 { 1 } else { precision } ;
Original file line number Diff line number Diff line change @@ -375,15 +375,15 @@ impl FormatSpec {
375
375
Some ( FormatType :: GeneralFormatLower ) => {
376
376
Err ( "Format code 'g' for object of type 'float' not implemented yet" )
377
377
}
378
- Some ( FormatType :: ExponentUpper ) => Ok ( float_ops:: format_float_as_exponent (
378
+ Some ( FormatType :: ExponentUpper ) => Ok ( float_ops:: format_exponent (
379
379
precision,
380
380
magnitude,
381
- float_ops:: FloatFormatCase :: Upper ,
381
+ float_ops:: Case :: Upper ,
382
382
) ) ,
383
- Some ( FormatType :: ExponentLower ) => Ok ( float_ops:: format_float_as_exponent (
383
+ Some ( FormatType :: ExponentLower ) => Ok ( float_ops:: format_exponent (
384
384
precision,
385
385
magnitude,
386
- float_ops:: FloatFormatCase :: Lower ,
386
+ float_ops:: Case :: Lower ,
387
387
) ) ,
388
388
Some ( FormatType :: Percentage ) => match magnitude {
389
389
magnitude if magnitude. is_nan ( ) => Ok ( "nan%" . to_owned ( ) ) ,
You can’t perform that action at this time.
0 commit comments