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

Commit 8817dee

Browse files
committed
fix overflow
1 parent 43b648b commit 8817dee

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,16 @@ fn frexpf_cases() -> Vec<TestCase<op::frexpf::Routine>> {
429429
}
430430

431431
fn hypot_cases() -> Vec<TestCase<op::hypot::Routine>> {
432-
vec![]
432+
let mut v = vec![];
433+
TestCase::append_pairs(
434+
&mut v,
435+
&[(
436+
// Case that can overflow exponent if wrapping arithmetic is not used
437+
(hf64!("-0x1.800f800f80100p+1023"), hf64!("0x1.8354835473720p+996")),
438+
Some(hf64!("0x1.800f800f80100p+1023")),
439+
)],
440+
);
441+
v
433442
}
434443

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

src/math/hypot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn cr_hypot(mut x: f64, mut y: f64) -> f64 {
118118
ex = thd;
119119
ey = tld;
120120
ex &= 0x7ff_u64 << 52;
121-
let aidr: u64 = ey + (0x3fe_u64 << 52) - ex;
121+
let aidr: u64 = ey.wrapping_add(0x3fe_u64 << 52).wrapping_sub(ex);
122122
let mid: u64 = (aidr.wrapping_sub(0x3c90000000000000) + 16) >> 5;
123123
if mid == 0 || !(0x39b0000000000000_u64..=0x3c9fffffffffff80_u64).contains(&aidr) {
124124
cold_path();

0 commit comments

Comments
 (0)