Skip to content

Commit 5e9008d

Browse files
committed
Fix undefined behavior in f64::sqrt
This fixes a reappearance of bug #9987 introduced in 1ddee80, which caused f64::tests::test_sqrt_domain to fail (at least on some systems).
1 parent 4a1fda8 commit 5e9008d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/libstd/num/f64.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,11 @@ impl f64 {
454454
#[stable(feature = "rust1", since = "1.0.0")]
455455
#[inline]
456456
pub fn sqrt(self) -> f64 {
457-
unsafe { intrinsics::sqrtf64(self) }
457+
if self < 0.0 {
458+
NAN
459+
} else {
460+
unsafe { intrinsics::sqrtf64(self) }
461+
}
458462
}
459463

460464
/// Returns `e^(self)`, (the exponential function).

0 commit comments

Comments
 (0)