@@ -471,7 +471,7 @@ impl f128 {
471471 #[ inline]
472472 #[ must_use]
473473 #[ unstable( feature = "f128" , issue = "116909" ) ]
474- pub fn is_sign_positive ( self ) -> bool {
474+ pub const fn is_sign_positive ( self ) -> bool {
475475 !self . is_sign_negative ( )
476476 }
477477
@@ -497,7 +497,7 @@ impl f128 {
497497 #[ inline]
498498 #[ must_use]
499499 #[ unstable( feature = "f128" , issue = "116909" ) ]
500- pub fn is_sign_negative ( self ) -> bool {
500+ pub const fn is_sign_negative ( self ) -> bool {
501501 // IEEE754 says: isSignMinus(x) is true if and only if x has negative sign. isSignMinus
502502 // applies to zeros and NaNs as well.
503503 // SAFETY: This is just transmuting to get the sign bit, it's fine.
@@ -538,7 +538,7 @@ impl f128 {
538538 #[ inline]
539539 #[ unstable( feature = "f128" , issue = "116909" ) ]
540540 // #[unstable(feature = "float_next_up_down", issue = "91399")]
541- pub fn next_up ( self ) -> Self {
541+ pub const fn next_up ( self ) -> Self {
542542 // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
543543 // denormals to zero. This is in general unsound and unsupported, but here
544544 // we do our best to still produce the correct result on such targets.
@@ -592,7 +592,7 @@ impl f128 {
592592 #[ inline]
593593 #[ unstable( feature = "f128" , issue = "116909" ) ]
594594 // #[unstable(feature = "float_next_up_down", issue = "91399")]
595- pub fn next_down ( self ) -> Self {
595+ pub const fn next_down ( self ) -> Self {
596596 // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing
597597 // denormals to zero. This is in general unsound and unsupported, but here
598598 // we do our best to still produce the correct result on such targets.
@@ -627,8 +627,9 @@ impl f128 {
627627 /// ```
628628 #[ inline]
629629 #[ unstable( feature = "f128" , issue = "116909" ) ]
630+ #[ rustc_const_unstable( feature = "const_float_methods" , issue = "130843" ) ]
630631 #[ 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 {
632633 1.0 / self
633634 }
634635
@@ -647,8 +648,9 @@ impl f128 {
647648 /// ```
648649 #[ inline]
649650 #[ unstable( feature = "f128" , issue = "116909" ) ]
651+ #[ rustc_const_unstable( feature = "const_float_methods" , issue = "130843" ) ]
650652 #[ 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 {
652654 // Use a literal for better precision.
653655 const PIS_IN_180 : f128 = 57.2957795130823208767981548141051703324054724665643215491602_f128 ;
654656 self * PIS_IN_180
@@ -670,8 +672,9 @@ impl f128 {
670672 /// ```
671673 #[ inline]
672674 #[ unstable( feature = "f128" , issue = "116909" ) ]
675+ #[ rustc_const_unstable( feature = "const_float_methods" , issue = "130843" ) ]
673676 #[ 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 {
675678 // Use a literal for better precision.
676679 const RADS_PER_DEG : f128 =
677680 0.0174532925199432957692369076848861271344287188854172545609719_f128 ;
@@ -698,8 +701,9 @@ impl f128 {
698701 /// ```
699702 #[ inline]
700703 #[ unstable( feature = "f128" , issue = "116909" ) ]
704+ #[ rustc_const_unstable( feature = "const_float_methods" , issue = "130843" ) ]
701705 #[ 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 {
703707 intrinsics:: maxnumf128 ( self , other)
704708 }
705709
@@ -723,8 +727,9 @@ impl f128 {
723727 /// ```
724728 #[ inline]
725729 #[ unstable( feature = "f128" , issue = "116909" ) ]
730+ #[ rustc_const_unstable( feature = "const_float_methods" , issue = "130843" ) ]
726731 #[ 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 {
728733 intrinsics:: minnumf128 ( self , other)
729734 }
730735
@@ -757,7 +762,7 @@ impl f128 {
757762 #[ unstable( feature = "f128" , issue = "116909" ) ]
758763 // #[unstable(feature = "float_minimum_maximum", issue = "91079")]
759764 #[ 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 {
761766 if self > other {
762767 self
763768 } else if other > self {
@@ -798,7 +803,7 @@ impl f128 {
798803 #[ unstable( feature = "f128" , issue = "116909" ) ]
799804 // #[unstable(feature = "float_minimum_maximum", issue = "91079")]
800805 #[ 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 {
802807 if self < other {
803808 self
804809 } else if other < self {
@@ -1269,9 +1274,20 @@ impl f128 {
12691274 /// ```
12701275 #[ inline]
12711276 #[ unstable( feature = "f128" , issue = "116909" ) ]
1277+ #[ rustc_const_unstable( feature = "const_float_methods" , issue = "130843" ) ]
12721278 #[ 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) ;
12751291 if self < min {
12761292 self = min;
12771293 }
0 commit comments