Skip to content

Commit

Permalink
Fix undefined behavior in f64::sqrt
Browse files Browse the repository at this point in the history
This fixes a reappearance of bug #9987 introduced in
1ddee80, which caused
f64::tests::test_sqrt_domain to fail (at least on some systems).
  • Loading branch information
wthrowe committed Aug 23, 2015
1 parent 4a1fda8 commit 5e9008d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/libstd/num/f64.rs
Expand Up @@ -454,7 +454,11 @@ impl f64 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn sqrt(self) -> f64 {
unsafe { intrinsics::sqrtf64(self) }
if self < 0.0 {
NAN
} else {
unsafe { intrinsics::sqrtf64(self) }
}
}

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

0 comments on commit 5e9008d

Please sign in to comment.