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

Commit 5da2c93

Browse files
committed
Add cr_hypot from core-math
1 parent a1950c7 commit 5da2c93

File tree

5 files changed

+328
-75
lines changed

5 files changed

+328
-75
lines changed

crates/libm-test/src/gen/case_list.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub struct TestCase<Op: MathOp> {
1818
}
1919

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

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

435445
fn hypotf_cases() -> Vec<TestCase<op::hypotf::Routine>> {

crates/libm-test/src/precision.rs

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub fn default_ulp(ctx: &CheckCtx) -> u32 {
4747

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

5152
// Bessel functions have large inaccuracies.
5253
Bn::J0 | Bn::J1 | Bn::Y0 | Bn::Y1 | Bn::Jn | Bn::Yn => 8_000_000,
@@ -99,6 +100,7 @@ pub fn default_ulp(ctx: &CheckCtx) -> u32 {
99100
Id::Cbrt => ulp = 2,
100101
// FIXME(#401): musl has an incorrect result here.
101102
Id::Fdim => ulp = 2,
103+
Id::Hypot => ulp = 1,
102104
Id::Sincosf => ulp = 500,
103105
Id::Tgamma => ulp = 20,
104106
_ => (),

crates/libm-test/src/run_cfg.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,6 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 {
200200
domain_iter_count = 100_000;
201201
}
202202

203-
// Larger float types get more iterations.
204-
if t_env.large_float_ty {
205-
domain_iter_count *= 4;
206-
}
207-
208-
// Functions with more arguments get more iterations.
209-
let arg_multiplier = 1 << (t_env.input_count - 1);
210-
domain_iter_count *= arg_multiplier;
211-
212203
// If we will be running tests against MPFR, we don't need to test as much against musl.
213204
// However, there are some platforms where we have to test against musl since MPFR can't be
214205
// built.
@@ -228,6 +219,24 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 {
228219
}
229220
};
230221

222+
// Larger float types get more iterations.
223+
if t_env.large_float_ty && ctx.gen_kind != GeneratorKind::Extensive {
224+
if ctx.gen_kind == GeneratorKind::Extensive {
225+
total_iterations *= 2;
226+
} else {
227+
total_iterations *= 4;
228+
}
229+
}
230+
231+
// Functions with more arguments get more iterations.
232+
let arg_multiplier = 1 << (t_env.input_count - 1);
233+
total_iterations *= arg_multiplier;
234+
235+
// FMA has a huge domain but is reasonably fast to run, so increase iterations.
236+
if ctx.base_name == BaseName::Fma {
237+
total_iterations *= 4;
238+
}
239+
231240
// Some tests are significantly slower than others and need to be further reduced.
232241
if let Some((_id, _gen, scale)) = EXTEMELY_SLOW_TESTS
233242
.iter()
@@ -239,11 +248,6 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 {
239248
}
240249
}
241250

242-
// FMA has a huge domain but is reasonably fast to run, so increase iterations.
243-
if ctx.base_name == BaseName::Fma {
244-
total_iterations *= 4;
245-
}
246-
247251
if cfg!(optimizations_enabled) {
248252
// Always run at least 10,000 tests.
249253
total_iterations = total_iterations.max(10_000);

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![cfg_attr(all(intrinsics_enabled, target_family = "wasm"), feature(wasm_numeric_instr))]
66
#![cfg_attr(f128_enabled, feature(f128))]
77
#![cfg_attr(f16_enabled, feature(f16))]
8+
#![allow(internal_features)]
89
#![allow(clippy::assign_op_pattern)]
910
#![allow(clippy::deprecated_cfg_attr)]
1011
#![allow(clippy::eq_op)]

0 commit comments

Comments
 (0)