This will dispatch on the type, thus it will specialize the code:
function floatconvergents{T<:FloatingPoint}(a::Vector{Int}, n_quotients::Int, ::Type{T})
r = Array(T, n_quotients)
u = Array(T, n_quotients)
v = Array(T, n_quotients)
r[1],u[1],v[1] = a[1],0,1
for k=2:n_quotients
u[k] = 1 / (a[k] + u[k-1])
r[k] = (a[k]*r[k-1] + v[k-1]) * u[k]
v[k] = r[k-1] * u[k]
end
return r
end
It can be called, for example, by floatconvergents(some_vector, some_int, Float64)
.
Proof:
julia> f{T<:FloatingPoint}(::Type{T}) = T===Float64 ? 1 : 0
julia> code_llvm(f, (Type{Float64},))
define i64 @julia_f15644(%jl_value_t*) {
top:
ret i64 1, !dbg !2042
}
julia> code_llvm(f, (Type{BigFloat},))
define i64 @julia_f15645(%jl_value_t*) {
top:
ret i64 0, !dbg !2045
}