Make some float methods unstable const fn
· qinheping/verify-rust-std@1897d05 (original) (raw)
`@@ -471,7 +471,7 @@ impl f128 {
`
471
471
`#[inline]
`
472
472
`#[must_use]
`
473
473
`#[unstable(feature = "f128", issue = "116909")]
`
474
``
`-
pub fn is_sign_positive(self) -> bool {
`
``
474
`+
pub const fn is_sign_positive(self) -> bool {
`
475
475
` !self.is_sign_negative()
`
476
476
`}
`
477
477
``
`@@ -497,7 +497,7 @@ impl f128 {
`
497
497
`#[inline]
`
498
498
`#[must_use]
`
499
499
`#[unstable(feature = "f128", issue = "116909")]
`
500
``
`-
pub fn is_sign_negative(self) -> bool {
`
``
500
`+
pub const fn is_sign_negative(self) -> bool {
`
501
501
`// IEEE754 says: isSignMinus(x) is true if and only if x has negative sign. isSignMinus
`
502
502
`// applies to zeros and NaNs as well.
`
503
503
`// SAFETY: This is just transmuting to get the sign bit, it's fine.
`
`@@ -538,7 +538,7 @@ impl f128 {
`
538
538
`#[inline]
`
539
539
`#[unstable(feature = "f128", issue = "116909")]
`
540
540
`// #[unstable(feature = "float_next_up_down", issue = "91399")]
`
541
``
`-
pub fn next_up(self) -> Self {
`
``
541
`+
pub const fn next_up(self) -> Self {
`
542
542
`// Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
`
543
543
`// denormals to zero. This is in general unsound and unsupported, but here
`
544
544
`// we do our best to still produce the correct result on such targets.
`
`@@ -592,7 +592,7 @@ impl f128 {
`
592
592
`#[inline]
`
593
593
`#[unstable(feature = "f128", issue = "116909")]
`
594
594
`// #[unstable(feature = "float_next_up_down", issue = "91399")]
`
595
``
`-
pub fn next_down(self) -> Self {
`
``
595
`+
pub const fn next_down(self) -> Self {
`
596
596
`// Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
`
597
597
`// denormals to zero. This is in general unsound and unsupported, but here
`
598
598
`// we do our best to still produce the correct result on such targets.
`
`@@ -627,8 +627,9 @@ impl f128 {
`
627
627
```` /// ```
`628`
`628`
`#[inline]
`
`629`
`629`
`#[unstable(feature = "f128", issue = "116909")]
`
``
`630`
`+
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
`
`630`
`631`
`#[must_use = "this returns the result of the operation, without modifying the original"]
`
`631`
``
`-
pub fn recip(self) -> Self {
`
``
`632`
`+
pub const fn recip(self) -> Self {
`
`632`
`633`
`1.0 / self
`
`633`
`634`
`}
`
`634`
`635`
``
`@@ -647,8 +648,9 @@ impl f128 {
`
`647`
`648`
```` /// ```
648
649
`#[inline]
`
649
650
`#[unstable(feature = "f128", issue = "116909")]
`
``
651
`+
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
`
650
652
`#[must_use = "this returns the result of the operation, without modifying the original"]
`
651
``
`-
pub fn to_degrees(self) -> Self {
`
``
653
`+
pub const fn to_degrees(self) -> Self {
`
652
654
`// Use a literal for better precision.
`
653
655
`const PIS_IN_180: f128 = 57.2957795130823208767981548141051703324054724665643215491602_f128;
`
654
656
`self * PIS_IN_180
`
`@@ -670,8 +672,9 @@ impl f128 {
`
670
672
```` /// ```
`671`
`673`
`#[inline]
`
`672`
`674`
`#[unstable(feature = "f128", issue = "116909")]
`
``
`675`
`+
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
`
`673`
`676`
`#[must_use = "this returns the result of the operation, without modifying the original"]
`
`674`
``
`-
pub fn to_radians(self) -> f128 {
`
``
`677`
`+
pub const fn to_radians(self) -> f128 {
`
`675`
`678`
`// Use a literal for better precision.
`
`676`
`679`
`const RADS_PER_DEG: f128 =
`
`677`
`680`
`0.0174532925199432957692369076848861271344287188854172545609719_f128;
`
`@@ -698,8 +701,9 @@ impl f128 {
`
`698`
`701`
```` /// ```
699
702
`#[inline]
`
700
703
`#[unstable(feature = "f128", issue = "116909")]
`
``
704
`+
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
`
701
705
`#[must_use = "this returns the result of the comparison, without modifying either input"]
`
702
``
`-
pub fn max(self, other: f128) -> f128 {
`
``
706
`+
pub const fn max(self, other: f128) -> f128 {
`
703
707
` intrinsics::maxnumf128(self, other)
`
704
708
`}
`
705
709
``
`@@ -723,8 +727,9 @@ impl f128 {
`
723
727
```` /// ```
`724`
`728`
`#[inline]
`
`725`
`729`
`#[unstable(feature = "f128", issue = "116909")]
`
``
`730`
`+
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
`
`726`
`731`
`#[must_use = "this returns the result of the comparison, without modifying either input"]
`
`727`
``
`-
pub fn min(self, other: f128) -> f128 {
`
``
`732`
`+
pub const fn min(self, other: f128) -> f128 {
`
`728`
`733`
` intrinsics::minnumf128(self, other)
`
`729`
`734`
`}
`
`730`
`735`
``
`@@ -757,7 +762,7 @@ impl f128 {
`
`757`
`762`
`#[unstable(feature = "f128", issue = "116909")]
`
`758`
`763`
`// #[unstable(feature = "float_minimum_maximum", issue = "91079")]
`
`759`
`764`
`#[must_use = "this returns the result of the comparison, without modifying either input"]
`
`760`
``
`-
pub fn maximum(self, other: f128) -> f128 {
`
``
`765`
`+
pub const fn maximum(self, other: f128) -> f128 {
`
`761`
`766`
`if self > other {
`
`762`
`767`
`self
`
`763`
`768`
`} else if other > self {
`
`@@ -798,7 +803,7 @@ impl f128 {
`
`798`
`803`
`#[unstable(feature = "f128", issue = "116909")]
`
`799`
`804`
`// #[unstable(feature = "float_minimum_maximum", issue = "91079")]
`
`800`
`805`
`#[must_use = "this returns the result of the comparison, without modifying either input"]
`
`801`
``
`-
pub fn minimum(self, other: f128) -> f128 {
`
``
`806`
`+
pub const fn minimum(self, other: f128) -> f128 {
`
`802`
`807`
`if self < other {
`
`803`
`808`
`self
`
`804`
`809`
`} else if other < self {
`
`@@ -1269,9 +1274,20 @@ impl f128 {
`
`1269`
`1274`
```` /// ```
1270
1275
`#[inline]
`
1271
1276
`#[unstable(feature = "f128", issue = "116909")]
`
``
1277
`+
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
`
1272
1278
`#[must_use = "method returns a new number and does not mutate the original value"]
`
1273
``
`-
pub fn clamp(mut self, min: f128, max: f128) -> f128 {
`
1274
``
`-
assert!(min <= max, "min > max, or either was NaN. min = {min:?}, max = {max:?}");
`
``
1279
`+
pub const fn clamp(mut self, min: f128, max: f128) -> f128 {
`
``
1280
`+
#[inline] // inline to avoid LLVM crash
`
``
1281
`+
const fn assert_at_const(min: f128, max: f128) {
`
``
1282
`+
// Note that we cannot format in constant expressions.
`
``
1283
`+
assert!(min <= max, "min > max, or either was NaN");
`
``
1284
`+
}
`
``
1285
`+
#[inline] // inline to avoid codegen regression
`
``
1286
`+
fn assert_at_rt(min: f128, max: f128) {
`
``
1287
`+
assert!(min <= max, "min > max, or either was NaN. min = {min:?}, max = {max:?}");
`
``
1288
`+
}
`
``
1289
`+
// FIXME(const-hack): We would prefer to have streamlined panics when formatters become const-friendly.
`
``
1290
`+
intrinsics::const_eval_select((min, max), assert_at_const, assert_at_rt);
`
1275
1291
`if self < min {
`
1276
1292
`self = min;
`
1277
1293
`}
`