Skip to content

Instantly share code, notes, and snippets.

@nbaksalyar
Last active January 20, 2016 18:55
Show Gist options
  • Save nbaksalyar/bf8f1eae0e1650db6a2d to your computer and use it in GitHub Desktop.
Save nbaksalyar/bf8f1eae0e1650db6a2d to your computer and use it in GitHub Desktop.
f64 implementation
impl f64 {
// ...
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn ln(self) -> f64 {
if self.is_finite() {
if x > 0.0 {
return unsafe { intrinsics::logf64(self) }
}
return if x == 0.0 {
NEG_INFINITY // log(0) = -Inf
} else {
NAN // log(-ve) = NaN
}
} else if self.is_nan() {
self // log(NaN) = NaN
} else if x > 0.0 {
x // log(Inf) = Inf
} else {
return NAN // log(-Inf) = NaN
}
}
// ...
}
impl f64 {
// ...
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn ln(self) -> f64 {
unsafe { intrinsics::logf64(self) }
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment