chop - multiple declarations

Function chop

Replaces real numbers that are close to zero by exactly zero.

Real chop(Real) (
  Real x,
  real threshold = 1e-10L
) pure nothrow
if (isFloatingPoint!Real);
assert (chop(1.0) == 1.0);
assert (chop(1e-20) == 0.0);

Function 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.

Real[] chop(Real) (
  Real[] x,
  real threshold = 1e-10L,
  Real[] buffer = null
) nothrow
if (isFloatingPoint!Real);
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);