The function round.([0.1 ,-0.1]) returns minus zeros and positive zero.
Is there a way, that both will be just zero (positive).
I have this issue, since later I use unique([-0.0,0.0]), which give again two zeros: -0.0 and 0.0.
Thanks in advance.
The function round.([0.1 ,-0.1]) returns minus zeros and positive zero.
Is there a way, that both will be just zero (positive).
I have this issue, since later I use unique([-0.0,0.0]), which give again two zeros: -0.0 and 0.0.
Thanks in advance.
Short answer:
If you want to round to an integer, you can do the following:
julia> round.(Int, [-0.1,0.1])
2-element Vector{Int64}:
0
0
Another option is to convert the negative zeros to positive:
julia> round.([0.1 ,-0.1]) .+ 0
2-element Vector{Float64}:
0.0
0.0
What about defining your own rounding function?
function roundzero(x; kwargs...)
xrd = round(x;kwargs...)
xrd = ifelse(==(-zero(xrd)),zero(xrd))
return xrd
end