@@ -73,7 +73,8 @@ function lgamma(z::Complex{Float64})
73
73
else
74
74
return Complex (NaN , NaN )
75
75
end
76
- elseif x > 7 || yabs > 7 # use the Stirling asymptotic series for sufficiently large x or |y|
76
+ elseif x > 7 || yabs > 7
77
+ # use the Stirling asymptotic series for sufficiently large x or |y|
77
78
return lgamma_asymptotic (z)
78
79
elseif x < 0.1 # use reflection formula to transform to x > 0
79
80
if x == 0 && y == 0 # return Inf with the correct imaginary part for z == 0
@@ -107,7 +108,8 @@ function lgamma(z::Complex{Float64})
107
108
- 2.2315475845357937976132853e-04 ,9.9457512781808533714662972e-05 ,
108
109
- 4.4926236738133141700224489e-05 ,2.0507212775670691553131246e-05 )
109
110
end
110
- # use recurrence relation lgamma(z) = lgamma(z+1) - log(z) to shift to x > 7 for asymptotic series
111
+ # use recurrence relation lgamma(z) = lgamma(z+1) - log(z )
112
+ # to shift to x > 7 for asymptotic series
111
113
shiftprod = Complex (x,yabs)
112
114
x += 1
113
115
sb = false # == signbit(imag(shiftprod)) == signbit(yabs)
@@ -394,7 +396,8 @@ function zeta(s::Union{Int, ComplexOrReal{Float64}},
394
396
minus_z = - z
395
397
ζ += pow_oftype (ζ, minus_z, minus_s) # ν = 0 term
396
398
if xf != z
397
- ζ += pow_oftype (ζ, z - nx, minus_s) # real(z - nx) > 0, so use correct branch cut
399
+ ζ += pow_oftype (ζ, z - nx, minus_s)
400
+ # real(z - nx) > 0, so use correct branch cut
398
401
# otherwise, if xf==z, then the definition skips this term
399
402
end
400
403
# do loop in different order, depending on the sign of s,
447
450
"""
448
451
polygamma(m, x)
449
452
450
- Compute the polygamma function of order `m` of argument `x` (the `(m+1)th` derivative of the
451
- logarithm of `gamma(x)`)
453
+ Compute the polygamma function of order `m` of argument `x`
454
+ (the `(m+1)th` derivative of the logarithm of `gamma(x)`)
452
455
"""
453
456
function polygamma (m:: Integer , z:: ComplexOrReal{Float64} )
454
457
m == 0 && return digamma (z)
511
514
"""
512
515
beta(x, y)
513
516
514
- Euler integral of the first kind ``\\ operatorname{B}(x,y) = \\ Gamma(x)\\ Gamma(y)/\\ Gamma(x+y)``.
517
+ Euler integral of the first kind
518
+ ``\\ operatorname{B}(x,y) = \\ Gamma(x)\\ Gamma(y)/\\ Gamma(x+y)``.
515
519
"""
516
520
function beta (x:: Number , w:: Number )
517
521
yx, sx = lgamma_r (x)
@@ -611,10 +615,11 @@ end
611
615
# and if we really cared about half precision, we could make a faster
612
616
# Float16 version, by using a precomputed table look-up.
613
617
614
- # Float16, and Float32 and their Complex equivalents can be cast to Float64
615
- # and results cast back. Similar for BitIntegers (eg Int32), but no casting back
618
+ # Float16, and Float32 and their Complex equivalents can be converted to Float64
619
+ # and results converted back. Similar for BitIntegers (eg Int32), but no converting back
616
620
# Otherwise, we need to make things use their own `float` converting methods
617
- # and in those cases, we do not cast back either.
621
+ # and in those cases, we do not convert back either as we assume
622
+ # they also implement there own versions of the functions
618
623
619
624
620
625
ofpromotedtype (as:: Tuple , c) = convert (promote_type (typeof .(as)... ), c)
@@ -632,19 +637,19 @@ for f in (:digamma, :trigamma, :zeta, :eta, :invdigamma)
632
637
@eval begin
633
638
$ f (z:: ComplexOrRealUnion (Base. BitInteger. types... )) = $ f (f64 (z))
634
639
$ f (z:: ComplexOrRealUnion (Float16,Float32)) = oftype (z, $ f (f64 (z)))
635
-
640
+
636
641
function $f (z:: Number )
637
642
x = float (z)
638
643
typeof (x) == typeof (z) && throw (MethodError ($ f, (z,)))
639
- # There is nothing to fallback to, since this didn't work
644
+ # There is nothing to fallback to, since this didn't change the argument types
640
645
$ f (x)
641
646
end
642
647
end
643
648
end
644
649
645
-
646
- polygamma (m :: Integer , z :: ComplexOrRealUnion (Float16,Float32)) = oftype (z, polygamma (m, f64 (z)))
647
-
650
+ function polygamma (m :: Integer , z :: ComplexOrRealUnion (Float16,Float32))
651
+ oftype (z, polygamma (m, f64 (z)))
652
+ end
648
653
649
654
for T1 in types_le_Float64, T2 in types_le_Float64
650
655
if (T1 == T2 == Float64) || (T1 == Int && T2 == Float64)
@@ -664,12 +669,12 @@ for T1 in types_le_Float64, T2 in types_le_Float64
664
669
end
665
670
end
666
671
667
- # this is the one definition that is skipped
672
+ # this is the one definition that is skipped
668
673
function zeta (s:: Complex{Int} , z:: ComplexOrReal{Float64} ):: Complex{Float64}
669
674
zeta (f64 (s), f64 (z))
670
675
end
671
676
672
- function zeta (s:: Integer , z:: Number )
677
+ function zeta (s:: Integer , z:: Number )
673
678
x = float (z)
674
679
t = Int (s) # One could worry here about converting a BigInteger into a Int32/Int64
675
680
if typeof (x) === typeof (z) && typeof (t) === typeof (s)
@@ -680,7 +685,7 @@ function zeta(s::Integer, z::Number)
680
685
end
681
686
682
687
683
- function zeta (s:: Number , z:: Number )
688
+ function zeta (s:: Number , z:: Number )
684
689
x = float (z)
685
690
t = float (s)
686
691
if typeof (x) === typeof (z) && typeof (t) === typeof (s)
0 commit comments