utils.dart 590 Bytes
Newer Older
1
// Copyright 2016 The Chromium Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Ian Hickson's avatar
Ian Hickson committed
5 6 7
/// Whether two doubles are within a given distance of each other.
///
/// The epsilon argument must be positive.
8 9 10 11
bool nearEqual(double a, double b, double epsilon) {
  assert(epsilon >= 0.0);
  return (a > (b - epsilon)) && (a < (b + epsilon));
}
12

Ian Hickson's avatar
Ian Hickson committed
13 14 15
/// Whether a double is within a given distance of zero.
///
/// The epsilon argument must be positive.
16
bool nearZero(double a, double epsilon) => nearEqual(a, 0.0, epsilon);