1#ifndef LIBCPP_TEST_VALARRAY_HELPER_H
2#define LIBCPP_TEST_VALARRAY_HELPER_H
3
4#include <cmath>
5
6// Returns whether `x` and `y` are equal, up to the given number of
7// significant digits after the decimal.
8//
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.
13inline bool is_about(double x, double y, int significant_digits) {
14 double epsilon = std::pow(x: 1.0 / 10.0, y: significant_digits);
15 return std::abs(x: x - y) < epsilon;
16}
17
18#endif /* LIBCPP_TEST_VALARRAY_HELPER */
19

source code of libcxx/test/std/numerics/numarray/valarray.nonmembers/valarray.transcend/valarray_helper.h