Consolidate classify tests
This commit is contained in:
parent
d2c1900086
commit
79769f2d5b
5 changed files with 23 additions and 71 deletions
|
|
@ -2,7 +2,6 @@
|
|||
#![cfg(target_has_reliable_f128)]
|
||||
|
||||
use std::f128::consts;
|
||||
use std::num::FpCategory as Fp;
|
||||
|
||||
use super::{assert_approx_eq, assert_biteq};
|
||||
|
||||
|
|
@ -40,23 +39,6 @@ const NAN_MASK2: u128 = 0x00005555555555555555555555555555;
|
|||
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
|
||||
// the intrinsics.
|
||||
|
||||
#[test]
|
||||
fn test_classify() {
|
||||
let nan: f128 = f128::NAN;
|
||||
let inf: f128 = f128::INFINITY;
|
||||
let neg_inf: f128 = f128::NEG_INFINITY;
|
||||
let zero: f128 = 0.0f128;
|
||||
let neg_zero: f128 = -0.0;
|
||||
assert_eq!(nan.classify(), Fp::Nan);
|
||||
assert_eq!(inf.classify(), Fp::Infinite);
|
||||
assert_eq!(neg_inf.classify(), Fp::Infinite);
|
||||
assert_eq!(zero.classify(), Fp::Zero);
|
||||
assert_eq!(neg_zero.classify(), Fp::Zero);
|
||||
assert_eq!(1f128.classify(), Fp::Normal);
|
||||
assert_eq!(1e-4931f128.classify(), Fp::Normal);
|
||||
assert_eq!(1e-4932f128.classify(), Fp::Subnormal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(miri, target_has_reliable_f128_math))]
|
||||
fn test_abs() {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
#![cfg(target_has_reliable_f16)]
|
||||
|
||||
use std::f16::consts;
|
||||
use std::num::FpCategory as Fp;
|
||||
|
||||
use super::{assert_approx_eq, assert_biteq};
|
||||
|
||||
|
|
@ -46,23 +45,6 @@ const NAN_MASK2: u16 = 0x0155;
|
|||
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
|
||||
// the intrinsics.
|
||||
|
||||
#[test]
|
||||
fn test_classify() {
|
||||
let nan: f16 = f16::NAN;
|
||||
let inf: f16 = f16::INFINITY;
|
||||
let neg_inf: f16 = f16::NEG_INFINITY;
|
||||
let zero: f16 = 0.0f16;
|
||||
let neg_zero: f16 = -0.0;
|
||||
assert_eq!(nan.classify(), Fp::Nan);
|
||||
assert_eq!(inf.classify(), Fp::Infinite);
|
||||
assert_eq!(neg_inf.classify(), Fp::Infinite);
|
||||
assert_eq!(zero.classify(), Fp::Zero);
|
||||
assert_eq!(neg_zero.classify(), Fp::Zero);
|
||||
assert_eq!(1f16.classify(), Fp::Normal);
|
||||
assert_eq!(1e-4f16.classify(), Fp::Normal);
|
||||
assert_eq!(1e-5f16.classify(), Fp::Subnormal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(miri, target_has_reliable_f16_math))]
|
||||
fn test_abs() {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use core::f32;
|
||||
use core::f32::consts;
|
||||
use core::num::FpCategory as Fp;
|
||||
|
||||
use super::{assert_approx_eq, assert_biteq};
|
||||
|
||||
|
|
@ -30,23 +29,6 @@ const NAN_MASK2: u32 = 0x0055_5555;
|
|||
/// They serve as a way to get an idea of the real precision of floating point operations on different platforms.
|
||||
const APPROX_DELTA: f32 = if cfg!(miri) { 1e-4 } else { 1e-6 };
|
||||
|
||||
#[test]
|
||||
fn test_classify() {
|
||||
let nan: f32 = f32::NAN;
|
||||
let inf: f32 = f32::INFINITY;
|
||||
let neg_inf: f32 = f32::NEG_INFINITY;
|
||||
let zero: f32 = 0.0f32;
|
||||
let neg_zero: f32 = -0.0;
|
||||
assert_eq!(nan.classify(), Fp::Nan);
|
||||
assert_eq!(inf.classify(), Fp::Infinite);
|
||||
assert_eq!(neg_inf.classify(), Fp::Infinite);
|
||||
assert_eq!(zero.classify(), Fp::Zero);
|
||||
assert_eq!(neg_zero.classify(), Fp::Zero);
|
||||
assert_eq!(1f32.classify(), Fp::Normal);
|
||||
assert_eq!(1e-37f32.classify(), Fp::Normal);
|
||||
assert_eq!(1e-38f32.classify(), Fp::Subnormal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_abs() {
|
||||
assert_biteq!(f32::INFINITY.abs(), f32::INFINITY);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use core::f64;
|
||||
use core::f64::consts;
|
||||
use core::num::FpCategory as Fp;
|
||||
|
||||
use super::{assert_approx_eq, assert_biteq};
|
||||
|
||||
|
|
@ -25,22 +24,6 @@ const NAN_MASK1: u64 = 0x000a_aaaa_aaaa_aaaa;
|
|||
/// Second pattern over the mantissa
|
||||
const NAN_MASK2: u64 = 0x0005_5555_5555_5555;
|
||||
|
||||
#[test]
|
||||
fn test_classify() {
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
let zero: f64 = 0.0f64;
|
||||
let neg_zero: f64 = -0.0;
|
||||
assert_eq!(nan.classify(), Fp::Nan);
|
||||
assert_eq!(inf.classify(), Fp::Infinite);
|
||||
assert_eq!(neg_inf.classify(), Fp::Infinite);
|
||||
assert_eq!(zero.classify(), Fp::Zero);
|
||||
assert_eq!(neg_zero.classify(), Fp::Zero);
|
||||
assert_eq!(1e-307f64.classify(), Fp::Normal);
|
||||
assert_eq!(1e-308f64.classify(), Fp::Subnormal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_abs() {
|
||||
assert_biteq!(f64::INFINITY.abs(), f64::INFINITY);
|
||||
|
|
|
|||
|
|
@ -483,6 +483,29 @@ float_test! {
|
|||
}
|
||||
}
|
||||
|
||||
float_test! {
|
||||
name: classify,
|
||||
attrs: {
|
||||
f16: #[cfg(any(miri, target_has_reliable_f16))],
|
||||
},
|
||||
test<Float> {
|
||||
let nan: Float = Float::NAN;
|
||||
let inf: Float = Float::INFINITY;
|
||||
let neg_inf: Float = Float::NEG_INFINITY;
|
||||
let zero: Float = 0.0;
|
||||
let neg_zero: Float = -0.0;
|
||||
let one: Float = 1.0;
|
||||
assert!(matches!(nan.classify(), Fp::Nan));
|
||||
assert!(matches!(inf.classify(), Fp::Infinite));
|
||||
assert!(matches!(neg_inf.classify(), Fp::Infinite));
|
||||
assert!(matches!(zero.classify(), Fp::Zero));
|
||||
assert!(matches!(neg_zero.classify(), Fp::Zero));
|
||||
assert!(matches!(one.classify(), Fp::Normal));
|
||||
assert!(matches!(Float::MIN_POSITIVE_NORMAL.classify(), Fp::Normal));
|
||||
assert!(matches!(Float::MAX_SUBNORMAL.classify(), Fp::Subnormal));
|
||||
}
|
||||
}
|
||||
|
||||
float_test! {
|
||||
name: min,
|
||||
attrs: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue