@@ -380,16 +380,18 @@ impl f64 {
380
380
/// assert!(!f.is_nan());
381
381
/// ```
382
382
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
383
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
383
384
#[ inline]
384
- pub fn is_nan ( self ) -> bool {
385
+ pub const fn is_nan ( self ) -> bool {
385
386
self != self
386
387
}
387
388
388
389
// FIXME(#50145): `abs` is publicly unavailable in libcore due to
389
390
// concerns about portability, so this implementation is for
390
391
// private use internally.
391
392
#[ inline]
392
- fn abs_private ( self ) -> f64 {
393
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
394
+ const fn abs_private ( self ) -> f64 {
393
395
f64:: from_bits ( self . to_bits ( ) & 0x7fff_ffff_ffff_ffff )
394
396
}
395
397
@@ -409,8 +411,9 @@ impl f64 {
409
411
/// assert!(neg_inf.is_infinite());
410
412
/// ```
411
413
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
414
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
412
415
#[ inline]
413
- pub fn is_infinite ( self ) -> bool {
416
+ pub const fn is_infinite ( self ) -> bool {
414
417
self . abs_private ( ) == Self :: INFINITY
415
418
}
416
419
@@ -429,8 +432,9 @@ impl f64 {
429
432
/// assert!(!neg_inf.is_finite());
430
433
/// ```
431
434
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
435
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
432
436
#[ inline]
433
- pub fn is_finite ( self ) -> bool {
437
+ pub const fn is_finite ( self ) -> bool {
434
438
// There's no need to handle NaN separately: if self is NaN,
435
439
// the comparison is not true, exactly as desired.
436
440
self . abs_private ( ) < Self :: INFINITY
@@ -456,9 +460,10 @@ impl f64 {
456
460
/// ```
457
461
/// [subnormal]: https://en.wikipedia.org/wiki/Denormal_number
458
462
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
463
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
459
464
#[ inline]
460
- pub fn is_normal ( self ) -> bool {
461
- self . classify ( ) == FpCategory :: Normal
465
+ pub const fn is_normal ( self ) -> bool {
466
+ matches ! ( self . classify( ) , FpCategory :: Normal )
462
467
}
463
468
464
469
/// Returns the floating point category of the number. If only one property
@@ -475,7 +480,8 @@ impl f64 {
475
480
/// assert_eq!(inf.classify(), FpCategory::Infinite);
476
481
/// ```
477
482
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
478
- pub fn classify ( self ) -> FpCategory {
483
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
484
+ pub const fn classify ( self ) -> FpCategory {
479
485
const EXP_MASK : u64 = 0x7ff0000000000000 ;
480
486
const MAN_MASK : u64 = 0x000fffffffffffff ;
481
487
@@ -500,16 +506,18 @@ impl f64 {
500
506
/// assert!(!g.is_sign_positive());
501
507
/// ```
502
508
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
509
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
503
510
#[ inline]
504
- pub fn is_sign_positive ( self ) -> bool {
511
+ pub const fn is_sign_positive ( self ) -> bool {
505
512
!self . is_sign_negative ( )
506
513
}
507
514
508
515
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
516
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
509
517
#[ rustc_deprecated( since = "1.0.0" , reason = "renamed to is_sign_positive" ) ]
510
518
#[ inline]
511
519
#[ doc( hidden) ]
512
- pub fn is_positive ( self ) -> bool {
520
+ pub const fn is_positive ( self ) -> bool {
513
521
self . is_sign_positive ( )
514
522
}
515
523
@@ -524,16 +532,18 @@ impl f64 {
524
532
/// assert!(g.is_sign_negative());
525
533
/// ```
526
534
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
535
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
527
536
#[ inline]
528
- pub fn is_sign_negative ( self ) -> bool {
537
+ pub const fn is_sign_negative ( self ) -> bool {
529
538
self . to_bits ( ) & 0x8000_0000_0000_0000 != 0
530
539
}
531
540
532
541
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
542
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
533
543
#[ rustc_deprecated( since = "1.0.0" , reason = "renamed to is_sign_negative" ) ]
534
544
#[ inline]
535
545
#[ doc( hidden) ]
536
- pub fn is_negative ( self ) -> bool {
546
+ pub const fn is_negative ( self ) -> bool {
537
547
self . is_sign_negative ( )
538
548
}
539
549
@@ -664,8 +674,9 @@ impl f64 {
664
674
///
665
675
/// ```
666
676
#[ stable( feature = "float_bits_conv" , since = "1.20.0" ) ]
677
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
667
678
#[ inline]
668
- pub fn to_bits ( self ) -> u64 {
679
+ pub const fn to_bits ( self ) -> u64 {
669
680
// SAFETY: `u64` is a plain old datatype so we can always transmute to it
670
681
unsafe { mem:: transmute ( self ) }
671
682
}
@@ -707,8 +718,9 @@ impl f64 {
707
718
/// assert_eq!(v, 12.5);
708
719
/// ```
709
720
#[ stable( feature = "float_bits_conv" , since = "1.20.0" ) ]
721
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
710
722
#[ inline]
711
- pub fn from_bits ( v : u64 ) -> Self {
723
+ pub const fn from_bits ( v : u64 ) -> Self {
712
724
// SAFETY: `u64` is a plain old datatype so we can always transmute from it
713
725
// It turns out the safety issues with sNaN were overblown! Hooray!
714
726
unsafe { mem:: transmute ( v) }
@@ -724,8 +736,9 @@ impl f64 {
724
736
/// assert_eq!(bytes, [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
725
737
/// ```
726
738
#[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
739
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
727
740
#[ inline]
728
- pub fn to_be_bytes ( self ) -> [ u8 ; 8 ] {
741
+ pub const fn to_be_bytes ( self ) -> [ u8 ; 8 ] {
729
742
self . to_bits ( ) . to_be_bytes ( )
730
743
}
731
744
@@ -739,8 +752,9 @@ impl f64 {
739
752
/// assert_eq!(bytes, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
740
753
/// ```
741
754
#[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
755
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
742
756
#[ inline]
743
- pub fn to_le_bytes ( self ) -> [ u8 ; 8 ] {
757
+ pub const fn to_le_bytes ( self ) -> [ u8 ; 8 ] {
744
758
self . to_bits ( ) . to_le_bytes ( )
745
759
}
746
760
@@ -767,8 +781,9 @@ impl f64 {
767
781
/// );
768
782
/// ```
769
783
#[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
784
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
770
785
#[ inline]
771
- pub fn to_ne_bytes ( self ) -> [ u8 ; 8 ] {
786
+ pub const fn to_ne_bytes ( self ) -> [ u8 ; 8 ] {
772
787
self . to_bits ( ) . to_ne_bytes ( )
773
788
}
774
789
@@ -781,8 +796,9 @@ impl f64 {
781
796
/// assert_eq!(value, 12.5);
782
797
/// ```
783
798
#[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
799
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
784
800
#[ inline]
785
- pub fn from_be_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
801
+ pub const fn from_be_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
786
802
Self :: from_bits ( u64:: from_be_bytes ( bytes) )
787
803
}
788
804
@@ -795,8 +811,9 @@ impl f64 {
795
811
/// assert_eq!(value, 12.5);
796
812
/// ```
797
813
#[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
814
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
798
815
#[ inline]
799
- pub fn from_le_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
816
+ pub const fn from_le_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
800
817
Self :: from_bits ( u64:: from_le_bytes ( bytes) )
801
818
}
802
819
@@ -820,8 +837,9 @@ impl f64 {
820
837
/// assert_eq!(value, 12.5);
821
838
/// ```
822
839
#[ stable( feature = "float_to_from_bytes" , since = "1.40.0" ) ]
840
+ #[ rustc_const_unstable( feature = "const_float_bits_conv" , issue = "72447" ) ]
823
841
#[ inline]
824
- pub fn from_ne_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
842
+ pub const fn from_ne_bytes ( bytes : [ u8 ; 8 ] ) -> Self {
825
843
Self :: from_bits ( u64:: from_ne_bytes ( bytes) )
826
844
}
827
845
0 commit comments