Skip to content

Commit

Permalink
Check with sin
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Oct 29, 2024
1 parent b3527c9 commit 6838d3b
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 7 deletions.
15 changes: 10 additions & 5 deletions crates/libm-test/src/gen/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Does the following:

use std::ops::{Bound, RangeBounds};

use crate::Float;
use crate::domain::{self, Domain};
use crate::{CheckCtx, Float};

/// Number of values near an interesting point to check.
const AROUND: usize = 100;
Expand Down Expand Up @@ -138,9 +138,14 @@ fn count_down<F: Float>(mut x: F) -> impl Iterator<Item = F> {
})
}

#[test]
fn foobarbaz() {
let values = near_bounds::<f32, domain::sin::D>();
// #[test]
// fn foobarbaz() {
// let values = near_bounds::<f32, domain::sin::D>();

panic!("{}", values.len());
// panic!("{}", values.len());
// }

/// Create a test case iterator.
pub fn get_test_cases<F: Float, D: Domain<F>>(ctx: &CheckCtx) -> impl Iterator<Item = (F,)> {
near_bounds::<F, D>().into_iter().map(|v| (v,))
}
2 changes: 1 addition & 1 deletion crates/libm-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod domain;
pub mod domain;
pub mod gen;
#[cfg(feature = "test-multiprecision")]
pub mod mpfloat;
Expand Down
83 changes: 82 additions & 1 deletion crates/libm-test/tests/multiprecision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#![cfg(feature = "test-multiprecision")]

use libm_test::gen::random;
use libm_test::gen::{domain, random};
use libm_test::mpfloat::{self, MpOp};
use libm_test::{CheckBasis, CheckCtx, CheckOutput, TupleCall, multiprec_allowed_ulp};

Expand Down Expand Up @@ -69,3 +69,84 @@ libm_macros::for_each_function! {
nextafterf,
],
}

// macro_rules! multiprec_domain_tests {
// (
// fn_name: $fn_name:ident,
// CFn: $CFn:ty,
// CArgs: $CArgs:ty,
// CRet: $CRet:ty,
// RustFn: $RustFn:ty,
// RustArgs: $RustArgs:ty,
// RustRet: $RustRet:ty,
// attrs: [$($meta:meta)*]
// ) => {
// paste::paste! {
// #[test]
// $(#[$meta])*
// fn [< multiprec_domain_ $fn_name >]() {
// type MpOpTy = mpfloat::$fn_name::Operation;

// let fname = stringify!($fn_name);
// let ulp = multiprec_allowed_ulp(fname);
// let mut mp_vals = MpOpTy::new();
// let ctx = CheckCtx::new(ulp, fname, CheckBasis::Mpfr);
// let cases = domain::get_test_cases::<$RustArgs>(&ctx);

// for input in cases {
// let mp_res = mp_vals.run(input);
// let crate_res = input.call(libm::$fn_name as $RustFn);

// crate_res.validate(mp_res, input, &ctx).unwrap();
// }
// }
// }
// };
// }

// libm_macros::for_each_function! {
// callback: multiprec_domain_tests,
// attributes: [
// // Also an assertion failure on i686: at `MPFR_ASSERTN (! mpfr_erangeflag_p ())`
// #[ignore = "large values are infeasible in MPFR"]
// [jn, jnf],
// ],
// skip: [
// // FIXME: MPFR tests needed
// frexp,
// frexpf,
// ilogb,
// ilogbf,
// ldexp,
// ldexpf,
// modf,
// modff,
// remquo,
// remquof,
// scalbn,
// scalbnf,

// // FIXME: test needed, see
// // https://github.com/rust-lang/libm/pull/311#discussion_r1818273392
// nextafter,
// nextafterf,
// ],
// }

#[test]
fn multiprec_domain_sin() {
type MpOpTy = mpfloat::sin::Operation;

let fname = "sin";
let ulp = multiprec_allowed_ulp(fname);
let mut mp_vals = MpOpTy::new();
let ctx = CheckCtx::new(ulp, fname, CheckBasis::Mpfr);
let cases = domain::get_test_cases::<f64, libm_test::domain::sin::D>(&ctx);

for input in cases {
let mp_res = mp_vals.run(input);
let crate_res = input.call(libm::sin as fn(f64) -> f64);

crate_res.validate(mp_res, input, &ctx).unwrap();
}
}

0 comments on commit 6838d3b

Please sign in to comment.