Implement tests for floattidf and floattisf

This commit is contained in:
est31 2017-05-06 05:20:20 +02:00
parent 9e7b61cb10
commit f9b5297ccc
3 changed files with 151 additions and 1 deletions

136
build.rs
View File

@ -49,7 +49,7 @@ mod tests {
use std::path::PathBuf; use std::path::PathBuf;
use std::{env, mem}; use std::{env, mem};
use self::cast::{f32, f64, u32, u64, i32, i64}; use self::cast::{f32, f64, u32, u64, u128, i32, i64, i128};
use self::rand::Rng; use self::rand::Rng;
const NTESTS: usize = 10_000; const NTESTS: usize = 10_000;
@ -81,6 +81,8 @@ mod tests {
Floatdidf, Floatdidf,
Floatsidf, Floatsidf,
Floatsisf, Floatsisf,
Floattisf,
Floattidf,
Floatundidf, Floatundidf,
Floatunsidf, Floatunsidf,
Floatunsisf, Floatunsisf,
@ -1536,6 +1538,138 @@ fn floatsisf() {
} }
} }
#[derive(Eq, Hash, PartialEq)]
pub struct Floattisf {
a: i128,
b: u32, // f32
}
impl TestCase for Floattisf {
fn name() -> &'static str {
"floattisf"
}
fn generate<R>(rng: &mut R) -> Option<Self>
where
R: Rng,
Self: Sized,
{
let a = gen_i128(rng);
Some(
Floattisf {
a,
b: to_u32(f32(a)),
},
)
}
fn to_string(&self, buffer: &mut String) {
writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
}
fn prologue() -> &'static str {
r#"
#[cfg(all(target_arch = "arm",
not(any(target_env = "gnu", target_env = "musl")),
target_os = "linux",
test))]
use core::mem;
#[cfg(not(all(target_arch = "arm",
not(any(target_env = "gnu", target_env = "musl")),
target_os = "linux",
test)))]
use std::mem;
use compiler_builtins::float::conv::__floattisf;
fn to_u32(x: f32) -> u32 {
unsafe { mem::transmute(x) }
}
static TEST_CASES: &[((i128,), u32)] = &[
"#
}
fn epilogue() -> &'static str {
"
];
#[test]
fn floattisf() {
for &((a,), b) in TEST_CASES {
let b_ = __floattisf(a);
assert_eq!(((a,), b), ((a,), to_u32(b_)));
}
}
"
}
}
#[derive(Eq, Hash, PartialEq)]
pub struct Floattidf {
a: i128,
b: u64, // f64
}
impl TestCase for Floattidf {
fn name() -> &'static str {
"floattidf"
}
fn generate<R>(rng: &mut R) -> Option<Self>
where
R: Rng,
Self: Sized,
{
let a = gen_i128(rng);
Some(
Floattidf {
a,
b: to_u64(f64(a)),
},
)
}
fn to_string(&self, buffer: &mut String) {
writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
}
fn prologue() -> &'static str {
r#"
#[cfg(all(target_arch = "arm",
not(any(target_env = "gnu", target_env = "musl")),
target_os = "linux",
test))]
use core::mem;
#[cfg(not(all(target_arch = "arm",
not(any(target_env = "gnu", target_env = "musl")),
target_os = "linux",
test)))]
use std::mem;
use compiler_builtins::float::conv::__floattidf;
fn to_u64(x: f64) -> u64 {
unsafe { mem::transmute(x) }
}
static TEST_CASES: &[((i128,), u64)] = &[
"#
}
fn epilogue() -> &'static str {
"
];
#[test]
fn floattidf() {
for &((a,), b) in TEST_CASES {
let b_ = __floattidf(a);
assert_eq!(((a,), b), ((a,), to_u64(b_)));
}
}
"
}
}
#[derive(Eq, Hash, PartialEq)] #[derive(Eq, Hash, PartialEq)]
pub struct Floatundidf { pub struct Floatundidf {
a: u64, a: u64,

8
tests/floattidf.rs Normal file
View File

@ -0,0 +1,8 @@
#![feature(compiler_builtins_lib)]
#![feature(i128_type)]
#![cfg_attr(all(target_arch = "arm",
not(any(target_env = "gnu", target_env = "musl")),
target_os = "linux",
test), no_std)]
include!(concat!(env!("OUT_DIR"), "/floattidf.rs"));

8
tests/floattisf.rs Normal file
View File

@ -0,0 +1,8 @@
#![feature(compiler_builtins_lib)]
#![feature(i128_type)]
#![cfg_attr(all(target_arch = "arm",
not(any(target_env = "gnu", target_env = "musl")),
target_os = "linux",
test), no_std)]
include!(concat!(env!("OUT_DIR"), "/floattisf.rs"));