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