@@ -481,13 +481,12 @@ impl<T: Float> Complex<T> {
481481 // formula: arctan(z) = (ln(1+iz) - ln(1-iz))/(2i)
482482 let i = Self :: i ( ) ;
483483 let one = Self :: one ( ) ;
484- let two = one + one;
485484 if self == i {
486485 return Self :: new ( T :: zero ( ) , T :: infinity ( ) ) ;
487486 } else if self == -i {
488487 return Self :: new ( T :: zero ( ) , -T :: infinity ( ) ) ;
489488 }
490- ( ( one + i * self ) . ln ( ) - ( one - i * self ) . ln ( ) ) / ( two * i)
489+ ( ( one + i * self ) . ln ( ) - ( one - i * self ) . ln ( ) ) / ( i + i)
491490 }
492491
493492 /// Computes the hyperbolic sine of `self`.
@@ -544,8 +543,8 @@ impl<T: Float> Complex<T> {
544543 pub fn acosh ( self ) -> Self {
545544 // formula: arccosh(z) = 2 ln(sqrt((z+1)/2) + sqrt((z-1)/2))
546545 let one = Self :: one ( ) ;
547- let two = one + one;
548- two * ( ( ( self + one) / two) . sqrt ( ) + ( ( self - one) / two) . sqrt ( ) ) . ln ( )
546+ let two = T :: one ( ) + T :: one ( ) ;
547+ ( ( ( self + one) / two) . sqrt ( ) + ( ( self - one) / two) . sqrt ( ) ) . ln ( ) * two
549548 }
550549
551550 /// Computes the principal value of inverse hyperbolic tangent of `self`.
@@ -560,7 +559,7 @@ impl<T: Float> Complex<T> {
560559 pub fn atanh ( self ) -> Self {
561560 // formula: arctanh(z) = (ln(1+z) - ln(1-z))/2
562561 let one = Self :: one ( ) ;
563- let two = one + one;
562+ let two = T :: one ( ) + T :: one ( ) ;
564563 if self == one {
565564 return Self :: new ( T :: infinity ( ) , T :: zero ( ) ) ;
566565 } else if self == -one {
@@ -2274,7 +2273,7 @@ pub(crate) mod test {
22742273 assert ! ( close( _0_1i. tanh( ) , _0_1i. scale( 1.0 . tan( ) ) ) ) ;
22752274 for & c in all_consts. iter ( ) {
22762275 // tanh(conj(z)) = conj(tanh(z))
2277- assert ! ( close( c. conj( ) . tanh( ) , c. conj ( ) . tanh ( ) ) ) ;
2276+ assert ! ( close( c. conj( ) . tanh( ) , c. tanh ( ) . conj ( ) ) ) ;
22782277 // tanh(-z) = -tanh(z)
22792278 assert ! ( close( c. scale( -1.0 ) . tanh( ) , c. tanh( ) . scale( -1.0 ) ) ) ;
22802279 }
@@ -2291,7 +2290,7 @@ pub(crate) mod test {
22912290 ) ) ;
22922291 for & c in all_consts. iter ( ) {
22932292 // asinh(conj(z)) = conj(asinh(z))
2294- assert ! ( close( c. conj( ) . asinh( ) , c. conj ( ) . asinh ( ) ) ) ;
2293+ assert ! ( close( c. conj( ) . asinh( ) , c. asinh ( ) . conj ( ) ) ) ;
22952294 // asinh(-z) = -asinh(z)
22962295 assert ! ( close( c. scale( -1.0 ) . asinh( ) , c. asinh( ) . scale( -1.0 ) ) ) ;
22972296 // for this branch, -pi/2 <= asinh(z).im <= pi/2
@@ -2305,13 +2304,18 @@ pub(crate) mod test {
23052304 fn test_acosh ( ) {
23062305 assert ! ( close( _0_0i. acosh( ) , _0_1i. scale( f64 :: consts:: PI / 2.0 ) ) ) ;
23072306 assert ! ( close( _1_0i. acosh( ) , _0_0i) ) ;
2307+ // zero sign on imaginary part is used!
23082308 assert ! ( close(
2309- _1_0i . scale ( -1.0 ) . acosh( ) ,
2309+ Complex :: new ( -1. , 0. ) . acosh( ) ,
23102310 _0_1i. scale( f64 :: consts:: PI )
23112311 ) ) ;
2312+ assert ! ( close(
2313+ _1_0i. scale( -1.0 ) . acosh( ) ,
2314+ _0_1i. scale( -f64 :: consts:: PI )
2315+ ) ) ;
23122316 for & c in all_consts. iter ( ) {
23132317 // acosh(conj(z)) = conj(acosh(z))
2314- assert ! ( close( c. conj( ) . acosh( ) , c. conj ( ) . acosh ( ) ) ) ;
2318+ assert ! ( close( c. conj( ) . acosh( ) , c. acosh ( ) . conj ( ) ) ) ;
23152319 // for this branch, -pi <= acosh(z).im <= pi and 0 <= acosh(z).re
23162320 assert ! (
23172321 -f64 :: consts:: PI <= c. acosh( ) . im
@@ -2328,7 +2332,7 @@ pub(crate) mod test {
23282332 assert ! ( close( _1_0i. atanh( ) , Complex :: new( f64 :: infinity( ) , 0.0 ) ) ) ;
23292333 for & c in all_consts. iter ( ) {
23302334 // atanh(conj(z)) = conj(atanh(z))
2331- assert ! ( close( c. conj( ) . atanh( ) , c. conj ( ) . atanh ( ) ) ) ;
2335+ assert ! ( close( c. conj( ) . atanh( ) , c. atanh ( ) . conj ( ) ) ) ;
23322336 // atanh(-z) = -atanh(z)
23332337 assert ! ( close( c. scale( -1.0 ) . atanh( ) , c. atanh( ) . scale( -1.0 ) ) ) ;
23342338 // for this branch, -pi/2 <= atanh(z).im <= pi/2
0 commit comments