2024-06-18 18:27:28 -05:00
|
|
|
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
|
2025-04-26 05:37:52 +00:00
|
|
|
#![cfg(target_has_reliable_f16)]
|
2024-06-18 18:27:28 -05:00
|
|
|
|
2025-06-09 14:17:28 +02:00
|
|
|
use super::{assert_approx_eq, assert_biteq};
|
|
|
|
|
|
2024-08-08 12:06:42 +02:00
|
|
|
/// Tolerance for results on the order of 10.0e-2
|
|
|
|
|
#[allow(unused)]
|
2024-06-27 04:13:25 -05:00
|
|
|
const TOL_N2: f16 = 0.0001;
|
|
|
|
|
|
|
|
|
|
/// Tolerance for results on the order of 10.0e+0
|
2024-08-08 12:06:42 +02:00
|
|
|
#[allow(unused)]
|
2024-06-27 04:13:25 -05:00
|
|
|
const TOL_0: f16 = 0.01;
|
|
|
|
|
|
|
|
|
|
/// Tolerance for results on the order of 10.0e+2
|
2024-08-08 12:06:42 +02:00
|
|
|
#[allow(unused)]
|
2024-06-27 04:13:25 -05:00
|
|
|
const TOL_P2: f16 = 0.5;
|
|
|
|
|
|
|
|
|
|
/// Tolerance for results on the order of 10.0e+4
|
2024-08-08 12:06:42 +02:00
|
|
|
#[allow(unused)]
|
2024-06-27 04:13:25 -05:00
|
|
|
const TOL_P4: f16 = 10.0;
|
2024-03-26 04:02:54 -04:00
|
|
|
|
2025-04-26 05:37:52 +00:00
|
|
|
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
|
|
|
|
|
// the intrinsics.
|
|
|
|
|
|
2024-06-27 04:13:25 -05:00
|
|
|
#[test]
|
2025-05-29 14:15:17 +00:00
|
|
|
#[cfg(any(miri, target_has_reliable_f16_math))]
|
2025-08-15 09:54:22 +02:00
|
|
|
fn test_max_recip() {
|
2024-06-27 04:13:25 -05:00
|
|
|
assert_approx_eq!(f16::MAX.recip(), 1.526624e-5f16, 1e-4);
|
2024-06-18 18:27:28 -05:00
|
|
|
}
|
|
|
|
|
|
2025-03-11 17:16:22 +00:00
|
|
|
#[test]
|
|
|
|
|
fn test_from() {
|
2025-05-29 14:44:32 +00:00
|
|
|
assert_biteq!(f16::from(false), 0.0);
|
|
|
|
|
assert_biteq!(f16::from(true), 1.0);
|
|
|
|
|
assert_biteq!(f16::from(u8::MIN), 0.0);
|
|
|
|
|
assert_biteq!(f16::from(42_u8), 42.0);
|
|
|
|
|
assert_biteq!(f16::from(u8::MAX), 255.0);
|
|
|
|
|
assert_biteq!(f16::from(i8::MIN), -128.0);
|
|
|
|
|
assert_biteq!(f16::from(42_i8), 42.0);
|
|
|
|
|
assert_biteq!(f16::from(i8::MAX), 127.0);
|
2025-03-11 17:16:22 +00:00
|
|
|
}
|