blob: 82e696fa797c525feac21c45c3ac4eb9dd05fb3a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// { dg-do run { target c++20 } }
#include <format>
#include <testsuite_hooks.h>
template<typename T>
bool format_float()
{
auto s = std::format("{:#} != {:<+7.3f}", (T)-0.0, (T)0.5);
return s == "-0. != +0.500 ";
}
#if __cplusplus > 202002L
template<typename T>
concept formattable = std::formattable<T, char>;
#else
template<typename T>
concept formattable = std::semiregular<std::formatter<T, char>>;
#endif
void
test_float16()
{
#if __FLT16_DIG__
if constexpr (formattable<_Float16>)
VERIFY( format_float<_Float16>() );
else
std::puts("Cannot format _Float16 on this target");
#endif
}
void
test_float32()
{
#if __FLT32_DIG__
if constexpr (formattable<_Float32>)
VERIFY( format_float<_Float32>() );
else
std::puts("Cannot format _Float32 on this target");
#endif
}
void
test_float64()
{
#if __FLT64_DIG__
if constexpr (formattable<_Float64>)
VERIFY( format_float<_Float64>() );
else
std::puts("Cannot format _Float64 on this target");
#endif
}
void
test_float128()
{
#ifdef __SIZEOF_FLOAT128__
if constexpr (formattable<__float128>)
VERIFY( format_float<__float128>() );
else
std::puts("Cannot format __float128 on this target");
#endif
#if __FLT128_DIG__
if constexpr (formattable<_Float128>)
VERIFY( format_float<_Float128>() );
else
std::puts("Cannot format _Float128 on this target");
#endif
}
void
test_bfloat16()
{
#if __BFLT16_DIG__
using bfloat16_t = decltype(0.0bf16);
if constexpr (formattable<bfloat16_t>)
VERIFY( format_float<bfloat16_t>() );
else
std::puts("Cannot format bfloat16_t on this target");
#endif
}
int main()
{
test_float16();
test_float32();
test_float64();
test_float128();
test_bfloat16();
}
|