Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Float::copysign impl #293

Merged
merged 2 commits into from
Jan 3, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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