11use crate :: raw;
22#[ cfg( maybe_uninit) ]
33use core:: mem:: MaybeUninit ;
4- use core:: { mem , slice, str} ;
4+ use core:: { slice, str} ;
55#[ cfg( feature = "no-panic" ) ]
66use no_panic:: no_panic;
77
8- const NAN : & ' static str = "NaN" ;
9- const INFINITY : & ' static str = "Infinity" ;
10- const NEG_INFINITY : & ' static str = "-Infinity" ;
8+ const NAN : & str = "NaN" ;
9+ const INFINITY : & str = "Infinity" ;
10+ const NEG_INFINITY : & str = "-Infinity" ;
1111
1212/// Safe API for formatting floating point numbers to text.
1313///
1414/// ## Example
1515///
1616/// ```
17- /// let mut buffer = ryu ::Buffer::new();
17+ /// let mut buffer = ryu_js ::Buffer::new();
1818/// let printed = buffer.format_finite(1.234);
1919/// assert_eq!(printed, "1.234");
2020/// ```
2121pub struct Buffer {
2222 #[ cfg( maybe_uninit) ]
23- bytes : [ MaybeUninit < u8 > ; 24 ] ,
23+ bytes : [ MaybeUninit < u8 > ; 25 ] ,
2424 #[ cfg( not( maybe_uninit) ) ]
25- bytes : [ u8 ; 24 ] ,
25+ bytes : [ u8 ; 25 ] ,
2626}
2727
2828impl Buffer {
@@ -34,11 +34,11 @@ impl Buffer {
3434 // assume_init is safe here, since this is an array of MaybeUninit, which does not need
3535 // to be initialized.
3636 #[ cfg( maybe_uninit) ]
37- let bytes = [ MaybeUninit :: < u8 > :: uninit ( ) ; 24 ] ;
37+ let bytes = [ MaybeUninit :: < u8 > :: uninit ( ) ; 25 ] ;
3838 #[ cfg( not( maybe_uninit) ) ]
3939 let bytes = unsafe { mem:: uninitialized ( ) } ;
4040
41- Buffer { bytes : bytes }
41+ Buffer { bytes }
4242 }
4343
4444 /// Print a floating point number into this buffer and return a reference to
@@ -47,11 +47,13 @@ impl Buffer {
4747 /// # Special cases
4848 ///
4949 /// This function formats NaN as the string "NaN", positive infinity as
50- /// "inf ", and negative infinity as "-inf " to match std::fmt .
50+ /// "Infinity ", and negative infinity as "-Infinity " to match the [ECMAScript specification][spec] .
5151 ///
5252 /// If your input is known to be finite, you may get better performance by
5353 /// calling the `format_finite` method instead of `format` to avoid the
5454 /// checks for special cases.
55+ ///
56+ /// [spec]: https://tc39.es/ecma262/#sec-numeric-types-number-tostring
5557 #[ cfg_attr( feature = "no-panic" , inline) ]
5658 #[ cfg_attr( feature = "no-panic" , no_panic) ]
5759 pub fn format < F : Float > ( & mut self , f : F ) -> & str {
@@ -125,7 +127,7 @@ impl Sealed for f32 {
125127 #[ inline]
126128 fn is_nonfinite ( self ) -> bool {
127129 const EXP_MASK : u32 = 0x7f800000 ;
128- let bits = unsafe { mem :: transmute :: < f32 , u32 > ( self ) } ;
130+ let bits = self . to_bits ( ) ;
129131 bits & EXP_MASK == EXP_MASK
130132 }
131133
@@ -134,7 +136,7 @@ impl Sealed for f32 {
134136 fn format_nonfinite ( self ) -> & ' static str {
135137 const MANTISSA_MASK : u32 = 0x007fffff ;
136138 const SIGN_MASK : u32 = 0x80000000 ;
137- let bits = unsafe { mem :: transmute :: < f32 , u32 > ( self ) } ;
139+ let bits = self . to_bits ( ) ;
138140 if bits & MANTISSA_MASK != 0 {
139141 NAN
140142 } else if bits & SIGN_MASK != 0 {
@@ -154,7 +156,7 @@ impl Sealed for f64 {
154156 #[ inline]
155157 fn is_nonfinite ( self ) -> bool {
156158 const EXP_MASK : u64 = 0x7ff0000000000000 ;
157- let bits = unsafe { mem :: transmute :: < f64 , u64 > ( self ) } ;
159+ let bits = self . to_bits ( ) ;
158160 bits & EXP_MASK == EXP_MASK
159161 }
160162
@@ -163,7 +165,7 @@ impl Sealed for f64 {
163165 fn format_nonfinite ( self ) -> & ' static str {
164166 const MANTISSA_MASK : u64 = 0x000fffffffffffff ;
165167 const SIGN_MASK : u64 = 0x8000000000000000 ;
166- let bits = unsafe { mem :: transmute :: < f64 , u64 > ( self ) } ;
168+ let bits = self . to_bits ( ) ;
167169 if bits & MANTISSA_MASK != 0 {
168170 NAN
169171 } else if bits & SIGN_MASK != 0 {
0 commit comments