Skip to content

Commit

Permalink
fix {f32,f64,F32,F64}::copysign Float impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbepop committed Jan 1, 2022
1 parent 8b27c2b commit ac18ee5
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,11 +767,6 @@ macro_rules! impl_float {
}
fn copysign(self, other: $type) -> $type {
use core::mem::size_of;

if self.is_nan() {
return self;
}

let sign_mask: $iXX = 1 << ((size_of::<$iXX>() << 3) - 1);
let self_int: $iXX = self.transmute_into();
let other_int: $iXX = other.transmute_into();
Expand All @@ -794,6 +789,19 @@ impl_float!(f64, f64, i64);
impl_float!(F32, f32, i32);
impl_float!(F64, f64, i64);

#[test]
fn copysign_regression_works() {
// This test has been directly extracted from a WebAssembly Specification assertion.
use Float as _;
assert!(F32::from_bits(0xFFC00000).is_nan());
assert_eq!(
F32::from_bits(0xFFC00000)
.copysign(F32::from_bits(0x0000_0000))
.to_bits(),
F32::from_bits(0x7FC00000).to_bits()
)
}

#[cfg(not(feature = "std"))]
mod libm_adapters {
pub mod f32 {
Expand Down

0 comments on commit ac18ee5

Please sign in to comment.