Skip to content

Commit

Permalink
Add way more rounds for f16
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Jan 25, 2025
1 parent 946f6ec commit 9d32668
Showing 1 changed file with 73 additions and 2 deletions.
75 changes: 73 additions & 2 deletions src/math/generic/scalbn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,27 @@ where
if n > exp_max {
x *= f_exp_max;
n -= exp_max;
if n > exp_max {

if F::BITS < 32 && n > exp_max {
x *= f_exp_max;
n -= exp_max;

if n > exp_max {
x *= f_exp_max;
n -= exp_max;
if n > exp_max {
x *= f_exp_max;
n -= exp_max;
if n > exp_max {
x *= f_exp_max;
n -= exp_max;
if n > exp_max {
n = exp_max;
}
}
}
}
} else if n > exp_max {
n = exp_max;
}
}
Expand All @@ -59,7 +79,46 @@ where
if n < exp_min {
x *= mul;
n += add;
if n < exp_min {
if F::BITS < 32 {
if n < exp_min {
x *= mul;
n += add;

if n < exp_min {
x *= mul;
n += add;

if n < exp_min {
x *= mul;
n += add;

if n < exp_min {
x *= mul;
n += add;

if n < exp_min {
x *= mul;
n += add;

if n < exp_min {
x *= mul;
n += add;

if n < exp_min {
x *= mul;
n += add;

if n < exp_min {
n = exp_min;
}
}
}
}
}
}
}
}
} else if n < exp_min {
n = exp_min;
}
}
Expand Down Expand Up @@ -111,6 +170,12 @@ mod tests {
assert!(scalbn(-F::NAN, -10).is_nan());
}

#[test]
#[cfg(f16_enabled)]
fn spec_test_f16() {
spec_test::<f16>();
}

#[test]
fn spec_test_f32() {
spec_test::<f32>();
Expand All @@ -120,4 +185,10 @@ mod tests {
fn spec_test_f64() {
spec_test::<f64>();
}

#[test]
#[cfg(f128_enabled)]
fn spec_test_f128() {
spec_test::<f128>();
}
}

0 comments on commit 9d32668

Please sign in to comment.