chop

Replaces all numbers in the given array that are close to zero by exactly zero. To chop the array in-place, pass the same array as both x and buffer.

double[] a = [1.0, 1e-20, 2.0];
double[] x = [1.0, 0.0, 2.0];
auto b = chop(a);
assert (b == x);
chop(a, 1e-12L, a);
assert (a == x);
  1. Real chop(Real x, real threshold)
  2. Real[] chop(Real[] x, real threshold, Real[] buffer)
    nothrow
    Real[]
    chop
    (
    Real
    )
    (
    Real[] x
    ,
    real threshold = 1e-10L
    ,
    Real[] buffer = null
    )
    if (
    isFloatingPoint!Real
    )

Meta