@@ -277,16 +277,6 @@ fn parse_format_spec(text: &str) -> Result<FormatSpec, &'static str> {
277
277
} )
278
278
}
279
279
280
- // Formats floats into Python style exponent notation, by first formatting in Rust style
281
- // exponent notation (`1.0000e0`), then convert to Python style (`1.0000e+00`).
282
- fn format_float_as_exponent ( precision : usize , magnitude : f64 , separator : & str ) -> String {
283
- let r_exp = format ! ( "{:.*e}" , precision, magnitude) ;
284
- let mut parts = r_exp. splitn ( 2 , 'e' ) ;
285
- let base = parts. next ( ) . unwrap ( ) ;
286
- let exponent = parts. next ( ) . unwrap ( ) . parse :: < i64 > ( ) . unwrap ( ) ;
287
- format ! ( "{}{}+{:02}" , base, separator, exponent)
288
- }
289
-
290
280
impl FormatSpec {
291
281
pub ( crate ) fn parse ( text : & str ) -> Result < FormatSpec , & ' static str > {
292
282
parse_format_spec ( text)
@@ -385,16 +375,12 @@ impl FormatSpec {
385
375
Some ( FormatType :: GeneralFormatLower ) => {
386
376
Err ( "Format code 'g' for object of type 'float' not implemented yet" )
387
377
}
388
- Some ( FormatType :: ExponentUpper ) => match magnitude {
389
- magnitude if magnitude. is_nan ( ) => Ok ( "NAN" . to_owned ( ) ) ,
390
- magnitude if magnitude. is_infinite ( ) => Ok ( "INF" . to_owned ( ) ) ,
391
- _ => Ok ( format_float_as_exponent ( precision, magnitude, "E" ) ) ,
392
- } ,
393
- Some ( FormatType :: ExponentLower ) => match magnitude {
394
- magnitude if magnitude. is_nan ( ) => Ok ( "nan" . to_owned ( ) ) ,
395
- magnitude if magnitude. is_infinite ( ) => Ok ( "inf" . to_owned ( ) ) ,
396
- _ => Ok ( format_float_as_exponent ( precision, magnitude, "e" ) ) ,
397
- } ,
378
+ Some ( FormatType :: ExponentUpper ) => {
379
+ Ok ( float_ops:: format_float_as_exponent ( precision, magnitude) . to_uppercase ( ) )
380
+ }
381
+ Some ( FormatType :: ExponentLower ) => {
382
+ Ok ( float_ops:: format_float_as_exponent ( precision, magnitude) . to_lowercase ( ) )
383
+ }
398
384
Some ( FormatType :: Percentage ) => match magnitude {
399
385
magnitude if magnitude. is_nan ( ) => Ok ( "nan%" . to_owned ( ) ) ,
400
386
magnitude if magnitude. is_infinite ( ) => Ok ( "inf%" . to_owned ( ) ) ,
0 commit comments