@@ -84,38 +84,6 @@ mod cmath {
8484 }
8585}
8686
87- #[ cfg( not( target_os = "sunos" ) ) ]
88- macro_rules! log_wrapper {
89- ( $num: ident, $f: ident) => (
90- unsafe { intrinsics:: $f( $num) }
91- )
92- }
93-
94- // Illumos requires a wrapper around log, log2, and log10 functions
95- // because of non-standard behavior (e.g. log(-n) returns -Inf instead
96- // of expected NaN).
97- #[ cfg( target_os = "sunos" ) ]
98- macro_rules! log_wrapper {
99- ( $num: ident, $f: ident) => (
100- if $num. is_finite( ) {
101- if $num > 0.0 {
102- return unsafe { intrinsics:: $f( $num) }
103- }
104- return if $num == 0.0 {
105- NEG_INFINITY // log(0) = -Inf
106- } else {
107- NAN // log(-ve) = NaN
108- }
109- } else if $num. is_nan( ) {
110- $num // log(NaN) = NaN
111- } else if $num > 0.0 {
112- $num // log(Inf) = Inf
113- } else {
114- return NAN // log(-Inf) = NaN
115- }
116- )
117- }
118-
11987#[ cfg( not( test) ) ]
12088#[ lang = "f64" ]
12189impl f64 {
@@ -543,7 +511,28 @@ impl f64 {
543511 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
544512 #[ inline]
545513 pub fn ln ( self ) -> f64 {
546- log_wrapper ! ( self , logf64)
514+ if !cfg ! ( target_os = "sunos" ) {
515+ unsafe { intrinsics:: logf64 ( self ) }
516+ } else {
517+ // Illumos requires a wrapper around log, log2, and log10 functions
518+ // because of their non-standard behavior (e.g. log(-n) returns -Inf instead
519+ // of expected NaN).
520+ if self . is_finite ( ) {
521+ if self > 0.0 {
522+ unsafe { intrinsics:: logf64 ( self ) }
523+ } else if self == 0.0 {
524+ NEG_INFINITY // log(0) = -Inf
525+ } else {
526+ NAN // log(-n) = NaN
527+ }
528+ } else if self . is_nan ( ) {
529+ self // log(NaN) = NaN
530+ } else if self > 0.0 {
531+ self // log(Inf) = Inf
532+ } else {
533+ NAN // log(-Inf) = NaN
534+ }
535+ }
547536 }
548537
549538 /// Returns the logarithm of the number with respect to an arbitrary base.
@@ -578,7 +567,27 @@ impl f64 {
578567 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
579568 #[ inline]
580569 pub fn log2 ( self ) -> f64 {
581- log_wrapper ! ( self , log2f64)
570+ if !cfg ! ( target_os = "sunos" ) {
571+ unsafe { intrinsics:: log2f64 ( self ) }
572+ } else {
573+ // Illumos requires a wrapper around the log2 function because of
574+ // its non-standard behavior
575+ if self . is_finite ( ) {
576+ if self > 0.0 {
577+ unsafe { intrinsics:: log2f64 ( self ) }
578+ } else if self == 0.0 {
579+ NEG_INFINITY // log2(0) = -Inf
580+ } else {
581+ NAN // log2(-n) = NaN
582+ }
583+ } else if self . is_nan ( ) {
584+ self // log2(NaN) = NaN
585+ } else if self > 0.0 {
586+ self // log2(Inf) = Inf
587+ } else {
588+ NAN // log2(-Inf) = NaN
589+ }
590+ }
582591 }
583592
584593 /// Returns the base 10 logarithm of the number.
@@ -594,7 +603,27 @@ impl f64 {
594603 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
595604 #[ inline]
596605 pub fn log10 ( self ) -> f64 {
597- log_wrapper ! ( self , log10f64)
606+ if !cfg ! ( target_os = "sunos" ) {
607+ unsafe { intrinsics:: log10f64 ( self ) }
608+ } else {
609+ // Illumos requires a wrapper around the log10 function because of
610+ // its non-standard behavior.
611+ if self . is_finite ( ) {
612+ if self > 0.0 {
613+ unsafe { intrinsics:: log10f64 ( self ) }
614+ } else if self == 0.0 {
615+ NEG_INFINITY // log10(0) = -Inf
616+ } else {
617+ NAN // log10(-n) = NaN
618+ }
619+ } else if self . is_nan ( ) {
620+ self // log10(NaN) = NaN
621+ } else if self > 0.0 {
622+ self // log10(Inf) = Inf
623+ } else {
624+ NAN // log10(-Inf) = NaN
625+ }
626+ }
598627 }
599628
600629 /// Converts radians to degrees.
0 commit comments