]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/test/karma/real3.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / spirit / test / karma / real3.cpp
CommitLineData
1e59de90 1// Copyright (c) 2001-2020 Hartmut Kaiser
7c673cae
FG
2// Copyright (c) 2011 Bryce Lelbach
3//
4// Distributed under the Boost Software License, Version 1.0. (See accompanying
5// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
1e59de90
TL
7#include "real.hpp"
8
7c673cae 9#include <boost/spirit/include/version.hpp>
92f5a8d4 10#include <boost/spirit/include/karma_phoenix_attributes.hpp>
1e59de90
TL
11#include <boost/phoenix/core.hpp>
12#include <boost/phoenix/operator.hpp>
7c673cae
FG
13
14///////////////////////////////////////////////////////////////////////////////
1e59de90 15#ifndef BOOST_SPIRIT_NO_MATH_REAL_CONCEPT
7c673cae
FG
16// does not provide proper std::numeric_limits, we need to roll our own
17namespace boost { namespace spirit { namespace traits
18{
19 template <>
20 struct is_nan<boost::math::concepts::real_concept>
21 {
22 static bool call(boost::math::concepts::real_concept n)
23 {
24 return test_nan(n.value());
25 }
26 };
27
28 template <>
29 struct is_infinite<boost::math::concepts::real_concept>
30 {
31 static bool call(boost::math::concepts::real_concept n)
32 {
33 return test_infinite(n.value());
34 }
35 };
36}}}
37#endif
38
39///////////////////////////////////////////////////////////////////////////////
40int main()
41{
42 using namespace boost::spirit;
43
44 {
45 using namespace boost::spirit::ascii;
46
47 ///////////////////////////////////////////////////////////////////////
48 typedef karma::real_generator<double, fixed_policy<double> > fixed_type;
49 fixed_type const fixed = fixed_type();
50
51 BOOST_TEST(test("0.0", fixed, 0.0));
52 BOOST_TEST(test("1.0", fixed, 1.0));
53
54 BOOST_TEST(test("0.0", fixed, 0.000012345));
55 BOOST_TEST(test("0.0", fixed, 0.00012345));
56 BOOST_TEST(test("0.001", fixed, 0.0012345));
57 BOOST_TEST(test("0.012", fixed, 0.012345));
58 BOOST_TEST(test("0.123", fixed, 0.12345));
59 BOOST_TEST(test("1.234", fixed, 1.2345));
60 BOOST_TEST(test("12.345", fixed, 12.345));
61 BOOST_TEST(test("123.45", fixed, 123.45));
62 BOOST_TEST(test("1234.5", fixed, 1234.5));
63 BOOST_TEST(test("12342.0", fixed, 12342.));
64 BOOST_TEST(test("123420.0", fixed, 123420.));
65 BOOST_TEST(test("123420000000000000000.0", fixed, 1.23420e20));
66
67 BOOST_TEST(test("0.0", fixed, -0.000012345));
68 BOOST_TEST(test("0.0", fixed, -0.00012345));
69 BOOST_TEST(test("-0.001", fixed, -0.0012345));
70 BOOST_TEST(test("-0.012", fixed, -0.012345));
71 BOOST_TEST(test("-0.123", fixed, -0.12345));
72 BOOST_TEST(test("-1.234", fixed, -1.2345));
73 BOOST_TEST(test("-12.346", fixed, -12.346));
74 BOOST_TEST(test("-123.46", fixed, -123.46));
75 BOOST_TEST(test("-1234.5", fixed, -1234.5));
76 BOOST_TEST(test("-12342.0", fixed, -12342.));
77 BOOST_TEST(test("-123420.0", fixed, -123420.));
78 BOOST_TEST(test("-123420000000000000000.0", fixed, -1.23420e20));
79 }
80
1e59de90 81#ifndef BOOST_SPIRIT_NO_MATH_REAL_CONCEPT
7c673cae
FG
82 {
83 using boost::math::concepts::real_concept;
84 typedef karma::real_generator<real_concept> custom_type;
85 custom_type const custom = custom_type();
86
87 BOOST_TEST(test("0.0", custom, real_concept(0.0)));
88 BOOST_TEST(test("1.0", custom, real_concept(1.0)));
89 BOOST_TEST(test("1.0", custom, real_concept(1.0001)));
90 BOOST_TEST(test("1.001", custom, real_concept(1.001)));
91 BOOST_TEST(test("1.01", custom, real_concept(1.010)));
92 BOOST_TEST(test("1.1", custom, real_concept(1.100)));
93
94 BOOST_TEST(test("1.234e-04", custom, real_concept(0.00012345)));
95 BOOST_TEST(test("0.001", custom, real_concept(0.0012345)));
96 BOOST_TEST(test("0.012", custom, real_concept(0.012345)));
97 BOOST_TEST(test("0.123", custom, real_concept(0.12345)));
98 BOOST_TEST(test("1.234", custom, real_concept(1.2345)));
99 BOOST_TEST(test("12.346", custom, real_concept(12.346)));
100 BOOST_TEST(test("123.46", custom, real_concept(123.46)));
101 BOOST_TEST(test("1234.5", custom, real_concept(1234.5)));
102 BOOST_TEST(test("12342.0", custom, real_concept(12342.)));
103 BOOST_TEST(test("1.234e05", custom, real_concept(123420.)));
104
105 BOOST_TEST(test("-1.0", custom, real_concept(-1.0)));
106 BOOST_TEST(test("-1.234", custom, real_concept(-1.2345)));
107 BOOST_TEST(test("-1.235", custom, real_concept(-1.2346)));
108 BOOST_TEST(test("-1234.2", custom, real_concept(-1234.2)));
109
110 BOOST_TEST(test("1.0", custom(real_concept(1.0))));
111 BOOST_TEST(test("1.0", custom(real_concept(1.0001))));
112 BOOST_TEST(test("1.001", custom(real_concept(1.001))));
113 BOOST_TEST(test("1.01", custom(real_concept(1.010))));
114 BOOST_TEST(test("1.1", custom(real_concept(1.100))));
115
116 BOOST_TEST(test("1.234e-04", custom(real_concept(0.00012345))));
117 BOOST_TEST(test("0.001", custom(real_concept(0.0012345))));
118 BOOST_TEST(test("0.012", custom(real_concept(0.012345))));
119 BOOST_TEST(test("0.123", custom(real_concept(0.12345))));
120 BOOST_TEST(test("1.234", custom(real_concept(1.2345))));
121 BOOST_TEST(test("12.346", custom(real_concept(12.346))));
122 BOOST_TEST(test("123.46", custom(real_concept(123.46))));
123 BOOST_TEST(test("1234.5", custom(real_concept(1234.5))));
124 BOOST_TEST(test("12342.0", custom(real_concept(12342.))));
125 BOOST_TEST(test("1.234e05", custom(real_concept(123420.))));
126 }
127#endif
128
129// this appears to be broken on Apple Tiger x86 with gcc4.0.1
130#if (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__ != 40001) || \
131 !defined(__APPLE__)
132 {
133 ///////////////////////////////////////////////////////////////////////
134 typedef karma::real_generator<double, bordercase_policy<double> >
135 bordercase_type;
136 bordercase_type const bordercase = bordercase_type();
137
138// BOOST_TEST(test("-5.7222349715140557e307",
139// bordercase(-5.7222349715140557e307)));
140
141 BOOST_TEST(test("1.7976931348623158e308",
142 bordercase(1.7976931348623158e308))); // DBL_MAX
143 BOOST_TEST(test("-1.7976931348623158e308",
144 bordercase(-1.7976931348623158e308))); // -DBL_MAX
145 BOOST_TEST(test("2.2250738585072014e-308",
146 bordercase(2.2250738585072014e-308))); // DBL_MIN
147 BOOST_TEST(test("-2.2250738585072014e-308",
148 bordercase(-2.2250738585072014e-308))); // -DBL_MIN
149 }
150#endif
151
152 {
153 boost::optional<double> v;
154 BOOST_TEST(!test("", double_, v));
155 BOOST_TEST(!test("", double_(1.0), v));
156
157 v = 1.0;
158 BOOST_TEST(test("1.0", double_, v));
159 BOOST_TEST(test("1.0", double_(1.0), v));
160 }
161
7c673cae
FG
162 { // Phoenix expression tests (requires to include
163 // karma_phoenix_attributes.hpp)
164 namespace phoenix = boost::phoenix;
165
166 BOOST_TEST(test("1.0", double_, phoenix::val(1.0)));
167
168 double d = 1.2;
169 BOOST_TEST(test("1.2", double_, phoenix::ref(d)));
170 BOOST_TEST(test("2.2", double_, ++phoenix::ref(d)));
171 }
7c673cae 172
11fdf7f2
TL
173 // test for denormalized numbers
174 {
175 BOOST_TEST(test("4.941e-324", double_, std::numeric_limits<double>::denorm_min()));
176 }
1e59de90
TL
177
178 // test for #628: spirit::karma::generate generates 10.0e-04, but expecting 1.0e-03
179 {
180 BOOST_TEST(test("1.0", double_, 0.99999999999999829));
181 BOOST_TEST(test("0.1", double_, 0.099999999999999829));
182 BOOST_TEST(test("0.01", double_, 0.0099999999999999829));
183 BOOST_TEST(test("1.0e-03", double_, 0.00099999999999999829));
184 BOOST_TEST(test("1.0e-04", double_, 0.00009999999999999982));
185 BOOST_TEST(test("1.0e-05", double_, 0.00000999999999999998));
186 }
187
7c673cae
FG
188 return boost::report_errors();
189}
190