Skip to content

Commit 648609c

Browse files
authored
Merge pull request #781 from cppalliance/capital_format
Capital format
2 parents 7df9c21 + 38d91c4 commit 648609c

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

examples/format.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
// Distributed under the Boost Software License, Version 1.0.
33
// https://www.boost.org/LICENSE_1_0.txt
44

5-
// MSVC 14.3 has a conversion error in <algorithm> so we need to try and supress that everywhere
6-
#ifdef _MSC_VER
7-
# pragma warning(push)
8-
# pragma warning(disable : 4244)
9-
#endif
10-
115
#include <boost/decimal.hpp>
126
#include <iostream>
137

include/boost/decimal/format.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ constexpr auto parse_impl(ParseContext &ctx)
7070
break;
7171

7272
case 'F':
73+
is_upper = true;
7374
[[fallthrough]];
7475
case 'f':
7576
fmt = chars_format::fixed;
@@ -142,9 +143,18 @@ struct formatter<T>
142143

143144
if (is_upper)
144145
{
146+
#ifdef _MSC_VER
147+
# pragma warning(push)
148+
# pragma warning(disable : 4244)
149+
#endif
150+
145151
std::transform(s.begin(), s.end(), s.begin(),
146152
[](unsigned char c)
147153
{ return std::toupper(c); });
154+
155+
#ifdef _MSC_VER
156+
# pragma warning(pop)
157+
#endif
148158
}
149159

150160
if (s.size() < static_cast<std::size_t>(padding_digits))

test/test_format.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
// Distributed under the Boost Software License, Version 1.0.
33
// https://www.boost.org/LICENSE_1_0.txt
44

5-
// MSVC 14.3 has a conversion error in <algorithm> so we need to try and supress that everywhere
6-
#ifdef _MSC_VER
7-
# pragma warning(push)
8-
# pragma warning(disable : 4244)
9-
#endif
10-
115
#include <boost/decimal.hpp>
126
#include <boost/core/lightweight_test.hpp>
137
#include <limits>
@@ -16,7 +10,7 @@ using namespace boost::decimal;
1610

1711
#ifdef BOOST_DECIMAL_HAS_FORMAT_SUPPORT
1812

19-
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
13+
template <concepts::decimal_floating_point_type T>
2014
void test_general()
2115
{
2216
// For unknown reasons Clang does not like this empty bracket and throws compiler errors
@@ -82,6 +76,13 @@ void test_general()
8276
BOOST_TEST_EQ(std::format("{:g}", -std::numeric_limits<T>::quiet_NaN()), "-nan(ind)");
8377
BOOST_TEST_EQ(std::format("{:g}", std::numeric_limits<T>::signaling_NaN()), "nan(snan)");
8478
BOOST_TEST_EQ(std::format("{:g}", -std::numeric_limits<T>::signaling_NaN()), "-nan(snan)");
79+
80+
BOOST_TEST_EQ(std::format("{:G}", std::numeric_limits<T>::infinity()), "INF");
81+
BOOST_TEST_EQ(std::format("{:G}", -std::numeric_limits<T>::infinity()), "-INF");
82+
BOOST_TEST_EQ(std::format("{:G}", std::numeric_limits<T>::quiet_NaN()), "NAN");
83+
BOOST_TEST_EQ(std::format("{:G}", -std::numeric_limits<T>::quiet_NaN()), "-NAN(IND)");
84+
BOOST_TEST_EQ(std::format("{:G}", std::numeric_limits<T>::signaling_NaN()), "NAN(SNAN)");
85+
BOOST_TEST_EQ(std::format("{:G}", -std::numeric_limits<T>::signaling_NaN()), "-NAN(SNAN)");
8586
}
8687

