@@ -464,7 +464,7 @@ function inv(w::ComplexF64)
464
464
return ComplexF64 (p* s,q* s) # undo scaling
465
465
end
466
466
467
- function ssqs (x:: T , y:: T ) where T<: AbstractFloat
467
+ function ssqs (x:: T , y:: T ) where T
468
468
k:: Int = 0
469
469
ρ = x* x + y* y
470
470
if ! isfinite (ρ) && (isinf (x) || isinf (y))
@@ -478,7 +478,8 @@ function ssqs(x::T, y::T) where T<:AbstractFloat
478
478
ρ, k
479
479
end
480
480
481
- function sqrt (z:: Complex{<:AbstractFloat} )
481
+ function sqrt (z:: Complex )
482
+ z = float (z)
482
483
x, y = reim (z)
483
484
if x== y== 0
484
485
return Complex (zero (x),y)
@@ -503,7 +504,6 @@ function sqrt(z::Complex{<:AbstractFloat})
503
504
end
504
505
Complex (ξ,η)
505
506
end
506
- sqrt (z:: Complex ) = sqrt (float (z))
507
507
508
508
# function sqrt(z::Complex)
509
509
# rz = float(real(z))
@@ -560,10 +560,12 @@ julia> rad2deg(angle(-1 - im))
560
560
"""
561
561
angle (z:: Complex ) = atan (imag (z), real (z))
562
562
563
- function log (z:: Complex{T} ) where T<: AbstractFloat
564
- T1:: T = 1.25
565
- T2:: T = 3
566
- ln2:: T = log (convert (T,2 )) # 0.6931471805599453
563
+ function log (z:: Complex )
564
+ z = float (z)
565
+ T = typeof (real (z))
566
+ T1 = convert (T,5 )/ convert (T,4 )
567
+ T2 = convert (T,3 )
568
+ ln2 = log (convert (T,2 )) # 0.6931471805599453
567
569
x, y = reim (z)
568
570
ρ, k = ssqs (x,y)
569
571
ax = abs (x)
@@ -580,7 +582,6 @@ function log(z::Complex{T}) where T<:AbstractFloat
580
582
end
581
583
Complex (ρρ, angle (z))
582
584
end
583
- log (z:: Complex ) = log (float (z))
584
585
585
586
# function log(z::Complex)
586
587
# ar = abs(real(z))
@@ -633,7 +634,7 @@ function exp(z::Complex)
633
634
end
634
635
end
635
636
636
- function expm1 (z:: Complex{T} ) where T<: Real
637
+ function expm1 (z:: Complex{T} ) where T
637
638
Tf = float (T)
638
639
zr,zi = reim (z)
639
640
if isnan (zr)
@@ -681,24 +682,26 @@ function log1p(z::Complex{T}) where T
681
682
end
682
683
end
683
684
684
- function exp2 (z:: Complex{T} ) where T<: AbstractFloat
685
+ function exp2 (z:: Complex{T} ) where T
686
+ z = float (z)
685
687
er = exp2 (real (z))
686
688
theta = imag (z) * log (convert (T, 2 ))
687
689
s, c = sincos (theta)
688
690
Complex (er * c, er * s)
689
691
end
690
- exp2 (z:: Complex ) = exp2 (float (z))
691
692
692
- function exp10 (z:: Complex{T} ) where T<: AbstractFloat
693
+ function exp10 (z:: Complex{T} ) where T
694
+ z = float (z)
693
695
er = exp10 (real (z))
694
696
theta = imag (z) * log (convert (T, 10 ))
695
697
s, c = sincos (theta)
696
698
Complex (er * c, er * s)
697
699
end
698
- exp10 (z:: Complex ) = exp10 (float (z))
699
700
700
701
# _cpow helper function to avoid method ambiguity with ^(::Complex,::Real)
701
- function _cpow (z:: Union{T,Complex{T}} , p:: Union{T,Complex{T}} ) where {T<: AbstractFloat }
702
+ function _cpow (z:: Union{T,Complex{T}} , p:: Union{T,Complex{T}} ) where T
703
+ z = float (z)
704
+ p = float (p)
702
705
if isreal (p)
703
706
pᵣ = real (p)
704
707
if isinteger (pᵣ) && abs (pᵣ) < typemax (Int32)
@@ -777,7 +780,6 @@ function _cpow(z::Union{T,Complex{T}}, p::Union{T,Complex{T}}) where {T<:Abstrac
777
780
return Complex (T (NaN ),T (NaN )) # non-finite phase angle or NaN input
778
781
end
779
782
end
780
- _cpow (z, p) = _cpow (float (z), float (p))
781
783
^ (z:: Complex{T} , p:: Complex{T} ) where T<: Real = _cpow (z, p)
782
784
^ (z:: Complex{T} , p:: T ) where T<: Real = _cpow (z, p)
783
785
^ (z:: T , p:: Complex{T} ) where T<: Real = _cpow (z, p)
@@ -859,7 +861,8 @@ function asin(z::Complex)
859
861
Complex (ξ,η)
860
862
end
861
863
862
- function acos (z:: Complex{<:AbstractFloat} )
864
+ function acos (z:: Complex )
865
+ z = float (z)
863
866
zr, zi = reim (z)
864
867
if isnan (zr)
865
868
if isinf (zi) return Complex (zr, - zi)
@@ -880,7 +883,6 @@ function acos(z::Complex{<:AbstractFloat})
880
883
if isinf (zr) && isinf (zi) ξ -= oftype (η,pi )/ 4 * sign (zr) end
881
884
Complex (ξ,η)
882
885
end
883
- acos (z:: Complex ) = acos (float (z))
884
886
885
887
function atan (z:: Complex )
886
888
w = atanh (Complex (- imag (z),real (z)))
@@ -898,7 +900,8 @@ function cosh(z::Complex)
898
900
cos (Complex (zi,- zr))
899
901
end
900
902
901
- function tanh (z:: Complex{T} ) where T<: AbstractFloat
903
+ function tanh (z:: Complex{T} ) where T
904
+ z = float (z)
902
905
Ω = prevfloat (typemax (T))
903
906
ξ, η = reim (z)
904
907
if isnan (ξ) && η== 0 return Complex (ξ, η) end
@@ -917,7 +920,6 @@ function tanh(z::Complex{T}) where T<:AbstractFloat
917
920
end
918
921
end
919
922
end
920
- tanh (z:: Complex ) = tanh (float (z))
921
923
922
924
function asinh (z:: Complex )
923
925
w = asin (Complex (- imag (z),real (z)))
@@ -943,7 +945,8 @@ function acosh(z::Complex)
943
945
Complex (ξ, η)
944
946
end
945
947
946
- function atanh (z:: Complex{T} ) where T<: AbstractFloat
948
+ function atanh (z:: Complex{T} ) where T
949
+ z = float (z)
947
950
Ω = prevfloat (typemax (T))
948
951
θ = sqrt (Ω)/ 4
949
952
ρ = 1 / θ
@@ -986,7 +989,6 @@ function atanh(z::Complex{T}) where T<:AbstractFloat
986
989
end
987
990
β * Complex (ξ, η)
988
991
end
989
- atanh (z:: Complex ) = atanh (float (z))
990
992
991
993
# Rounding complex numbers
992
994
# Requires two different RoundingModes for the real and imaginary components
0 commit comments