I am writing some signal processing code, and I want to be able to call it for both real and complex signals, based on either Float32 or Float64. I make no use of the real and imaginary parts of the signals (the function is a simple interpolator using Lagrange polynomials).
Right now I define my functions as
function foo(x::Vector{T}, t::T) where T <: AbstractFloat
tmp = T(0)
...
end
function foo(x::Vector{Complex{T}}, t::T) where T <: AbstractFloat
tmp = T(0)
...
end
where the complex version is identical to the real. This is not a good way to organise ones code, so I wonder if there is any way I can write this function once for all four types? I could of course not use typing in the function argument list, but then I could get a mix of doubles and floats as arguments. Any ideas or hints?
(I guess this is one example of type traits having been useful)
I see what you mean, but in this particular case I would probably do eg. Integer implementations slightly differently due to under- and overflows etc. One of the purposes of my code is to simulate implementations on embedded hw, so that is why I need it to be eg. pure Float32 in those cases so that I don’t miss any round-off effects somewhere…
AbstractFloat covers four types of floats which will be used identically.