From d4e7aa649aa95b1be555d03a174bcbca19db4005 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Thu, 5 Oct 2023 16:28:15 +0200 Subject: [PATCH] type-stabilize reli(n,x) --- src/Eta.jl | 2 +- src/Factorial.jl | 4 ++-- src/Harmonic.jl | 2 +- src/Li.jl | 6 ++++-- src/Zeta.jl | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Eta.jl b/src/Eta.jl index 704d4bd..bc39e2e 100644 --- a/src/Eta.jl +++ b/src/Eta.jl @@ -61,7 +61,7 @@ const MINUS_ETA_NEG = ( ) # returns Li(n,-1) = (2^(1 - n) - 1)*zeta(n) -function neg_eta(n::Integer, T) +function neg_eta(n::Integer, ::Type{T})::T where T if issimplefloat(T) convert(T, neg_eta_f46(n)) else diff --git a/src/Factorial.jl b/src/Factorial.jl index b4b86f6..40caba2 100644 --- a/src/Factorial.jl +++ b/src/Factorial.jl @@ -121,7 +121,7 @@ const INVERSE_FACTORIALS = ( ) # returns n! for n >= 0 -function fac(n::Integer, T) +function fac(n::Integer, ::Type{T})::T where T if issimplefloat(T) convert(T, fac_f64(n)) else @@ -148,7 +148,7 @@ function fac_big(n::Integer)::BigFloat end # returns 1/n! for n >= 0 -function inv_fac(n::Integer, T) +function inv_fac(n::Integer, ::Type{T})::T where T if issimplefloat(T) convert(T, inv_fac_f64(n)) else diff --git a/src/Harmonic.jl b/src/Harmonic.jl index b829f06..e335c6a 100644 --- a/src/Harmonic.jl +++ b/src/Harmonic.jl @@ -1,5 +1,5 @@ # returns n-th harmonic number, n > 0 -function harmonic(n::Integer, T) +function harmonic(n::Integer, ::Type{T})::T where T if issimplefloat(T) convert(T, harmonic_f64(n)) else diff --git a/src/Li.jl b/src/Li.jl index 2b9ee89..a7fd0bd 100644 --- a/src/Li.jl +++ b/src/Li.jl @@ -29,7 +29,7 @@ _reli(n::Integer, x::Float16) = oftype(x, _reli(n, Float32(x))) _reli(n::Integer, x::Float32) = oftype(x, _reli(n, Float64(x))) -function _reli(n::Integer, x::Real)::Real +function _reli(n::Integer, x::Real) isnan(x) && return oftype(x, NaN) isinf(x) && return oftype(x, -Inf) x == zero(x) && return zero(x) @@ -157,7 +157,9 @@ function _li(n::Integer, z::ComplexF64)::ComplexF64 end # returns -(-1)^n of type T -oddsgn(n, T) = isodd(n) ? one(T) : -one(T) +function oddsgn(n, ::Type{T})::T where T + isodd(n) ? one(T) : -one(T) +end # returns r.h.s. of inversion formula for complex z: # diff --git a/src/Zeta.jl b/src/Zeta.jl index ed60ecd..adccae4 100644 --- a/src/Zeta.jl +++ b/src/Zeta.jl @@ -63,7 +63,7 @@ const ZETA_NEG = ( ) # Riemann zeta function for integer arguments -function zeta(n::Integer, T) +function zeta(n::Integer, ::Type{T})::T where T if issimplefloat(T) convert(T, zeta_f64(n)) else