From 9d3266824b841b905df466f51bffa78fb2c7489e Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sat, 25 Jan 2025 01:59:31 +0000 Subject: [PATCH] Add way more rounds for `f16` --- src/math/generic/scalbn.rs | 75 +++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/src/math/generic/scalbn.rs b/src/math/generic/scalbn.rs index f036c15c..ce143d4e 100644 --- a/src/math/generic/scalbn.rs +++ b/src/math/generic/scalbn.rs @@ -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; } } @@ -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; } } @@ -111,6 +170,12 @@ mod tests { assert!(scalbn(-F::NAN, -10).is_nan()); } + #[test] + #[cfg(f16_enabled)] + fn spec_test_f16() { + spec_test::(); + } + #[test] fn spec_test_f32() { spec_test::(); @@ -120,4 +185,10 @@ mod tests { fn spec_test_f64() { spec_test::(); } + + #[test] + #[cfg(f128_enabled)] + fn spec_test_f128() { + spec_test::(); + } }