Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 41 additions & 43 deletions library/std/tests/floats/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,18 +461,16 @@ fn test_recip() {
#[test]
#[cfg(reliable_f16_math)]
fn test_powi() {
// FIXME(llvm19): LLVM misoptimizes `powi.f16`
// <https://github.com/llvm/llvm-project/issues/98665>
// let nan: f16 = f16::NAN;
// let inf: f16 = f16::INFINITY;
// let neg_inf: f16 = f16::NEG_INFINITY;
// assert_eq!(1.0f16.powi(1), 1.0);
// assert_approx_eq!((-3.1f16).powi(2), 9.61, TOL_0);
// assert_approx_eq!(5.9f16.powi(-2), 0.028727, TOL_N2);
// assert_eq!(8.3f16.powi(0), 1.0);
// assert!(nan.powi(2).is_nan());
// assert_eq!(inf.powi(3), inf);
// assert_eq!(neg_inf.powi(2), inf);
let nan: f16 = f16::NAN;
let inf: f16 = f16::INFINITY;
let neg_inf: f16 = f16::NEG_INFINITY;
assert_eq!(1.0f16.powi(1), 1.0);
assert_approx_eq!((-3.1f16).powi(2), 9.61, TOL_0);
assert_approx_eq!(5.9f16.powi(-2), 0.028727, TOL_N2);
assert_eq!(8.3f16.powi(0), 1.0);
assert!(nan.powi(2).is_nan());
assert_eq!(inf.powi(3), inf);
assert_eq!(neg_inf.powi(2), inf);
}

#[test]
Expand Down Expand Up @@ -813,21 +811,21 @@ fn test_clamp_max_is_nan() {
}

#[test]
#[cfg(reliable_f16_math)]
fn test_total_cmp() {
use core::cmp::Ordering;

fn quiet_bit_mask() -> u16 {
1 << (f16::MANTISSA_DIGITS - 2)
}

// FIXME(f16_f128): test subnormals when powf is available
// fn min_subnorm() -> f16 {
// f16::MIN_POSITIVE / f16::powf(2.0, f16::MANTISSA_DIGITS as f16 - 1.0)
// }
fn min_subnorm() -> f16 {
f16::MIN_POSITIVE / f16::powf(2.0, f16::MANTISSA_DIGITS as f16 - 1.0)
}

// fn max_subnorm() -> f16 {
// f16::MIN_POSITIVE - min_subnorm()
// }
fn max_subnorm() -> f16 {
f16::MIN_POSITIVE - min_subnorm()
}

fn q_nan() -> f16 {
f16::from_bits(f16::NAN.to_bits() | quiet_bit_mask())
Expand All @@ -846,12 +844,12 @@ fn test_total_cmp() {
assert_eq!(Ordering::Equal, (-1.5_f16).total_cmp(&-1.5));
assert_eq!(Ordering::Equal, (-0.5_f16).total_cmp(&-0.5));
assert_eq!(Ordering::Equal, (-f16::MIN_POSITIVE).total_cmp(&-f16::MIN_POSITIVE));
// assert_eq!(Ordering::Equal, (-max_subnorm()).total_cmp(&-max_subnorm()));
// assert_eq!(Ordering::Equal, (-min_subnorm()).total_cmp(&-min_subnorm()));
assert_eq!(Ordering::Equal, (-max_subnorm()).total_cmp(&-max_subnorm()));
assert_eq!(Ordering::Equal, (-min_subnorm()).total_cmp(&-min_subnorm()));
assert_eq!(Ordering::Equal, (-0.0_f16).total_cmp(&-0.0));
assert_eq!(Ordering::Equal, 0.0_f16.total_cmp(&0.0));
// assert_eq!(Ordering::Equal, min_subnorm().total_cmp(&min_subnorm()));
// assert_eq!(Ordering::Equal, max_subnorm().total_cmp(&max_subnorm()));
assert_eq!(Ordering::Equal, min_subnorm().total_cmp(&min_subnorm()));
assert_eq!(Ordering::Equal, max_subnorm().total_cmp(&max_subnorm()));
assert_eq!(Ordering::Equal, f16::MIN_POSITIVE.total_cmp(&f16::MIN_POSITIVE));
assert_eq!(Ordering::Equal, 0.5_f16.total_cmp(&0.5));
assert_eq!(Ordering::Equal, 1.0_f16.total_cmp(&1.0));
Expand All @@ -870,13 +868,13 @@ fn test_total_cmp() {
assert_eq!(Ordering::Less, (-1.5_f16).total_cmp(&-1.0));
assert_eq!(Ordering::Less, (-1.0_f16).total_cmp(&-0.5));
assert_eq!(Ordering::Less, (-0.5_f16).total_cmp(&-f16::MIN_POSITIVE));
// assert_eq!(Ordering::Less, (-f16::MIN_POSITIVE).total_cmp(&-max_subnorm()));
// assert_eq!(Ordering::Less, (-max_subnorm()).total_cmp(&-min_subnorm()));
// assert_eq!(Ordering::Less, (-min_subnorm()).total_cmp(&-0.0));
assert_eq!(Ordering::Less, (-f16::MIN_POSITIVE).total_cmp(&-max_subnorm()));
assert_eq!(Ordering::Less, (-max_subnorm()).total_cmp(&-min_subnorm()));
assert_eq!(Ordering::Less, (-min_subnorm()).total_cmp(&-0.0));
assert_eq!(Ordering::Less, (-0.0_f16).total_cmp(&0.0));
// assert_eq!(Ordering::Less, 0.0_f16.total_cmp(&min_subnorm()));
// assert_eq!(Ordering::Less, min_subnorm().total_cmp(&max_subnorm()));
// assert_eq!(Ordering::Less, max_subnorm().total_cmp(&f16::MIN_POSITIVE));
assert_eq!(Ordering::Less, 0.0_f16.total_cmp(&min_subnorm()));
assert_eq!(Ordering::Less, min_subnorm().total_cmp(&max_subnorm()));
assert_eq!(Ordering::Less, max_subnorm().total_cmp(&f16::MIN_POSITIVE));
assert_eq!(Ordering::Less, f16::MIN_POSITIVE.total_cmp(&0.5));
assert_eq!(Ordering::Less, 0.5_f16.total_cmp(&1.0));
assert_eq!(Ordering::Less, 1.0_f16.total_cmp(&1.5));
Expand All @@ -894,13 +892,13 @@ fn test_total_cmp() {
assert_eq!(Ordering::Greater, (-1.0_f16).total_cmp(&-1.5));
assert_eq!(Ordering::Greater, (-0.5_f16).total_cmp(&-1.0));
assert_eq!(Ordering::Greater, (-f16::MIN_POSITIVE).total_cmp(&-0.5));
// assert_eq!(Ordering::Greater, (-max_subnorm()).total_cmp(&-f16::MIN_POSITIVE));
// assert_eq!(Ordering::Greater, (-min_subnorm()).total_cmp(&-max_subnorm()));
// assert_eq!(Ordering::Greater, (-0.0_f16).total_cmp(&-min_subnorm()));
assert_eq!(Ordering::Greater, (-max_subnorm()).total_cmp(&-f16::MIN_POSITIVE));
assert_eq!(Ordering::Greater, (-min_subnorm()).total_cmp(&-max_subnorm()));
assert_eq!(Ordering::Greater, (-0.0_f16).total_cmp(&-min_subnorm()));
assert_eq!(Ordering::Greater, 0.0_f16.total_cmp(&-0.0));
// assert_eq!(Ordering::Greater, min_subnorm().total_cmp(&0.0));
// assert_eq!(Ordering::Greater, max_subnorm().total_cmp(&min_subnorm()));
// assert_eq!(Ordering::Greater, f16::MIN_POSITIVE.total_cmp(&max_subnorm()));
assert_eq!(Ordering::Greater, min_subnorm().total_cmp(&0.0));
assert_eq!(Ordering::Greater, max_subnorm().total_cmp(&min_subnorm()));
assert_eq!(Ordering::Greater, f16::MIN_POSITIVE.total_cmp(&max_subnorm()));
assert_eq!(Ordering::Greater, 0.5_f16.total_cmp(&f16::MIN_POSITIVE));
assert_eq!(Ordering::Greater, 1.0_f16.total_cmp(&0.5));
assert_eq!(Ordering::Greater, 1.5_f16.total_cmp(&1.0));
Expand All @@ -918,12 +916,12 @@ fn test_total_cmp() {
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-1.0));
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-0.5));
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-f16::MIN_POSITIVE));
// assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-max_subnorm()));
// assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-min_subnorm()));
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-max_subnorm()));
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-min_subnorm()));
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-0.0));
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&0.0));
// assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&min_subnorm()));
// assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&max_subnorm()));
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&min_subnorm()));
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&max_subnorm()));
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&f16::MIN_POSITIVE));
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&0.5));
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&1.0));
Expand All @@ -940,12 +938,12 @@ fn test_total_cmp() {
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-1.0));
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-0.5));
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-f16::MIN_POSITIVE));
// assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-max_subnorm()));
// assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-min_subnorm()));
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-max_subnorm()));
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-min_subnorm()));
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&-0.0));
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&0.0));
// assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&min_subnorm()));
// assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&max_subnorm()));
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&min_subnorm()));
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&max_subnorm()));
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&f16::MIN_POSITIVE));
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&0.5));
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&1.0));
Expand Down
Loading