Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Add cr_hypot from core-math #322

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions crates/libm-test/src/gen/case_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub struct TestCase<Op: MathOp> {
}

impl<Op: MathOp> TestCase<Op> {
#[expect(dead_code)]
fn append_inputs(v: &mut Vec<Self>, l: &[Op::RustArgs]) {
v.extend(l.iter().copied().map(|input| Self { input, output: None }));
}
Expand Down Expand Up @@ -429,7 +428,18 @@ fn frexpf_cases() -> Vec<TestCase<op::frexpf::Routine>> {
}

fn hypot_cases() -> Vec<TestCase<op::hypot::Routine>> {
vec![]
let mut v = vec![];
TestCase::append_inputs(
&mut v,
&[
// Cases that can overflow exponent if wrapping arithmetic is not used
(hf64!("-0x1.800f800f80100p+1023"), hf64!("0x1.8354835473720p+996")),
(hf64!("0x1.201b201b201c0p+0"), hf64!("0x1.b028b028b02a0p-1")),
(hf64!("-0x1.e538e538e564p+980"), hf64!("-0x1.c4dfc4dfc508p+983")),
(hf64!("-0x1.2f22e4f77aa58p+983"), hf64!("-0x1.44c9f5524c8ccp+980")),
],
);
v
}

fn hypotf_cases() -> Vec<TestCase<op::hypotf::Routine>> {
Expand Down
2 changes: 2 additions & 0 deletions crates/libm-test/src/precision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn default_ulp(ctx: &CheckCtx) -> u32 {

// Operations that aren't required to be exact, but our implementations are.
Bn::Cbrt => 0,
Bn::Hypot if ctx.fn_ident == Id::Hypot => 0,

// Bessel functions have large inaccuracies.
Bn::J0 | Bn::J1 | Bn::Y0 | Bn::Y1 | Bn::Jn | Bn::Yn => 8_000_000,
Expand Down Expand Up @@ -99,6 +100,7 @@ pub fn default_ulp(ctx: &CheckCtx) -> u32 {
Id::Cbrt => ulp = 2,
// FIXME(#401): musl has an incorrect result here.
Id::Fdim => ulp = 2,
Id::Hypot => ulp = 1,
Id::Sincosf => ulp = 500,
Id::Tgamma => ulp = 20,
_ => (),
Expand Down
32 changes: 18 additions & 14 deletions crates/libm-test/src/run_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,6 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 {
domain_iter_count = 100_000;
}

// Larger float types get more iterations.
if t_env.large_float_ty {
domain_iter_count *= 4;
}

// Functions with more arguments get more iterations.
let arg_multiplier = 1 << (t_env.input_count - 1);
domain_iter_count *= arg_multiplier;

// If we will be running tests against MPFR, we don't need to test as much against musl.
// However, there are some platforms where we have to test against musl since MPFR can't be
// built.
Expand All @@ -228,6 +219,24 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 {
}
};

// Larger float types get more iterations.
if t_env.large_float_ty && ctx.gen_kind != GeneratorKind::Extensive {
if ctx.gen_kind == GeneratorKind::Extensive {
total_iterations *= 2;
} else {
total_iterations *= 4;
}
}

// Functions with more arguments get more iterations.
let arg_multiplier = 1 << (t_env.input_count - 1);
total_iterations *= arg_multiplier;

// FMA has a huge domain but is reasonably fast to run, so increase iterations.
if ctx.base_name == BaseName::Fma {
total_iterations *= 4;
}

// Some tests are significantly slower than others and need to be further reduced.
if let Some((_id, _gen, scale)) = EXTEMELY_SLOW_TESTS
.iter()
Expand All @@ -239,11 +248,6 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 {
}
}

// FMA has a huge domain but is reasonably fast to run, so increase iterations.
if ctx.base_name == BaseName::Fma {
total_iterations *= 4;
}

if cfg!(optimizations_enabled) {
// Always run at least 10,000 tests.
total_iterations = total_iterations.max(10_000);
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![cfg_attr(all(intrinsics_enabled, target_family = "wasm"), feature(wasm_numeric_instr))]
#![cfg_attr(f128_enabled, feature(f128))]
#![cfg_attr(f16_enabled, feature(f16))]
#![allow(internal_features)]
#![allow(clippy::assign_op_pattern)]
#![allow(clippy::deprecated_cfg_attr)]
#![allow(clippy::eq_op)]
Expand Down
Loading