ZChop.jl was written in December 2015. This is the first version with a new feature: Functions nchop
and nchop!
. This represents the culmination of a few hours of work.
EDIT: The original function zchop
does this:
zchop(x) replaces numbers in x that are close to zero with zero.
zchop(x) returns 0 if abs(x) is smaller than 1e-14, and x otherwise.
zchop(x,eps) uses eps rather than 1e-14
zchop!(a,eps) works inplace on Arrays and nested Arrays.
I added nchop
in response to a slack post by @staticfloat . Following the example in that post
julia> x = [7.401486830834377e-17 + 3.700743415417188e-17im
8.26024732898714e-17 + 7.020733317042351e-17im
0.9999999999999997 + 1.0000000000000002im
-1.0177044392397268e-16 - 6.476300976980079e-17im
0.0 - 7.401486830834377e-17im
-4.5595039135699516e-17 - 2.1823706978711105e-16im
1.2952601953960158e-16 + 0.0im
-2.1079998571544233e-16 + 5.303212320736824e-17im
0.0 - 7.401486830834377e-17im
-6.476300976980079e-17 + 2.498001805406602e-16im
7.401486830834377e-17 - 1.4802973661668753e-16im
1.7379255156127046e-16 + 2.0982745100975517e-17im]
julia> nchop(x)
12-element Vector{ComplexF64}:
0.0 + 0.0im
0.0 + 0.0im
1.0 + 1.0im
-0.0 - 0.0im
0.0 - 0.0im
-0.0 - 0.0im
0.0 + 0.0im
-0.0 + 0.0im
0.0 - 0.0im
-0.0 + 0.0im
0.0 - 0.0im
0.0 + 0.0im
You could get the same result with round.(x; digits=12)
(maybe you have to look it up first). Or, as in the slack post, Base.show(io::IO, f::Float64) = @printf(io, "%.2f", f)
!
But, there are other features, efficiency, nchop!
, zchop
, and zchop!
, which would require some thought and different incantations of round
.