google / google/truth

Support approximately-equal floating point assertions using ULPs

Open
#690 10 comments 0 reactions 0 assignees View on GitHub
P3 type=addition type=documentation
Dominant language
Java
Stars
2.8k
Forks
275
Avg merge
7m
Merged PRs (30d)
4

Description

Google's C++ test framework supports [approximate comparison of floating point numbers ](https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#floating-point-comparison) without requiring the user specify a precision (though that's available too). The `ASSERT_DOUBLE_EQ`/`ASSERT_FLOAT_EQ` macros assert that two numbers are [within four ULPs of one another](https://github.com/google/googletest/blob/472cd8fd8b1c665bddfd021ad0f62d6747fe8e72/googletest/include/gtest/internal/gtest-internal.h#L346), which (the documentations claims) should work well enough for most use-cases.

I'm *sure* this has been discussed before, so apologies if I'm dredging up something that's already been long-decided. But if ULP-based assertions are intentionally absent from `DoubleSubject` and `FloatSubject` I think the documentation should explain why that decision was made and what users should do instead. Currently the class makes no mention of ULPs, and expects callers to always pick an appropriate `tolerance`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.