Rollup merge of #77921 - wcampbell0x2a:f64-collapsible-if, r=jyn514

f64: Refactor collapsible_if
This commit is contained in:
Yuki Okushi 2020-10-30 18:00:49 +09:00 committed by GitHub
commit 02a4b58a3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -920,22 +920,20 @@ pub fn clamp(self, min: f64, max: f64) -> f64 {
fn log_wrapper<F: Fn(f64) -> f64>(self, log_fn: F) -> f64 {
if !cfg!(any(target_os = "solaris", target_os = "illumos")) {
log_fn(self)
} else {
if self.is_finite() {
if self > 0.0 {
log_fn(self)
} else if self == 0.0 {
Self::NEG_INFINITY // log(0) = -Inf
} else {
Self::NAN // log(-n) = NaN
}
} else if self.is_nan() {
self // log(NaN) = NaN
} else if self > 0.0 {
self // log(Inf) = Inf
} else if self.is_finite() {
if self > 0.0 {
log_fn(self)
} else if self == 0.0 {
Self::NEG_INFINITY // log(0) = -Inf
} else {
Self::NAN // log(-Inf) = NaN
Self::NAN // log(-n) = NaN
}
} else if self.is_nan() {
self // log(NaN) = NaN
} else if self > 0.0 {
self // log(Inf) = Inf
} else {
Self::NAN // log(-Inf) = NaN
}
}
}