Re-add float comparison tests

This commit is contained in:
Tony Garnock-Jones 2022-11-04 15:32:27 +01:00
parent 12b027b2d9
commit 259a3c8ead
1 changed files with 91 additions and 0 deletions

View File

@ -23,3 +23,94 @@ pub fn cmp_f64(a: f64, b: f64) -> Ordering {
pub fn eq_f64(a: f64, b: f64) -> bool {
a.to_bits() == b.to_bits()
}
#[cfg(test)]
mod ieee754_section_5_10_total_order_tests {
use std::cmp::Ordering::{Less, Equal, Greater};
use super::*;
// TODO: Test cases with a few different signalling and non-signalling NaNs
#[test] fn case32_a_1() { assert_eq!(cmp_f32(1.0, 2.0), Less) }
#[test] fn case32_a_2() { assert_eq!(cmp_f32(-1.0, 1.0), Less) }
#[test] fn case32_a_3() { assert_eq!(cmp_f32(0.0, 1.0), Less) }
#[test] fn case32_a_4() { assert_eq!(cmp_f32(-1.0, 0.0), Less) }
#[test] fn case32_a_5() { assert_eq!(cmp_f32(-1e32, -1e31), Less) }
#[test] fn case32_a_6() { assert_eq!(cmp_f32(-1e32, 1e33), Less) }
#[test] fn case32_a_7() {
assert_eq!(cmp_f32(std::f32::NEG_INFINITY, std::f32::INFINITY), Less)
}
#[test] fn case32_a_8() { assert_eq!(cmp_f32(std::f32::NEG_INFINITY, 0.0), Less) }
#[test] fn case32_a_9() { assert_eq!(cmp_f32(std::f32::NEG_INFINITY, 1.0), Less) }
#[test] fn case32_a_10() { assert_eq!(cmp_f32(std::f32::NEG_INFINITY, 1e33), Less) }
#[test] fn case32_a_11() { assert_eq!(cmp_f32(0.0, std::f32::INFINITY), Less) }
#[test] fn case32_a_12() { assert_eq!(cmp_f32(1.0, std::f32::INFINITY), Less) }
#[test] fn case32_a_13() { assert_eq!(cmp_f32(1e33, std::f32::INFINITY), Less) }
#[test] fn case32_b_1() { assert_eq!(cmp_f32(2.0, 1.0), Greater) }
#[test] fn case32_b_2() { assert_eq!(cmp_f32(1.0, -1.0), Greater) }
#[test] fn case32_b_3() { assert_eq!(cmp_f32(1.0, 0.0), Greater) }
#[test] fn case32_b_4() { assert_eq!(cmp_f32(0.0, -1.0), Greater) }
#[test] fn case32_b_5() { assert_eq!(cmp_f32(-1e31, -1e32), Greater) }
#[test] fn case32_b_6() { assert_eq!(cmp_f32(1e33, -1e32), Greater) }
#[test] fn case32_b_7() {
assert_eq!(cmp_f32(std::f32::INFINITY, std::f32::NEG_INFINITY), Greater)
}
#[test] fn case32_b_8() { assert_eq!(cmp_f32(std::f32::INFINITY, 0.0), Greater) }
#[test] fn case32_b_9() { assert_eq!(cmp_f32(std::f32::INFINITY, 1.0), Greater) }
#[test] fn case32_b_10() { assert_eq!(cmp_f32(std::f32::INFINITY, 1e33), Greater) }
#[test] fn case32_b_11() { assert_eq!(cmp_f32(0.0, std::f32::NEG_INFINITY), Greater) }
#[test] fn case32_b_12() { assert_eq!(cmp_f32(1.0, std::f32::NEG_INFINITY), Greater) }
#[test] fn case32_b_13() { assert_eq!(cmp_f32(1e33, std::f32::NEG_INFINITY), Greater) }
#[test] fn case32_c1() { assert_eq!(cmp_f32(-0.0, 0.0), Less) }
#[test] fn case32_c2() { assert_eq!(cmp_f32( 0.0, -0.0), Greater) }
#[test] fn case32_c3_1() { assert_eq!(cmp_f32(-0.0, -0.0), Equal) }
#[test] fn case32_c3_2() { assert_eq!(cmp_f32( 0.0, 0.0), Equal) }
#[test] fn case32_c3_3() { assert_eq!(cmp_f32(1.0, 1.0), Equal) }
#[test] fn case32_c3_4() { assert_eq!(cmp_f32(-1.0, -1.0), Equal) }
#[test] fn case32_c3_5() { assert_eq!(cmp_f32(-1e32, -1e32), Equal) }
#[test] fn case32_c3_6() { assert_eq!(cmp_f32(1e33, 1e33), Equal) }
#[test] fn case64_a_1() { assert_eq!(cmp_f64(1.0, 2.0), Less) }
#[test] fn case64_a_2() { assert_eq!(cmp_f64(-1.0, 1.0), Less) }
#[test] fn case64_a_3() { assert_eq!(cmp_f64(0.0, 1.0), Less) }
#[test] fn case64_a_4() { assert_eq!(cmp_f64(-1.0, 0.0), Less) }
#[test] fn case64_a_5() { assert_eq!(cmp_f64(-1e32, -1e31), Less) }
#[test] fn case64_a_6() { assert_eq!(cmp_f64(-1e32, 1e33), Less) }
#[test] fn case64_a_7() {
assert_eq!(cmp_f64(std::f64::NEG_INFINITY, std::f64::INFINITY), Less)
}
#[test] fn case64_a_8() { assert_eq!(cmp_f64(std::f64::NEG_INFINITY, 0.0), Less) }
#[test] fn case64_a_9() { assert_eq!(cmp_f64(std::f64::NEG_INFINITY, 1.0), Less) }
#[test] fn case64_a_10() { assert_eq!(cmp_f64(std::f64::NEG_INFINITY, 1e33), Less) }
#[test] fn case64_a_11() { assert_eq!(cmp_f64(0.0, std::f64::INFINITY), Less) }
#[test] fn case64_a_12() { assert_eq!(cmp_f64(1.0, std::f64::INFINITY), Less) }
#[test] fn case64_a_13() { assert_eq!(cmp_f64(1e33, std::f64::INFINITY), Less) }
#[test] fn case64_b_1() { assert_eq!(cmp_f64(2.0, 1.0), Greater) }
#[test] fn case64_b_2() { assert_eq!(cmp_f64(1.0, -1.0), Greater) }
#[test] fn case64_b_3() { assert_eq!(cmp_f64(1.0, 0.0), Greater) }
#[test] fn case64_b_4() { assert_eq!(cmp_f64(0.0, -1.0), Greater) }
#[test] fn case64_b_5() { assert_eq!(cmp_f64(-1e31, -1e32), Greater) }
#[test] fn case64_b_6() { assert_eq!(cmp_f64(1e33, -1e32), Greater) }
#[test] fn case64_b_7() {
assert_eq!(cmp_f64(std::f64::INFINITY, std::f64::NEG_INFINITY), Greater)
}
#[test] fn case64_b_8() { assert_eq!(cmp_f64(std::f64::INFINITY, 0.0), Greater) }
#[test] fn case64_b_9() { assert_eq!(cmp_f64(std::f64::INFINITY, 1.0), Greater) }
#[test] fn case64_b_10() { assert_eq!(cmp_f64(std::f64::INFINITY, 1e33), Greater) }
#[test] fn case64_b_11() { assert_eq!(cmp_f64(0.0, std::f64::NEG_INFINITY), Greater) }
#[test] fn case64_b_12() { assert_eq!(cmp_f64(1.0, std::f64::NEG_INFINITY), Greater) }
#[test] fn case64_b_13() { assert_eq!(cmp_f64(1e33, std::f64::NEG_INFINITY), Greater) }
#[test] fn case64_c1() { assert_eq!(cmp_f64(-0.0, 0.0), Less) }
#[test] fn case64_c2() { assert_eq!(cmp_f64( 0.0, -0.0), Greater) }
#[test] fn case64_c3_1() { assert_eq!(cmp_f64(-0.0, -0.0), Equal) }
#[test] fn case64_c3_2() { assert_eq!(cmp_f64( 0.0, 0.0), Equal) }
#[test] fn case64_c3_3() { assert_eq!(cmp_f64(1.0, 1.0), Equal) }
#[test] fn case64_c3_4() { assert_eq!(cmp_f64(-1.0, -1.0), Equal) }
#[test] fn case64_c3_5() { assert_eq!(cmp_f64(-1e32, -1e32), Equal) }
#[test] fn case64_c3_6() { assert_eq!(cmp_f64(1e33, 1e33), Equal) }
}