X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_apfloat%2Flib.rs;h=d08ff60a366ccf52e57ade5b6df24204d799d84e;hb=6980f82c0d152446506fee4d4a45d8afdf4ad9a4;hp=5efe4fda8ccf85f47f5764b5be18d9413d144769;hpb=f3c9cece7b6829e6fd7854a1aee6a1619a81a38c;p=rust.git diff --git a/src/librustc_apfloat/lib.rs b/src/librustc_apfloat/lib.rs index 5efe4fda8cc..d08ff60a366 100644 --- a/src/librustc_apfloat/lib.rs +++ b/src/librustc_apfloat/lib.rs @@ -33,7 +33,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![no_std] #![forbid(unsafe_code)] - #![feature(nll)] #[macro_use] @@ -41,8 +40,8 @@ use core::cmp::Ordering; use core::fmt; -use core::ops::{Neg, Add, Sub, Mul, Div, Rem}; -use core::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign}; +use core::ops::{Add, Div, Mul, Neg, Rem, Sub}; +use core::ops::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign}; use core::str::FromStr; bitflags::bitflags! { @@ -69,19 +68,13 @@ pub struct StatusAnd { impl Status { pub fn and(self, value: T) -> StatusAnd { - StatusAnd { - status: self, - value, - } + StatusAnd { status: self, value } } } impl StatusAnd { pub fn map U, U>(self, f: F) -> StatusAnd { - StatusAnd { - status: self.status, - value: f(self.value), - } + StatusAnd { status: self.status, value: f(self.value) } } } @@ -102,7 +95,7 @@ macro_rules! unpack { value } } - } + }; } /// Category of internally-represented number. @@ -219,8 +212,8 @@ fn neg(self) -> Round { /// /// New operations: sqrt, nexttoward. /// -pub trait Float - : Copy +pub trait Float: + Copy + Default + FromStr + PartialOrd @@ -235,7 +228,8 @@ pub trait Float + Sub> + Mul> + Div> - + Rem> { + + Rem> +{ /// Total number of bits in the in-memory format. const BITS: usize; @@ -348,11 +342,7 @@ fn abs(self) -> Self { if self.is_negative() { -self } else { self } } fn copy_sign(self, rhs: Self) -> Self { - if self.is_negative() != rhs.is_negative() { - -self - } else { - self - } + if self.is_negative() != rhs.is_negative() { -self } else { self } } // Conversions @@ -409,9 +399,7 @@ fn to_i128_r(self, width: usize, round: Round, is_exact: &mut bool) -> StatusAnd } else { // Positive case is simpler, can pretend it's a smaller unsigned // integer, and `to_u128` will take care of all the edge cases. - self.to_u128_r(width - 1, round, is_exact).map( - |r| r as i128, - ) + self.to_u128_r(width - 1, round, is_exact).map(|r| r as i128) } } fn to_i128(self, width: usize) -> StatusAnd { @@ -535,9 +523,7 @@ fn is_integer(self) -> bool { if !self.is_finite() { return false; } - self.round_to_integral(Round::TowardZero).value.bitwise_eq( - self, - ) + self.round_to_integral(Round::TowardZero).value.bitwise_eq(self) } /// If this value has an exact multiplicative inverse, return it. @@ -586,13 +572,19 @@ fn convert(self, loses_info: &mut bool) -> StatusAnd { macro_rules! float_common_impls { ($ty:ident<$t:tt>) => { - impl<$t> Default for $ty<$t> where Self: Float { + impl<$t> Default for $ty<$t> + where + Self: Float, + { fn default() -> Self { Self::ZERO } } - impl<$t> ::core::str::FromStr for $ty<$t> where Self: Float { + impl<$t> ::core::str::FromStr for $ty<$t> + where + Self: Float, + { type Err = ParseError; fn from_str(s: &str) -> Result { Self::from_str_r(s, Round::NearestTiesToEven).map(|x| x.value) @@ -601,71 +593,101 @@ fn from_str(s: &str) -> Result { // Rounding ties to the nearest even, by default. - impl<$t> ::core::ops::Add for $ty<$t> where Self: Float { + impl<$t> ::core::ops::Add for $ty<$t> + where + Self: Float, + { type Output = StatusAnd; fn add(self, rhs: Self) -> StatusAnd { self.add_r(rhs, Round::NearestTiesToEven) } } - impl<$t> ::core::ops::Sub for $ty<$t> where Self: Float { + impl<$t> ::core::ops::Sub for $ty<$t> + where + Self: Float, + { type Output = StatusAnd; fn sub(self, rhs: Self) -> StatusAnd { self.sub_r(rhs, Round::NearestTiesToEven) } } - impl<$t> ::core::ops::Mul for $ty<$t> where Self: Float { + impl<$t> ::core::ops::Mul for $ty<$t> + where + Self: Float, + { type Output = StatusAnd; fn mul(self, rhs: Self) -> StatusAnd { self.mul_r(rhs, Round::NearestTiesToEven) } } - impl<$t> ::core::ops::Div for $ty<$t> where Self: Float { + impl<$t> ::core::ops::Div for $ty<$t> + where + Self: Float, + { type Output = StatusAnd; fn div(self, rhs: Self) -> StatusAnd { self.div_r(rhs, Round::NearestTiesToEven) } } - impl<$t> ::core::ops::Rem for $ty<$t> where Self: Float { + impl<$t> ::core::ops::Rem for $ty<$t> + where + Self: Float, + { type Output = StatusAnd; fn rem(self, rhs: Self) -> StatusAnd { self.c_fmod(rhs) } } - impl<$t> ::core::ops::AddAssign for $ty<$t> where Self: Float { + impl<$t> ::core::ops::AddAssign for $ty<$t> + where + Self: Float, + { fn add_assign(&mut self, rhs: Self) { *self = (*self + rhs).value; } } - impl<$t> ::core::ops::SubAssign for $ty<$t> where Self: Float { + impl<$t> ::core::ops::SubAssign for $ty<$t> + where + Self: Float, + { fn sub_assign(&mut self, rhs: Self) { *self = (*self - rhs).value; } } - impl<$t> ::core::ops::MulAssign for $ty<$t> where Self: Float { + impl<$t> ::core::ops::MulAssign for $ty<$t> + where + Self: Float, + { fn mul_assign(&mut self, rhs: Self) { *self = (*self * rhs).value; } } - impl<$t> ::core::ops::DivAssign for $ty<$t> where Self: Float { + impl<$t> ::core::ops::DivAssign for $ty<$t> + where + Self: Float, + { fn div_assign(&mut self, rhs: Self) { *self = (*self / rhs).value; } } - impl<$t> ::core::ops::RemAssign for $ty<$t> where Self: Float { + impl<$t> ::core::ops::RemAssign for $ty<$t> + where + Self: Float, + { fn rem_assign(&mut self, rhs: Self) { *self = (*self % rhs).value; } } - } + }; } pub mod ieee;