1111
1212#include " src/__support/FPUtil/FEnvImpl.h"
1313#include " src/__support/FPUtil/FPBits.h"
14+ #include " test/UnitTest/StringUtils.h"
1415#include " test/UnitTest/Test.h"
1516#include " utils/testutils/RoundingModeUtils.h"
1617
@@ -20,9 +21,42 @@ namespace __llvm_libc {
2021namespace fputil {
2122namespace testing {
2223
23- template <typename ValType, typename StreamType >
24+ template <typename ValType>
2425cpp::enable_if_t <cpp::is_floating_point_v<ValType>, void >
25- describeValue (const char *label, ValType value, StreamType &stream);
26+ describeValue (const char *label, ValType value) {
27+ __llvm_libc::testing::tlog << label;
28+
29+ FPBits<ValType> bits (value);
30+ if (bits.is_nan ()) {
31+ __llvm_libc::testing::tlog << " (NaN)" ;
32+ } else if (bits.is_inf ()) {
33+ if (bits.get_sign ())
34+ __llvm_libc::testing::tlog << " (-Infinity)" ;
35+ else
36+ __llvm_libc::testing::tlog << " (+Infinity)" ;
37+ } else {
38+ constexpr int exponentWidthInHex =
39+ (fputil::ExponentWidth<ValType>::VALUE - 1 ) / 4 + 1 ;
40+ constexpr int mantissaWidthInHex =
41+ (fputil::MantissaWidth<ValType>::VALUE - 1 ) / 4 + 1 ;
42+ constexpr int bitsWidthInHex =
43+ sizeof (typename fputil::FPBits<ValType>::UIntType) * 2 ;
44+
45+ __llvm_libc::testing::tlog
46+ << " 0x"
47+ << int_to_hex<typename fputil::FPBits<ValType>::UIntType>(
48+ bits.uintval (), bitsWidthInHex)
49+ << " , (S | E | M) = (" << (bits.get_sign () ? ' 1' : ' 0' ) << " | 0x"
50+ << int_to_hex<uint16_t >(bits.get_unbiased_exponent (),
51+ exponentWidthInHex)
52+ << " | 0x"
53+ << int_to_hex<typename fputil::FPBits<ValType>::UIntType>(
54+ bits.get_mantissa (), mantissaWidthInHex)
55+ << " )" ;
56+ }
57+
58+ __llvm_libc::testing::tlog << ' \n ' ;
59+ }
2660
2761template <typename T, __llvm_libc::testing::TestCondition Condition>
2862class FPMatcher : public __llvm_libc ::testing::Matcher<T> {
@@ -52,9 +86,9 @@ class FPMatcher : public __llvm_libc::testing::Matcher<T> {
5286 (actualBits.uintval () != expectedBits.uintval ());
5387 }
5488
55- void explainError (testutils::StreamWrapper &stream ) override {
56- describeValue (" Expected floating point value: " , expected, stream );
57- describeValue (" Actual floating point value: " , actual, stream );
89+ void explainError () override {
90+ describeValue (" Expected floating point value: " , expected);
91+ describeValue (" Actual floating point value: " , actual);
5892 }
5993};
6094
0 commit comments