@@ -461,18 +461,16 @@ fn test_recip() {
461
461
#[ test]
462
462
#[ cfg( reliable_f16_math) ]
463
463
fn test_powi ( ) {
464
- // FIXME(llvm19): LLVM misoptimizes `powi.f16`
465
- // <https://github.com/llvm/llvm-project/issues/98665>
466
- // let nan: f16 = f16::NAN;
467
- // let inf: f16 = f16::INFINITY;
468
- // let neg_inf: f16 = f16::NEG_INFINITY;
469
- // assert_eq!(1.0f16.powi(1), 1.0);
470
- // assert_approx_eq!((-3.1f16).powi(2), 9.61, TOL_0);
471
- // assert_approx_eq!(5.9f16.powi(-2), 0.028727, TOL_N2);
472
- // assert_eq!(8.3f16.powi(0), 1.0);
473
- // assert!(nan.powi(2).is_nan());
474
- // assert_eq!(inf.powi(3), inf);
475
- // assert_eq!(neg_inf.powi(2), inf);
464
+ let nan: f16 = f16:: NAN ;
465
+ let inf: f16 = f16:: INFINITY ;
466
+ let neg_inf: f16 = f16:: NEG_INFINITY ;
467
+ assert_eq ! ( 1.0f16 . powi( 1 ) , 1.0 ) ;
468
+ assert_approx_eq ! ( ( -3.1f16 ) . powi( 2 ) , 9.61 , TOL_0 ) ;
469
+ assert_approx_eq ! ( 5.9f16 . powi( -2 ) , 0.028727 , TOL_N2 ) ;
470
+ assert_eq ! ( 8.3f16 . powi( 0 ) , 1.0 ) ;
471
+ assert ! ( nan. powi( 2 ) . is_nan( ) ) ;
472
+ assert_eq ! ( inf. powi( 3 ) , inf) ;
473
+ assert_eq ! ( neg_inf. powi( 2 ) , inf) ;
476
474
}
477
475
478
476
#[ test]
@@ -813,21 +811,21 @@ fn test_clamp_max_is_nan() {
813
811
}
814
812
815
813
#[ test]
814
+ #[ cfg( reliable_f16_math) ]
816
815
fn test_total_cmp ( ) {
817
816
use core:: cmp:: Ordering ;
818
817
819
818
fn quiet_bit_mask ( ) -> u16 {
820
819
1 << ( f16:: MANTISSA_DIGITS - 2 )
821
820
}
822
821
823
- // FIXME(f16_f128): test subnormals when powf is available
824
- // fn min_subnorm() -> f16 {
825
- // f16::MIN_POSITIVE / f16::powf(2.0, f16::MANTISSA_DIGITS as f16 - 1.0)
826
- // }
822
+ fn min_subnorm ( ) -> f16 {
823
+ f16:: MIN_POSITIVE / f16:: powf ( 2.0 , f16:: MANTISSA_DIGITS as f16 - 1.0 )
824
+ }
827
825
828
- // fn max_subnorm() -> f16 {
829
- // f16::MIN_POSITIVE - min_subnorm()
830
- // }
826
+ fn max_subnorm ( ) -> f16 {
827
+ f16:: MIN_POSITIVE - min_subnorm ( )
828
+ }
831
829
832
830
fn q_nan ( ) -> f16 {
833
831
f16:: from_bits ( f16:: NAN . to_bits ( ) | quiet_bit_mask ( ) )
@@ -846,12 +844,12 @@ fn test_total_cmp() {
846
844
assert_eq ! ( Ordering :: Equal , ( -1.5_f16 ) . total_cmp( & -1.5 ) ) ;
847
845
assert_eq ! ( Ordering :: Equal , ( -0.5_f16 ) . total_cmp( & -0.5 ) ) ;
848
846
assert_eq ! ( Ordering :: Equal , ( -f16:: MIN_POSITIVE ) . total_cmp( & -f16:: MIN_POSITIVE ) ) ;
849
- // assert_eq!(Ordering::Equal, (-max_subnorm()).total_cmp(&-max_subnorm()));
850
- // assert_eq!(Ordering::Equal, (-min_subnorm()).total_cmp(&-min_subnorm()));
847
+ assert_eq ! ( Ordering :: Equal , ( -max_subnorm( ) ) . total_cmp( & -max_subnorm( ) ) ) ;
848
+ assert_eq ! ( Ordering :: Equal , ( -min_subnorm( ) ) . total_cmp( & -min_subnorm( ) ) ) ;
851
849
assert_eq ! ( Ordering :: Equal , ( -0.0_f16 ) . total_cmp( & -0.0 ) ) ;
852
850
assert_eq ! ( Ordering :: Equal , 0.0_f16 . total_cmp( & 0.0 ) ) ;
853
- // assert_eq!(Ordering::Equal, min_subnorm().total_cmp(&min_subnorm()));
854
- // assert_eq!(Ordering::Equal, max_subnorm().total_cmp(&max_subnorm()));
851
+ assert_eq ! ( Ordering :: Equal , min_subnorm( ) . total_cmp( & min_subnorm( ) ) ) ;
852
+ assert_eq ! ( Ordering :: Equal , max_subnorm( ) . total_cmp( & max_subnorm( ) ) ) ;
855
853
assert_eq ! ( Ordering :: Equal , f16:: MIN_POSITIVE . total_cmp( & f16:: MIN_POSITIVE ) ) ;
856
854
assert_eq ! ( Ordering :: Equal , 0.5_f16 . total_cmp( & 0.5 ) ) ;
857
855
assert_eq ! ( Ordering :: Equal , 1.0_f16 . total_cmp( & 1.0 ) ) ;
@@ -870,13 +868,13 @@ fn test_total_cmp() {
870
868
assert_eq ! ( Ordering :: Less , ( -1.5_f16 ) . total_cmp( & -1.0 ) ) ;
871
869
assert_eq ! ( Ordering :: Less , ( -1.0_f16 ) . total_cmp( & -0.5 ) ) ;
872
870
assert_eq ! ( Ordering :: Less , ( -0.5_f16 ) . total_cmp( & -f16:: MIN_POSITIVE ) ) ;
873
- // assert_eq!(Ordering::Less, (-f16::MIN_POSITIVE).total_cmp(&-max_subnorm()));
874
- // assert_eq!(Ordering::Less, (-max_subnorm()).total_cmp(&-min_subnorm()));
875
- // assert_eq!(Ordering::Less, (-min_subnorm()).total_cmp(&-0.0));
871
+ assert_eq ! ( Ordering :: Less , ( -f16:: MIN_POSITIVE ) . total_cmp( & -max_subnorm( ) ) ) ;
872
+ assert_eq ! ( Ordering :: Less , ( -max_subnorm( ) ) . total_cmp( & -min_subnorm( ) ) ) ;
873
+ assert_eq ! ( Ordering :: Less , ( -min_subnorm( ) ) . total_cmp( & -0.0 ) ) ;
876
874
assert_eq ! ( Ordering :: Less , ( -0.0_f16 ) . total_cmp( & 0.0 ) ) ;
877
- // assert_eq!(Ordering::Less, 0.0_f16.total_cmp(&min_subnorm()));
878
- // assert_eq!(Ordering::Less, min_subnorm().total_cmp(&max_subnorm()));
879
- // assert_eq!(Ordering::Less, max_subnorm().total_cmp(&f16::MIN_POSITIVE));
875
+ assert_eq ! ( Ordering :: Less , 0.0_f16 . total_cmp( & min_subnorm( ) ) ) ;
876
+ assert_eq ! ( Ordering :: Less , min_subnorm( ) . total_cmp( & max_subnorm( ) ) ) ;
877
+ assert_eq ! ( Ordering :: Less , max_subnorm( ) . total_cmp( & f16:: MIN_POSITIVE ) ) ;
880
878
assert_eq ! ( Ordering :: Less , f16:: MIN_POSITIVE . total_cmp( & 0.5 ) ) ;
881
879
assert_eq ! ( Ordering :: Less , 0.5_f16 . total_cmp( & 1.0 ) ) ;
882
880
assert_eq ! ( Ordering :: Less , 1.0_f16 . total_cmp( & 1.5 ) ) ;
@@ -894,13 +892,13 @@ fn test_total_cmp() {
894
892
assert_eq ! ( Ordering :: Greater , ( -1.0_f16 ) . total_cmp( & -1.5 ) ) ;
895
893
assert_eq ! ( Ordering :: Greater , ( -0.5_f16 ) . total_cmp( & -1.0 ) ) ;
896
894
assert_eq ! ( Ordering :: Greater , ( -f16:: MIN_POSITIVE ) . total_cmp( & -0.5 ) ) ;
897
- // assert_eq!(Ordering::Greater, (-max_subnorm()).total_cmp(&-f16::MIN_POSITIVE));
898
- // assert_eq!(Ordering::Greater, (-min_subnorm()).total_cmp(&-max_subnorm()));
899
- // assert_eq!(Ordering::Greater, (-0.0_f16).total_cmp(&-min_subnorm()));
895
+ assert_eq ! ( Ordering :: Greater , ( -max_subnorm( ) ) . total_cmp( & -f16:: MIN_POSITIVE ) ) ;
896
+ assert_eq ! ( Ordering :: Greater , ( -min_subnorm( ) ) . total_cmp( & -max_subnorm( ) ) ) ;
897
+ assert_eq ! ( Ordering :: Greater , ( -0.0_f16 ) . total_cmp( & -min_subnorm( ) ) ) ;
900
898
assert_eq ! ( Ordering :: Greater , 0.0_f16 . total_cmp( & -0.0 ) ) ;
901
- // assert_eq!(Ordering::Greater, min_subnorm().total_cmp(&0.0));
902
- // assert_eq!(Ordering::Greater, max_subnorm().total_cmp(&min_subnorm()));
903
- // assert_eq!(Ordering::Greater, f16::MIN_POSITIVE.total_cmp(&max_subnorm()));
899
+ assert_eq ! ( Ordering :: Greater , min_subnorm( ) . total_cmp( & 0.0 ) ) ;
900
+ assert_eq ! ( Ordering :: Greater , max_subnorm( ) . total_cmp( & min_subnorm( ) ) ) ;
901
+ assert_eq ! ( Ordering :: Greater , f16:: MIN_POSITIVE . total_cmp( & max_subnorm( ) ) ) ;
904
902
assert_eq ! ( Ordering :: Greater , 0.5_f16 . total_cmp( & f16:: MIN_POSITIVE ) ) ;
905
903
assert_eq ! ( Ordering :: Greater , 1.0_f16 . total_cmp( & 0.5 ) ) ;
906
904
assert_eq ! ( Ordering :: Greater , 1.5_f16 . total_cmp( & 1.0 ) ) ;
@@ -918,12 +916,12 @@ fn test_total_cmp() {
918
916
assert_eq ! ( Ordering :: Less , ( -q_nan( ) ) . total_cmp( & -1.0 ) ) ;
919
917
assert_eq ! ( Ordering :: Less , ( -q_nan( ) ) . total_cmp( & -0.5 ) ) ;
920
918
assert_eq ! ( Ordering :: Less , ( -q_nan( ) ) . total_cmp( & -f16:: MIN_POSITIVE ) ) ;
921
- // assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-max_subnorm()));
922
- // assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-min_subnorm()));
919
+ assert_eq ! ( Ordering :: Less , ( -q_nan( ) ) . total_cmp( & -max_subnorm( ) ) ) ;
920
+ assert_eq ! ( Ordering :: Less , ( -q_nan( ) ) . total_cmp( & -min_subnorm( ) ) ) ;
923
921
assert_eq ! ( Ordering :: Less , ( -q_nan( ) ) . total_cmp( & -0.0 ) ) ;
924
922
assert_eq ! ( Ordering :: Less , ( -q_nan( ) ) . total_cmp( & 0.0 ) ) ;
925
- // assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&min_subnorm()));
926
- // assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&max_subnorm()));
923
+ assert_eq ! ( Ordering :: Less , ( -q_nan( ) ) . total_cmp( & min_subnorm( ) ) ) ;
924
+ assert_eq ! ( Ordering :: Less , ( -q_nan( ) ) . total_cmp( & max_subnorm( ) ) ) ;
927
925
assert_eq ! ( Ordering :: Less , ( -q_nan( ) ) . total_cmp( & f16:: MIN_POSITIVE ) ) ;
928
926
assert_eq ! ( Ordering :: Less , ( -q_nan( ) ) . total_cmp( & 0.5 ) ) ;
929
927
assert_eq ! ( Ordering :: Less , ( -q_nan( ) ) . total_cmp( & 1.0 ) ) ;
@@ -940,12 +938,12 @@ fn test_total_cmp() {
940
938
assert_eq ! ( Ordering :: Less , ( -s_nan( ) ) . total_cmp( & -1.0 ) ) ;
941
939
assert_eq ! ( Ordering :: Less , ( -s_nan( ) ) . total_cmp( & -0.5 ) ) ;
942
940
assert_eq ! ( Ordering :: Less , ( -s_nan( ) ) . total_cmp( & -f16:: MIN_POSITIVE ) ) ;
943
- // assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-max_subnorm()));
944
- // assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-min_subnorm()));
941
+ assert_eq ! ( Ordering :: Less , ( -s_nan( ) ) . total_cmp( & -max_subnorm( ) ) ) ;
942
+ assert_eq ! ( Ordering :: Less , ( -s_nan( ) ) . total_cmp( & -min_subnorm( ) ) ) ;
945
943
assert_eq ! ( Ordering :: Less , ( -s_nan( ) ) . total_cmp( & -0.0 ) ) ;
946
944
assert_eq ! ( Ordering :: Less , ( -s_nan( ) ) . total_cmp( & 0.0 ) ) ;
947
- // assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&min_subnorm()));
948
- // assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&max_subnorm()));
945
+ assert_eq ! ( Ordering :: Less , ( -s_nan( ) ) . total_cmp( & min_subnorm( ) ) ) ;
946
+ assert_eq ! ( Ordering :: Less , ( -s_nan( ) ) . total_cmp( & max_subnorm( ) ) ) ;
949
947
assert_eq ! ( Ordering :: Less , ( -s_nan( ) ) . total_cmp( & f16:: MIN_POSITIVE ) ) ;
950
948
assert_eq ! ( Ordering :: Less , ( -s_nan( ) ) . total_cmp( & 0.5 ) ) ;
951
949
assert_eq ! ( Ordering :: Less , ( -s_nan( ) ) . total_cmp( & 1.0 ) ) ;
0 commit comments