Skip to content

Commit 306764b

Browse files
committed
Fix issue extending f32::MIN/MAX to f64 and improve testcrate.
I was able to trigger an issue extending f32::MAX or f32::MIN to a f64. Issue was not triggered by `testcrate` mainly because f32::MAX/MIN are not in the list of special values to generate. This PR fix the issue and improve `testcrate` adding MAX/MIN/MIN_POSITIVE in the list of special values.
1 parent 2801c99 commit 306764b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/float/extend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn extend<F: Float, R: Float>(a: F) -> R where
4141
let abs_dst: R::Int = a_abs.cast();
4242
let bias_dst: R::Int = exp_bias_delta.cast();
4343
abs_result = abs_dst.wrapping_shl(sign_bits_delta);
44-
abs_result |= bias_dst.wrapping_shl(dst_sign_bits);
44+
abs_result += bias_dst.wrapping_shl(dst_sign_bits);
4545
} else if a_abs >= src_infinity {
4646
// a is NaN or infinity.
4747
// Conjure the result by beginning with infinity, then setting the qNaN

testcrate/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,9 @@ macro_rules! gen_float {
703703
// Special values
704704
*rng.choose(&[-0.0,
705705
0.0,
706+
::std::$fty::MIN,
707+
::std::$fty::MIN_POSITIVE,
708+
::std::$fty::MAX,
706709
::std::$fty::NAN,
707710
::std::$fty::INFINITY,
708711
-::std::$fty::INFINITY])
@@ -754,6 +757,9 @@ macro_rules! gen_large_float {
754757
// Special values
755758
*rng.choose(&[-0.0,
756759
0.0,
760+
::std::$fty::MIN,
761+
::std::$fty::MIN_POSITIVE,
762+
::std::$fty::MAX,
757763
::std::$fty::NAN,
758764
::std::$fty::INFINITY,
759765
-::std::$fty::INFINITY])

0 commit comments

Comments
 (0)