1 #ifndef LIBCPP_TEST_VALARRAY_HELPER_H
2 #define LIBCPP_TEST_VALARRAY_HELPER_H
6 // Returns whether `x` and `y` are equal, up to the given number of
7 // significant digits after the decimal.
9 // Specifically, we look whether `abs(x - y) < epsilon`, where epsilon
10 // is `(1 / 10)^p`, assuming p is the number of digits we care about.
11 // This means we're basically looking whether `abs(x - y)` is less
12 // than `0.00..001` for some number of digits.
13 inline bool is_about(double x
, double y
, int significant_digits
) {
14 double epsilon
= std::pow(1.0 / 10.0, significant_digits
);
15 return std::abs(x
- y
) < epsilon
;
18 #endif /* LIBCPP_TEST_VALARRAY_HELPER */