Hi,
I was experimenting with @simd and was a bit surprised about some results
on different implementations of a plain summing function:
julia> f(a)
399921.25f0
julia> g(a)
399916.2f0
julia> sum(a)
399922.25f0
julia> sum_kbn(a)
399920.66f0
julia> @printf("%.6f",g(a))
399916.187500
I don't understand the behavior here: most of the time (not to say always
when using the REPL), I got 8 digits printed with 32 bit floats. The only
exception is when there are less than 8 significant digits. But here it's
not the case: why isn't g(a) displayed with 8 digits?
As an additional question: is there advanced string formatting available in
Julia? Like a format function or a judicious rem overloading?
Cheers,
Gaƫl
a = rand(Float32,800000)
function f{T}(a::Array{T,1})
s = zero(T)
@simd for i in 1:length(a)
@inbounds s = s + a[i]
end
return s
end
function g{T}(a::Array{T,1})
s = zero(T)
for i in 1:length(a)
@inbounds s = s + a[i]
end
return s
end