8788
template <concepts::decimal_floating_point_type T>
@@ -106,6 +107,13 @@ void test_fixed()
106107
BOOST_TEST_EQ(std::format("{:f}", -std::numeric_limits<T>::quiet_NaN()), "-nan(ind)");
107108
BOOST_TEST_EQ(std::format("{:f}", std::numeric_limits<T>::signaling_NaN()), "nan(snan)");
108109
BOOST_TEST_EQ(std::format("{:f}", -std::numeric_limits<T>::signaling_NaN()), "-nan(snan)");
110+
111+
BOOST_TEST_EQ(std::format("{:F}", std::numeric_limits<T>::infinity()), "INF");
112+
BOOST_TEST_EQ(std::format("{:F}", -std::numeric_limits<T>::infinity()), "-INF");
113+
BOOST_TEST_EQ(std::format("{:F}", std::numeric_limits<T>::quiet_NaN()), "NAN");
114+
BOOST_TEST_EQ(std::format("{:F}", -std::numeric_limits<T>::quiet_NaN()), "-NAN(IND)");
115+
BOOST_TEST_EQ(std::format("{:F}", std::numeric_limits<T>::signaling_NaN()), "NAN(SNAN)");
116+
BOOST_TEST_EQ(std::format("{:F}", -std::numeric_limits<T>::signaling_NaN()), "-NAN(SNAN)");
109117
}
110118

111119
template <concepts::decimal_floating_point_type T>
@@ -127,6 +135,13 @@ void test_scientific()
127135
BOOST_TEST_EQ(std::format("{:e}", std::numeric_limits<T>::signaling_NaN()), "nan(snan)");
128136
BOOST_TEST_EQ(std::format("{:e}", -std::numeric_limits<T>::signaling_NaN()), "-nan(snan)");
129137

138+
BOOST_TEST_EQ(std::format("{:E}", std::numeric_limits<T>::infinity()), "INF");
139+
BOOST_TEST_EQ(std::format("{:E}", -std::numeric_limits<T>::infinity()), "-INF");
140+
BOOST_TEST_EQ(std::format("{:E}", std::numeric_limits<T>::quiet_NaN()), "NAN");
141+
BOOST_TEST_EQ(std::format("{:E}", -std::numeric_limits<T>::quiet_NaN()), "-NAN(IND)");
142+
BOOST_TEST_EQ(std::format("{:E}", std::numeric_limits<T>::signaling_NaN()), "NAN(SNAN)");
143+
BOOST_TEST_EQ(std::format("{:E}", -std::numeric_limits<T>::signaling_NaN()), "-NAN(SNAN)");
144+
130145
// Padding to the front
131146
BOOST_TEST_EQ(std::format("{:10.1E}", T {0}), " 0.0E+00");
132147
BOOST_TEST_EQ(std::format("{:10.3E}", T {0}), " 0.000E+00");
@@ -143,6 +158,13 @@ void test_hex()
143158
BOOST_TEST_EQ(std::format("{:a}", -std::numeric_limits<T>::quiet_NaN()), "-nan(ind)");
144159
BOOST_TEST_EQ(std::format("{:a}", std::numeric_limits<T>::signaling_NaN()), "nan(snan)");
145160
BOOST_TEST_EQ(std::format("{:a}", -std::numeric_limits<T>::signaling_NaN()), "-nan(snan)");
161+
162+
BOOST_TEST_EQ(std::format("{:A}", std::numeric_limits<T>::infinity()), "INF");
163+
BOOST_TEST_EQ(std::format("{:A}", -std::numeric_limits<T>::infinity()), "-INF");
164+
BOOST_TEST_EQ(std::format("{:A}", std::numeric_limits<T>::quiet_NaN()), "NAN");
165+
BOOST_TEST_EQ(std::format("{:A}", -std::numeric_limits<T>::quiet_NaN()), "-NAN(IND)");
166+
BOOST_TEST_EQ(std::format("{:A}", std::numeric_limits<T>::signaling_NaN()), "NAN(SNAN)");
167+
BOOST_TEST_EQ(std::format("{:A}", -std::numeric_limits<T>::signaling_NaN()), "-NAN(SNAN)");
146168
}
147169

148170
int main()

0 commit comments

Comments
 (0)