@@ -481,13 +481,12 @@ impl<T: Float> Complex<T> {
481
481
// formula: arctan(z) = (ln(1+iz) - ln(1-iz))/(2i)
482
482
let i = Self :: i ( ) ;
483
483
let one = Self :: one ( ) ;
484
- let two = one + one;
485
484
if self == i {
486
485
return Self :: new ( T :: zero ( ) , T :: infinity ( ) ) ;
487
486
} else if self == -i {
488
487
return Self :: new ( T :: zero ( ) , -T :: infinity ( ) ) ;
489
488
}
490
- ( ( one + i * self ) . ln ( ) - ( one - i * self ) . ln ( ) ) / ( two * i)
489
+ ( ( one + i * self ) . ln ( ) - ( one - i * self ) . ln ( ) ) / ( i + i)
491
490
}
492
491
493
492
/// Computes the hyperbolic sine of `self`.
@@ -544,8 +543,8 @@ impl<T: Float> Complex<T> {
544
543
pub fn acosh ( self ) -> Self {
545
544
// formula: arccosh(z) = 2 ln(sqrt((z+1)/2) + sqrt((z-1)/2))
546
545
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
549
548
}
550
549
551
550
/// Computes the principal value of inverse hyperbolic tangent of `self`.
@@ -560,7 +559,7 @@ impl<T: Float> Complex<T> {
560
559
pub fn atanh ( self ) -> Self {
561
560
// formula: arctanh(z) = (ln(1+z) - ln(1-z))/2
562
561
let one = Self :: one ( ) ;
563
- let two = one + one;
562
+ let two = T :: one ( ) + T :: one ( ) ;
564
563
if self == one {
565
564
return Self :: new ( T :: infinity ( ) , T :: zero ( ) ) ;
566
565
} else if self == -one {
@@ -2274,7 +2273,7 @@ pub(crate) mod test {
2274
2273
assert ! ( close( _0_1i. tanh( ) , _0_1i. scale( 1.0 . tan( ) ) ) ) ;
2275
2274
for & c in all_consts. iter ( ) {
2276
2275
// tanh(conj(z)) = conj(tanh(z))
2277
- assert ! ( close( c. conj( ) . tanh( ) , c. conj ( ) . tanh ( ) ) ) ;
2276
+ assert ! ( close( c. conj( ) . tanh( ) , c. tanh ( ) . conj ( ) ) ) ;
2278
2277
// tanh(-z) = -tanh(z)
2279
2278
assert ! ( close( c. scale( -1.0 ) . tanh( ) , c. tanh( ) . scale( -1.0 ) ) ) ;
2280
2279
}
@@ -2291,7 +2290,7 @@ pub(crate) mod test {
2291
2290
) ) ;
2292
2291
for & c in all_consts. iter ( ) {
2293
2292
// asinh(conj(z)) = conj(asinh(z))
2294
- assert ! ( close( c. conj( ) . asinh( ) , c. conj ( ) . asinh ( ) ) ) ;
2293
+ assert ! ( close( c. conj( ) . asinh( ) , c. asinh ( ) . conj ( ) ) ) ;
2295
2294
// asinh(-z) = -asinh(z)
2296
2295
assert ! ( close( c. scale( -1.0 ) . asinh( ) , c. asinh( ) . scale( -1.0 ) ) ) ;
2297
2296
// for this branch, -pi/2 <= asinh(z).im <= pi/2
@@ -2305,13 +2304,18 @@ pub(crate) mod test {
2305
2304
fn test_acosh ( ) {
2306
2305
assert ! ( close( _0_0i. acosh( ) , _0_1i. scale( f64 :: consts:: PI / 2.0 ) ) ) ;
2307
2306
assert ! ( close( _1_0i. acosh( ) , _0_0i) ) ;
2307
+ // zero sign on imaginary part is used!
2308
2308
assert ! ( close(
2309
- _1_0i . scale ( -1.0 ) . acosh( ) ,
2309
+ Complex :: new ( -1. , 0. ) . acosh( ) ,
2310
2310
_0_1i. scale( f64 :: consts:: PI )
2311
2311
) ) ;
2312
+ assert ! ( close(
2313
+ _1_0i. scale( -1.0 ) . acosh( ) ,
2314
+ _0_1i. scale( -f64 :: consts:: PI )
2315
+ ) ) ;
2312
2316
for & c in all_consts. iter ( ) {
2313
2317
// acosh(conj(z)) = conj(acosh(z))
2314
- assert ! ( close( c. conj( ) . acosh( ) , c. conj ( ) . acosh ( ) ) ) ;
2318
+ assert ! ( close( c. conj( ) . acosh( ) , c. acosh ( ) . conj ( ) ) ) ;
2315
2319
// for this branch, -pi <= acosh(z).im <= pi and 0 <= acosh(z).re
2316
2320
assert ! (
2317
2321
-f64 :: consts:: PI <= c. acosh( ) . im
@@ -2328,7 +2332,7 @@ pub(crate) mod test {
2328
2332
assert ! ( close( _1_0i. atanh( ) , Complex :: new( f64 :: infinity( ) , 0.0 ) ) ) ;
2329
2333
for & c in all_consts. iter ( ) {
2330
2334
// atanh(conj(z)) = conj(atanh(z))
2331
- assert ! ( close( c. conj( ) . atanh( ) , c. conj ( ) . atanh ( ) ) ) ;
2335
+ assert ! ( close( c. conj( ) . atanh( ) , c. atanh ( ) . conj ( ) ) ) ;
2332
2336
// atanh(-z) = -atanh(z)
2333
2337
assert ! ( close( c. scale( -1.0 ) . atanh( ) , c. atanh( ) . scale( -1.0 ) ) ) ;
2334
2338
// for this branch, -pi/2 <= atanh(z).im <= pi/2
0 commit comments