Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5021a82

Browse files
committedMar 11, 2025
Auto merge of #138343 - tgross35:f16-powf, r=<try>
Enable `f16` tests for `powf` The LLVM issue [1] was fixed with [2], which is included in the LLVM20 upgrade. Tests no longer fail, so enable them here. [1]: llvm/llvm-project#98681 [2]: llvm/llvm-project#98681 try-job: aarch64-gnu
2 parents 374ce1f + 1a2e22e commit 5021a82

File tree

1 file changed

+40
-43
lines changed
  • library/std/tests/floats

1 file changed

+40
-43
lines changed
 

‎library/std/tests/floats/f16.rs

+40-43
Original file line numberDiff line numberDiff line change
@@ -461,18 +461,16 @@ fn test_recip() {
461461
#[test]
462462
#[cfg(reliable_f16_math)]
463463
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);
476474
}
477475

478476
#[test]
@@ -820,14 +818,13 @@ fn test_total_cmp() {
820818
1 << (f16::MANTISSA_DIGITS - 2)
821819
}
822820

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-
// }
821+
fn min_subnorm() -> f16 {
822+
f16::MIN_POSITIVE / f16::powf(2.0, f16::MANTISSA_DIGITS as f16 - 1.0)
823+
}
827824

828-
// fn max_subnorm() -> f16 {
829-
// f16::MIN_POSITIVE - min_subnorm()
830-
// }
825+
fn max_subnorm() -> f16 {
826+
f16::MIN_POSITIVE - min_subnorm()
827+
}
831828

832829
fn q_nan() -> f16 {
833830
f16::from_bits(f16::NAN.to_bits() | quiet_bit_mask())
@@ -846,12 +843,12 @@ fn test_total_cmp() {
846843
assert_eq!(Ordering::Equal, (-1.5_f16).total_cmp(&-1.5));
847844
assert_eq!(Ordering::Equal, (-0.5_f16).total_cmp(&-0.5));
848845
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()));
846+
assert_eq!(Ordering::Equal, (-max_subnorm()).total_cmp(&-max_subnorm()));
847+
assert_eq!(Ordering::Equal, (-min_subnorm()).total_cmp(&-min_subnorm()));
851848
assert_eq!(Ordering::Equal, (-0.0_f16).total_cmp(&-0.0));
852849
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()));
850+
assert_eq!(Ordering::Equal, min_subnorm().total_cmp(&min_subnorm()));
851+
assert_eq!(Ordering::Equal, max_subnorm().total_cmp(&max_subnorm()));
855852
assert_eq!(Ordering::Equal, f16::MIN_POSITIVE.total_cmp(&f16::MIN_POSITIVE));
856853
assert_eq!(Ordering::Equal, 0.5_f16.total_cmp(&0.5));
857854
assert_eq!(Ordering::Equal, 1.0_f16.total_cmp(&1.0));
@@ -870,13 +867,13 @@ fn test_total_cmp() {
870867
assert_eq!(Ordering::Less, (-1.5_f16).total_cmp(&-1.0));
871868
assert_eq!(Ordering::Less, (-1.0_f16).total_cmp(&-0.5));
872869
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));
870+
assert_eq!(Ordering::Less, (-f16::MIN_POSITIVE).total_cmp(&-max_subnorm()));
871+
assert_eq!(Ordering::Less, (-max_subnorm()).total_cmp(&-min_subnorm()));
872+
assert_eq!(Ordering::Less, (-min_subnorm()).total_cmp(&-0.0));
876873
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));
874+
assert_eq!(Ordering::Less, 0.0_f16.total_cmp(&min_subnorm()));
875+
assert_eq!(Ordering::Less, min_subnorm().total_cmp(&max_subnorm()));
876+
assert_eq!(Ordering::Less, max_subnorm().total_cmp(&f16::MIN_POSITIVE));
880877
assert_eq!(Ordering::Less, f16::MIN_POSITIVE.total_cmp(&0.5));
881878
assert_eq!(Ordering::Less, 0.5_f16.total_cmp(&1.0));
882879
assert_eq!(Ordering::Less, 1.0_f16.total_cmp(&1.5));
@@ -894,13 +891,13 @@ fn test_total_cmp() {
894891
assert_eq!(Ordering::Greater, (-1.0_f16).total_cmp(&-1.5));
895892
assert_eq!(Ordering::Greater, (-0.5_f16).total_cmp(&-1.0));
896893
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()));
894+
assert_eq!(Ordering::Greater, (-max_subnorm()).total_cmp(&-f16::MIN_POSITIVE));
895+
assert_eq!(Ordering::Greater, (-min_subnorm()).total_cmp(&-max_subnorm()));
896+
assert_eq!(Ordering::Greater, (-0.0_f16).total_cmp(&-min_subnorm()));
900897
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()));
898+
assert_eq!(Ordering::Greater, min_subnorm().total_cmp(&0.0));
899+
assert_eq!(Ordering::Greater, max_subnorm().total_cmp(&min_subnorm()));
900+
assert_eq!(Ordering::Greater, f16::MIN_POSITIVE.total_cmp(&max_subnorm()));
904901
assert_eq!(Ordering::Greater, 0.5_f16.total_cmp(&f16::MIN_POSITIVE));
905902
assert_eq!(Ordering::Greater, 1.0_f16.total_cmp(&0.5));
906903
assert_eq!(Ordering::Greater, 1.5_f16.total_cmp(&1.0));
@@ -918,12 +915,12 @@ fn test_total_cmp() {
918915
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-1.0));
919916
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-0.5));
920917
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()));
918+
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-max_subnorm()));
919+
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-min_subnorm()));
923920
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-0.0));
924921
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()));
922+
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&min_subnorm()));
923+
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&max_subnorm()));
927924
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&f16::MIN_POSITIVE));
928925
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&0.5));
929926
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&1.0));
@@ -940,12 +937,12 @@ fn test_total_cmp() {
940937
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-1.0));
941938
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-0.5));
942939
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()));
940+
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-max_subnorm()));
941+
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-min_subnorm()));
945942
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-0.0));
946943
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()));
944+
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&min_subnorm()));
945+
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&max_subnorm()));
949946
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&f16::MIN_POSITIVE));
950947
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&0.5));
951948
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&1.0));

0 commit comments

Comments
 (0)
Failed to load comments.