Function matchDigits

Check whether lhs and rhs are equal to within the specified number of significant digits. Both lhs and rhs can be floating-point numbers, complex numbers, or input ranges of floating-point or complex numbers.

bool matchDigits(L, R) (
  L lhs,
  R rhs,
  uint significantDigits = 6,
  real maxAbsDiff = 1e-20
)
if ((isFloatingPoint!L || is(L T == Complex!T)) && (isFloatingPoint!R || is(R U == Complex!U)));

bool matchDigits(L, R) (
  L lhs,
  R rhs,
  uint significantDigits = 6,
  real maxAbsDiff = 1e-20
)
if (isInputRange!L || isInputRange!R);
assert (matchDigits(0.1234567, 0.1234568));

Note that numbers which are very close to zero should normally be compared using an absolute difference criterion. This can be specified using an optional parameter, and is by default set to 1e-20. Set it to zero if you do not want to use the absolute difference at all.