Skip to content

Commit

Permalink
Stabilize float_to_from_bytes feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji committed Oct 31, 2019
1 parent 92df638 commit 7b72c28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
18 changes: 6 additions & 12 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,10 @@ impl f32 {
/// # Examples
///
/// ```
/// #![feature(float_to_from_bytes)]
/// let bytes = 12.5f32.to_be_bytes();
/// assert_eq!(bytes, [0x41, 0x48, 0x00, 0x00]);
/// ```
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[inline]
pub fn to_be_bytes(self) -> [u8; 4] {
self.to_bits().to_be_bytes()
Expand All @@ -482,11 +481,10 @@ impl f32 {
/// # Examples
///
/// ```
/// #![feature(float_to_from_bytes)]
/// let bytes = 12.5f32.to_le_bytes();
/// assert_eq!(bytes, [0x00, 0x00, 0x48, 0x41]);
/// ```
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[inline]
pub fn to_le_bytes(self) -> [u8; 4] {
self.to_bits().to_le_bytes()
Expand All @@ -504,7 +502,6 @@ impl f32 {
/// # Examples
///
/// ```
/// #![feature(float_to_from_bytes)]
/// let bytes = 12.5f32.to_ne_bytes();
/// assert_eq!(
/// bytes,
Expand All @@ -515,7 +512,7 @@ impl f32 {
/// }
/// );
/// ```
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[inline]
pub fn to_ne_bytes(self) -> [u8; 4] {
self.to_bits().to_ne_bytes()
Expand All @@ -526,11 +523,10 @@ impl f32 {
/// # Examples
///
/// ```
/// #![feature(float_to_from_bytes)]
/// let value = f32::from_be_bytes([0x41, 0x48, 0x00, 0x00]);
/// assert_eq!(value, 12.5);
/// ```
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[inline]
pub fn from_be_bytes(bytes: [u8; 4]) -> Self {
Self::from_bits(u32::from_be_bytes(bytes))
Expand All @@ -541,11 +537,10 @@ impl f32 {
/// # Examples
///
/// ```
/// #![feature(float_to_from_bytes)]
/// let value = f32::from_le_bytes([0x00, 0x00, 0x48, 0x41]);
/// assert_eq!(value, 12.5);
/// ```
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[inline]
pub fn from_le_bytes(bytes: [u8; 4]) -> Self {
Self::from_bits(u32::from_le_bytes(bytes))
Expand All @@ -563,15 +558,14 @@ impl f32 {
/// # Examples
///
/// ```
/// #![feature(float_to_from_bytes)]
/// let value = f32::from_ne_bytes(if cfg!(target_endian = "big") {
/// [0x41, 0x48, 0x00, 0x00]
/// } else {
/// [0x00, 0x00, 0x48, 0x41]
/// });
/// assert_eq!(value, 12.5);
/// ```
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[inline]
pub fn from_ne_bytes(bytes: [u8; 4]) -> Self {
Self::from_bits(u32::from_ne_bytes(bytes))
Expand Down
18 changes: 6 additions & 12 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,10 @@ impl f64 {
/// # Examples
///
/// ```
/// #![feature(float_to_from_bytes)]
/// let bytes = 12.5f64.to_be_bytes();
/// assert_eq!(bytes, [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
/// ```
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[inline]
pub fn to_be_bytes(self) -> [u8; 8] {
self.to_bits().to_be_bytes()
Expand All @@ -495,11 +494,10 @@ impl f64 {
/// # Examples
///
/// ```
/// #![feature(float_to_from_bytes)]
/// let bytes = 12.5f64.to_le_bytes();
/// assert_eq!(bytes, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
/// ```
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[inline]
pub fn to_le_bytes(self) -> [u8; 8] {
self.to_bits().to_le_bytes()
Expand All @@ -517,7 +515,6 @@ impl f64 {
/// # Examples
///
/// ```
/// #![feature(float_to_from_bytes)]
/// let bytes = 12.5f64.to_ne_bytes();
/// assert_eq!(
/// bytes,
Expand All @@ -528,7 +525,7 @@ impl f64 {
/// }
/// );
/// ```
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[inline]
pub fn to_ne_bytes(self) -> [u8; 8] {
self.to_bits().to_ne_bytes()
Expand All @@ -539,11 +536,10 @@ impl f64 {
/// # Examples
///
/// ```
/// #![feature(float_to_from_bytes)]
/// let value = f64::from_be_bytes([0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
/// assert_eq!(value, 12.5);
/// ```
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[inline]
pub fn from_be_bytes(bytes: [u8; 8]) -> Self {
Self::from_bits(u64::from_be_bytes(bytes))
Expand All @@ -554,11 +550,10 @@ impl f64 {
/// # Examples
///
/// ```
/// #![feature(float_to_from_bytes)]
/// let value = f64::from_le_bytes([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
/// assert_eq!(value, 12.5);
/// ```
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[inline]
pub fn from_le_bytes(bytes: [u8; 8]) -> Self {
Self::from_bits(u64::from_le_bytes(bytes))
Expand All @@ -576,15 +571,14 @@ impl f64 {
/// # Examples
///
/// ```
/// #![feature(float_to_from_bytes)]
/// let value = f64::from_ne_bytes(if cfg!(target_endian = "big") {
/// [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
/// } else {
/// [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]
/// });
/// assert_eq!(value, 12.5);
/// ```
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[inline]
pub fn from_ne_bytes(bytes: [u8; 8]) -> Self {
Self::from_bits(u64::from_ne_bytes(bytes))
Expand Down

0 comments on commit 7b72c28

Please sign in to comment.