Skip to content

Commit 205d399

Browse files
authored
[libcxx] [test] Clarify the condition for long double hex formatting (#135334)
This test currently hardcodes which environments have got 80 bit long doubles on x86_64 with a suitable printf formatting; convert the architecture check into a check specifically for 80 bit long doubles. Not all x86_64 configurations do have 80 bit long doubles (e.g. Android doesn't), and i386 configurations can also have 80 bit long doubles, compatible with this test. Also clarify the exact reasons for why specific OSes such as FreeBSD are skipped for these tests, even though they have 80 bit long doubles.
1 parent 8c2233b commit 205d399

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.hex.pass.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,11 +1846,25 @@ void test1() {
18461846
void test2() {
18471847
std::locale lc = std::locale::classic();
18481848
std::locale lg(lc, new my_numpunct);
1849-
#if (defined(__APPLE__) || defined(TEST_HAS_GLIBC) || defined(__MINGW32__)) && defined(__x86_64__)
1850-
// This test is failing on FreeBSD, possibly due to different representations
1851-
// of the floating point numbers.
1852-
// This test is failing in MSVC environments, where long double is equal to regular
1853-
// double, and instead of "0x9.32c05a44p+27", this prints "0x1.26580b4880000p+30".
1849+
#if (defined(__APPLE__) || defined(TEST_HAS_GLIBC) || defined(__MINGW32__)) && defined(TEST_LONG_DOUBLE_IS_80_BIT)
1850+
// This test assumes that long doubles are x87 80 bit long doubles, and
1851+
// assumes one specific way of formatting the long doubles. (There are
1852+
// multiple valid ways of hex formatting the same float.)
1853+
//
1854+
// FreeBSD does use x87 80 bit long doubles, but normalizes the hex floats
1855+
// differently.
1856+
//
1857+
// This test assumes the form used by Glibc, Darwin and others, where the
1858+
// 64 mantissa bits are grouped by nibble as they are stored in the long
1859+
// double representation (nibble aligned at the end of the least significant
1860+
// bits). This makes 1.0L to be formatted as "0x8p-3" (where the leading
1861+
// bit of the mantissa is the higest bit in the 0x8 nibble), and makes
1862+
// __LDBL_MAX__ be formatted as "0xf.fffffffffffffffp+16380".
1863+
//
1864+
// FreeBSD normalizes/aligns the leading bit of the mantissa as a separate
1865+
// nibble, so that 1.0L is formatted as "0x1p+0" and __LDBL_MAX__ as
1866+
// "0x1.fffffffffffffffep+16383" (note the lowest bit of the last nibble
1867+
// being zero as the nibbles don't align to the actual floats).
18541868
const my_facet f(1);
18551869
char str[200];
18561870
{

libcxx/test/support/test_macros.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,4 +544,8 @@ inline Tp const& DoNotOptimize(Tp const& value) {
544544
# define TEST_LONG_DOUBLE_IS_DOUBLE
545545
#endif
546546

547+
#if defined(__LDBL_MANT_DIG__) && __LDBL_MANT_DIG__ == 64
548+
# define TEST_LONG_DOUBLE_IS_80_BIT
549+
#endif
550+
547551
#endif // SUPPORT_TEST_MACROS_HPP

0 commit comments

Comments
 (0)