diff options
| author | Nikita Baksalyar <nikita.baksalyar@gmail.com> | 2016-01-26 17:15:10 +0300 |
|---|---|---|
| committer | Nikita Baksalyar <nikita.baksalyar@gmail.com> | 2016-01-31 18:57:28 +0300 |
| commit | ebab24059a2b85cf6167c589c40a265f815d9f45 (patch) | |
| tree | 45743743244ea0ac23f8bbc9518265d7adce155a /src/libstd/num | |
| parent | f189d7a6937c063f9592136a39c836b17c008a93 (diff) | |
| download | rust-ebab24059a2b85cf6167c589c40a265f815d9f45.tar.gz rust-ebab24059a2b85cf6167c589c40a265f815d9f45.zip | |
Apply several fixes for Illumos support
Diffstat (limited to 'src/libstd/num')
| -rw-r--r-- | src/libstd/num/f64.rs | 99 |
1 files changed, 64 insertions, 35 deletions
diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 2afaef2fff1..f119b1d9f9a 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -84,38 +84,6 @@ mod cmath { } } -#[cfg(not(target_os = "sunos"))] -macro_rules! log_wrapper { - ($num:ident, $f:ident) => ( - unsafe { intrinsics::$f($num) } - ) -} - -// Illumos requires a wrapper around log, log2, and log10 functions -// because of non-standard behavior (e.g. log(-n) returns -Inf instead -// of expected NaN). -#[cfg(target_os = "sunos")] -macro_rules! log_wrapper { - ($num:ident, $f:ident) => ( - if $num.is_finite() { - if $num > 0.0 { - return unsafe { intrinsics::$f($num) } - } - return if $num == 0.0 { - NEG_INFINITY // log(0) = -Inf - } else { - NAN // log(-ve) = NaN - } - } else if $num.is_nan() { - $num // log(NaN) = NaN - } else if $num > 0.0 { - $num // log(Inf) = Inf - } else { - return NAN // log(-Inf) = NaN - } - ) -} - #[cfg(not(test))] #[lang = "f64"] impl f64 { @@ -543,7 +511,28 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ln(self) -> f64 { - log_wrapper!(self, logf64) + if !cfg!(target_os = "sunos") { + unsafe { intrinsics::logf64(self) } + } else { + // Illumos requires a wrapper around log, log2, and log10 functions + // because of their non-standard behavior (e.g. log(-n) returns -Inf instead + // of expected NaN). + if self.is_finite() { + if self > 0.0 { + unsafe { intrinsics::logf64(self) } + } else if self == 0.0 { + NEG_INFINITY // log(0) = -Inf + } else { + NAN // log(-n) = NaN + } + } else if self.is_nan() { + self // log(NaN) = NaN + } else if self > 0.0 { + self // log(Inf) = Inf + } else { + NAN // log(-Inf) = NaN + } + } } /// Returns the logarithm of the number with respect to an arbitrary base. @@ -578,7 +567,27 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn log2(self) -> f64 { - log_wrapper!(self, log2f64) + if !cfg!(target_os = "sunos") { + unsafe { intrinsics::log2f64(self) } + } else { + // Illumos requires a wrapper around the log2 function because of + // its non-standard behavior + if self.is_finite() { + if self > 0.0 { + unsafe { intrinsics::log2f64(self) } + } else if self == 0.0 { + NEG_INFINITY // log2(0) = -Inf + } else { + NAN // log2(-n) = NaN + } + } else if self.is_nan() { + self // log2(NaN) = NaN + } else if self > 0.0 { + self // log2(Inf) = Inf + } else { + NAN // log2(-Inf) = NaN + } + } } /// Returns the base 10 logarithm of the number. @@ -594,7 +603,27 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn log10(self) -> f64 { - log_wrapper!(self, log10f64) + if !cfg!(target_os = "sunos") { + unsafe { intrinsics::log10f64(self) } + } else { + // Illumos requires a wrapper around the log10 function because of + // its non-standard behavior. + if self.is_finite() { + if self > 0.0 { + unsafe { intrinsics::log10f64(self) } + } else if self == 0.0 { + NEG_INFINITY // log10(0) = -Inf + } else { + NAN // log10(-n) = NaN + } + } else if self.is_nan() { + self // log10(NaN) = NaN + } else if self > 0.0 { + self // log10(Inf) = Inf + } else { + NAN // log10(-Inf) = NaN + } + } } /// Converts radians to degrees. |
