Skip to content

Commit 63de7c6

Browse files
committed
Auto merge of #230 - paoloteti:fix-extend, r=alexcrichton
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.
2 parents 2801c99 + 2cb290a commit 63de7c6

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
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

src/float/sub.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
use float::Float;
2+
use float::add::__addsf3;
3+
use float::add::__adddf3;
24

35
intrinsics! {
46
#[arm_aeabi_alias = __aeabi_fsub]
57
pub extern "C" fn __subsf3(a: f32, b: f32) -> f32 {
6-
a + f32::from_repr(b.repr() ^ f32::SIGN_MASK)
8+
__addsf3(a, f32::from_repr(b.repr() ^ f32::SIGN_MASK))
79
}
810

911
#[arm_aeabi_alias = __aeabi_dsub]
1012
pub extern "C" fn __subdf3(a: f64, b: f64) -> f64 {
11-
a + f64::from_repr(b.repr() ^ f64::SIGN_MASK)
13+
__adddf3(a, f64::from_repr(b.repr() ^ f64::SIGN_MASK))
1214
}
1315

1416
#[cfg(target_arch = "arm")]

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)