epsilonOf function

double epsilonOf(
  1. double value
)

Evaluates the minimum distance to the next distinguishable number near the argument value.

Evaluates the negative epsilon. The more common positive epsilon is equal to two times this negative epsilon.

Implementation

double epsilonOf(double value) {
  if (value.isInfinite || value.isNaN) {
    return double.nan;
  }

  var bytes = ByteData(8);
  bytes.setFloat64(0, value);
  int signed64 = bytes.getInt64(0);
  if (signed64 == 0) {
    signed64++;
    return int64BitsToDouble(signed64) - value;
  }
  if (signed64-- < 0) {
    return int64BitsToDouble(signed64) - value;
  }
  return value - int64BitsToDouble(signed64);
}