diff --git a/src/gamma.jl b/src/gamma.jl index 5004404d..6e62b3fd 100644 --- a/src/gamma.jl +++ b/src/gamma.jl @@ -416,7 +416,27 @@ Riemann zeta function \zeta(s) = \sum_{n=1}^\infty \frac{1}{n^s}\quad\text{for}\quad s\in\mathbb{C}. ``` -External links: [Wikipedia](https://en.wikipedia.org/wiki/Riemann_zeta_function) +# Examples +```jldoctest +julia> zeta(-1) # -1/12 +-0.08333333333333338 + +julia> zeta(0) +-0.5 + +julia> zeta(-10) # zeta(-2n) == 0 +-0.0 + +julia> zeta(1) +NaN + +julia> zeta(Inf) +1.0 +``` + +External links: +[DLMF 25.2(i)](https://dlmf.nist.gov/25.2#i), +[Wikipedia](https://en.wikipedia.org/wiki/Riemann_zeta_function) """ zeta(s::Number) = _zeta(float(s)) diff --git a/test/gamma.jl b/test/gamma.jl index 8c970786..89ded587 100644 --- a/test/gamma.jl +++ b/test/gamma.jl @@ -174,18 +174,37 @@ end @testset "zeta" begin + # Riemann zeta function + # https://en.wikipedia.org/wiki/Particular_values_of_the_Riemann_zeta_function @test zeta(0) ≈ -0.5 + # Positive integers + @test isnan(zeta(1)) @test zeta(2) ≈ pi^2/6 @test zeta(Complex{Float32}(2)) ≈ zeta(2) + @test zeta(3) ≈ 1.2020569031595942 # Apéry's constant @test zeta(4) ≈ pi^4/90 - @test zeta(1,Float16(2.)) ≈ zeta(1,2.) - @test zeta(1.,Float16(2.)) ≈ zeta(1,2.) - @test zeta(Float16(1.),Float16(2.)) ≈ zeta(1,2.) + @test zeta(6) ≈ pi^6/945 + @test zeta(8) ≈ pi^8/9450 + # Negative integers + for n in 1:10 + # trivial zeros + @test zeta(-2n) == 0 + end + @test zeta(-1) ≈ -1/12 + @test zeta(-3) ≈ 1/120 + @test zeta(-5) ≈ -1/252 + @test zeta(-7) ≈ 1/240 + # NaN @test isnan(zeta(NaN)) @test isnan(zeta(1.0e0)) @test isnan(zeta(1.0f0)) - @test isnan(zeta(complex(0,Inf))) - @test isnan(zeta(complex(-Inf,0))) + @test isnan(zeta(complex(0, Inf))) + @test isnan(zeta(complex(-Inf, 0))) + + # Hurwitz zeta function + @test zeta(1, Float16(2.)) ≈ zeta(1, 2.) + @test zeta(1., Float16(2.)) ≈ zeta(1, 2.) + @test zeta(Float16(1.), Float16(2.)) ≈ zeta(1, 2.) end #(compared to Wolfram Alpha)