@@ -381,16 +381,18 @@ impl f32 {
381
381
/// assert!(!f.is_nan());
382
382
/// ```
383
383
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
384
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
384
385
#[ inline]
385
- pub fn is_nan ( self ) -> bool {
386
+ pub const fn is_nan ( self ) -> bool {
386
387
self != self
387
388
}
388
389
389
390
// FIXME(#50145): `abs` is publicly unavailable in libcore due to
390
391
// concerns about portability, so this implementation is for
391
392
// private use internally.
392
393
#[ inline]
393
- fn abs_private ( self ) -> f32 {
394
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
395
+ const fn abs_private ( self ) -> f32 {
394
396
f32:: from_bits ( self . to_bits ( ) & 0x7fff_ffff )
395
397
}
396
398
@@ -410,8 +412,9 @@ impl f32 {
410
412
/// assert!(neg_inf.is_infinite());
411
413
/// ```
412
414
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
415
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
413
416
#[ inline]
414
- pub fn is_infinite ( self ) -> bool {
417
+ pub const fn is_infinite ( self ) -> bool {
415
418
self . abs_private ( ) == Self :: INFINITY
416
419
}
417
420
@@ -430,8 +433,9 @@ impl f32 {
430
433
/// assert!(!neg_inf.is_finite());
431
434
/// ```
432
435
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
436
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
433
437
#[ inline]
434
- pub fn is_finite ( self ) -> bool {
438
+ pub const fn is_finite ( self ) -> bool {
435
439
// There's no need to handle NaN separately: if self is NaN,
436
440
// the comparison is not true, exactly as desired.
437
441
self . abs_private ( ) < Self :: INFINITY
@@ -457,9 +461,10 @@ impl f32 {
457
461
/// ```
458
462
/// [subnormal]: https://en.wikipedia.org/wiki/Denormal_number
459
463
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
464
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
460
465
#[ inline]
461
- pub fn is_normal ( self ) -> bool {
462
- self . classify ( ) == FpCategory :: Normal
466
+ pub const fn is_normal ( self ) -> bool {
467
+ matches ! ( self . classify( ) , FpCategory :: Normal )
463
468
}
464
469
465
470
/// Returns the floating point category of the number. If only one property
@@ -476,7 +481,8 @@ impl f32 {
476
481
/// assert_eq!(inf.classify(), FpCategory::Infinite);
477
482
/// ```
478
483
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
479
- pub fn classify ( self ) -> FpCategory {
484
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
485
+ pub const fn classify ( self ) -> FpCategory {
480
486
const EXP_MASK : u32 = 0x7f800000 ;
481
487
const MAN_MASK : u32 = 0x007fffff ;
482
488
@@ -501,8 +507,9 @@ impl f32 {
501
507
/// assert!(!g.is_sign_positive());
502
508
/// ```
503
509
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
510
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
504
511
#[ inline]
505
- pub fn is_sign_positive ( self ) -> bool {
512
+ pub const fn is_sign_positive ( self ) -> bool {
506
513
!self . is_sign_negative ( )
507
514
}
508
515
@@ -517,8 +524,9 @@ impl f32 {
517
524
/// assert!(g.is_sign_negative());
518
525
/// ```
519
526
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
527
+ #[ rustc_const_unstable( feature = "const_float_classify" , issue = "72505" ) ]
520
528
#[ inline]
521
- pub fn is_sign_negative ( self ) -> bool {
529
+ pub const fn is_sign_negative ( self ) -> bool {
522
530
// IEEE754 says: isSignMinus(x) is true if and only if x has negative sign. isSignMinus
523
531
// applies to zeros and NaNs as well.
524
532
self . to_bits ( ) & 0x8000_0000 != 0
0 commit comments