@@ -21,6 +21,10 @@ use result;
2121use slice;
2222use str;
2323
24+ mod float;
25+ mod num;
26+ mod builders;
27+
2428#[ unstable( feature = "fmt_flags_align" , issue = "27726" ) ]
2529/// Possible alignments returned by `Formatter::align`
2630#[ derive( Debug ) ]
@@ -38,9 +42,6 @@ pub enum Alignment {
3842#[ stable( feature = "debug_builders" , since = "1.2.0" ) ]
3943pub use self :: builders:: { DebugStruct , DebugTuple , DebugSet , DebugList , DebugMap } ;
4044
41- mod num;
42- mod builders;
43-
4445#[ unstable( feature = "fmt_internals" , reason = "internal to format_args!" ,
4546 issue = "0" ) ]
4647#[ doc( hidden) ]
@@ -1511,86 +1512,6 @@ impl<'a, T: ?Sized> Pointer for &'a mut T {
15111512 }
15121513}
15131514
1514- // Common code of floating point Debug and Display.
1515- fn float_to_decimal_common < T > ( fmt : & mut Formatter , num : & T , negative_zero : bool ) -> Result
1516- where T : flt2dec:: DecodableFloat
1517- {
1518- let force_sign = fmt. sign_plus ( ) ;
1519- let sign = match ( force_sign, negative_zero) {
1520- ( false , false ) => flt2dec:: Sign :: Minus ,
1521- ( false , true ) => flt2dec:: Sign :: MinusRaw ,
1522- ( true , false ) => flt2dec:: Sign :: MinusPlus ,
1523- ( true , true ) => flt2dec:: Sign :: MinusPlusRaw ,
1524- } ;
1525-
1526- let mut buf = [ 0 ; 1024 ] ; // enough for f32 and f64
1527- let mut parts = [ flt2dec:: Part :: Zero ( 0 ) ; 16 ] ;
1528- let formatted = if let Some ( precision) = fmt. precision {
1529- flt2dec:: to_exact_fixed_str ( flt2dec:: strategy:: grisu:: format_exact, * num, sign,
1530- precision, false , & mut buf, & mut parts)
1531- } else {
1532- flt2dec:: to_shortest_str ( flt2dec:: strategy:: grisu:: format_shortest, * num, sign,
1533- 0 , false , & mut buf, & mut parts)
1534- } ;
1535- fmt. pad_formatted_parts ( & formatted)
1536- }
1537-
1538- // Common code of floating point LowerExp and UpperExp.
1539- fn float_to_exponential_common < T > ( fmt : & mut Formatter , num : & T , upper : bool ) -> Result
1540- where T : flt2dec:: DecodableFloat
1541- {
1542- let force_sign = fmt. sign_plus ( ) ;
1543- let sign = match force_sign {
1544- false => flt2dec:: Sign :: Minus ,
1545- true => flt2dec:: Sign :: MinusPlus ,
1546- } ;
1547-
1548- let mut buf = [ 0 ; 1024 ] ; // enough for f32 and f64
1549- let mut parts = [ flt2dec:: Part :: Zero ( 0 ) ; 16 ] ;
1550- let formatted = if let Some ( precision) = fmt. precision {
1551- // 1 integral digit + `precision` fractional digits = `precision + 1` total digits
1552- flt2dec:: to_exact_exp_str ( flt2dec:: strategy:: grisu:: format_exact, * num, sign,
1553- precision + 1 , upper, & mut buf, & mut parts)
1554- } else {
1555- flt2dec:: to_shortest_exp_str ( flt2dec:: strategy:: grisu:: format_shortest, * num, sign,
1556- ( 0 , 0 ) , upper, & mut buf, & mut parts)
1557- } ;
1558- fmt. pad_formatted_parts ( & formatted)
1559- }
1560-
1561- macro_rules! floating { ( $ty: ident) => {
1562-
1563- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1564- impl Debug for $ty {
1565- fn fmt( & self , fmt: & mut Formatter ) -> Result {
1566- float_to_decimal_common( fmt, self , true )
1567- }
1568- }
1569-
1570- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1571- impl Display for $ty {
1572- fn fmt( & self , fmt: & mut Formatter ) -> Result {
1573- float_to_decimal_common( fmt, self , false )
1574- }
1575- }
1576-
1577- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1578- impl LowerExp for $ty {
1579- fn fmt( & self , fmt: & mut Formatter ) -> Result {
1580- float_to_exponential_common( fmt, self , false )
1581- }
1582- }
1583-
1584- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1585- impl UpperExp for $ty {
1586- fn fmt( & self , fmt: & mut Formatter ) -> Result {
1587- float_to_exponential_common( fmt, self , true )
1588- }
1589- }
1590- } }
1591- floating ! { f32 }
1592- floating ! { f64 }
1593-
15941515// Implementation of Display/Debug for various core types
15951516
15961517#[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments