brintos

brintos / llvm-project-archived public Read only

0
0
Text · 674 B · d68dac0 Raw
19 lines · c
1#ifndef LIBCPP_TEST_VALARRAY_HELPER_H2#define LIBCPP_TEST_VALARRAY_HELPER_H3 4#include <cmath>5 6// Returns whether `x` and `y` are equal, up to the given number of7// significant digits after the decimal.8//9// Specifically, we look whether `abs(x - y) < epsilon`, where epsilon10// 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 less12// 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(1.0 / 10.0, significant_digits);15    return std::abs(x - y) < epsilon;16}17 18#endif /* LIBCPP_TEST_VALARRAY_HELPER */19