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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
// Copyright (c) 2001-2011 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include "real.hpp"
///////////////////////////////////////////////////////////////////////////////
int main()
{
using namespace boost::spirit;
{
///////////////////////////////////////////////////////////////////////
// use the default real_policies
BOOST_TEST(test("0.0", double_, 0.0));
BOOST_TEST(test("1.0", double_, 1.0));
BOOST_TEST(test("1.0", double_, 1.0001));
BOOST_TEST(test("1.001", double_, 1.001));
BOOST_TEST(test("1.01", double_, 1.010));
BOOST_TEST(test("1.1", double_, 1.100));
BOOST_TEST(test("1.234e-04", double_, 0.00012345));
BOOST_TEST(test("0.001", double_, 0.0012345));
BOOST_TEST(test("0.012", double_, 0.012345));
BOOST_TEST(test("0.123", double_, 0.12345));
BOOST_TEST(test("1.234", double_, 1.2345));
BOOST_TEST(test("12.346", double_, 12.346));
BOOST_TEST(test("123.46", double_, 123.46));
BOOST_TEST(test("1234.5", double_, 1234.5));
BOOST_TEST(test("12342.0", double_, 12342.));
BOOST_TEST(test("1.234e05", double_, 123420.));
BOOST_TEST(test("-1.0", double_, -1.0));
BOOST_TEST(test("-1.234", double_, -1.2345));
BOOST_TEST(test("-1.235", double_, -1.2346));
BOOST_TEST(test("-1234.2", double_, -1234.2));
BOOST_TEST(test("1.0", double_(1.0)));
BOOST_TEST(test("1.0", double_(1.0001)));
BOOST_TEST(test("1.001", double_(1.001)));
BOOST_TEST(test("1.01", double_(1.010)));
BOOST_TEST(test("1.1", double_(1.100)));
BOOST_TEST(test("1.234e-04", double_(0.00012345)));
BOOST_TEST(test("0.001", double_(0.0012345)));
BOOST_TEST(test("0.012", double_(0.012345)));
BOOST_TEST(test("0.123", double_(0.12345)));
BOOST_TEST(test("1.234", double_(1.2345)));
BOOST_TEST(test("12.346", double_(12.346)));
BOOST_TEST(test("123.46", double_(123.46)));
BOOST_TEST(test("1234.5", double_(1234.5)));
BOOST_TEST(test("12342.0", double_(12342.)));
BOOST_TEST(test("1.234e05", double_(123420.)));
}
{
///////////////////////////////////////////////////////////////////////
// test NaN and Inf
BOOST_TEST(test("nan", double_, std::numeric_limits<double>::quiet_NaN()));
BOOST_TEST(test("-nan", double_, -std::numeric_limits<double>::quiet_NaN()));
BOOST_TEST(test("inf", double_, std::numeric_limits<double>::infinity()));
BOOST_TEST(test("-inf", double_, -std::numeric_limits<double>::infinity()));
typedef karma::real_generator<double, signed_policy<double> > signed_type;
signed_type const signed_ = signed_type();
BOOST_TEST(test("+nan", signed_, std::numeric_limits<double>::quiet_NaN()));
BOOST_TEST(test("-nan", signed_, -std::numeric_limits<double>::quiet_NaN()));
BOOST_TEST(test("+inf", signed_, std::numeric_limits<double>::infinity()));
BOOST_TEST(test("-inf", signed_, -std::numeric_limits<double>::infinity()));
#if defined(BOOST_SPIRIT_ZERO_PROBLEM)
BOOST_TEST(test(" 0.0", signed_, 0.0));
#endif
BOOST_TEST(test("+nan", signed_(std::numeric_limits<double>::quiet_NaN())));
BOOST_TEST(test("-nan", signed_(-std::numeric_limits<double>::quiet_NaN())));
BOOST_TEST(test("+inf", signed_(std::numeric_limits<double>::infinity())));
BOOST_TEST(test("-inf", signed_(-std::numeric_limits<double>::infinity())));
#if defined(BOOST_SPIRIT_ZERO_PROBLEM)
BOOST_TEST(test(" 0.0", signed_(0.0)));
#endif
}
{
///////////////////////////////////////////////////////////////////////
typedef karma::real_generator<double, statefull_policy<double> >
statefull_type;
statefull_policy<double> policy(5, true);
statefull_type const statefull = statefull_type(policy);
BOOST_TEST(test("0.00000", statefull, 0.0));
BOOST_TEST(test("0.00000", statefull(0.0)));
using namespace boost::phoenix;
BOOST_TEST(test("0.00000", statefull(val(0.0))));
}
{
///////////////////////////////////////////////////////////////////////
typedef karma::real_generator<double, trailing_zeros_policy<double> >
trailing_zeros_type;
trailing_zeros_type const trail_zeros = trailing_zeros_type();
BOOST_TEST(test("0.0000", trail_zeros, 0.0));
BOOST_TEST(test("1.0000", trail_zeros, 1.0));
BOOST_TEST(test("1.0001", trail_zeros, 1.0001));
BOOST_TEST(test("1.0010", trail_zeros, 1.001));
BOOST_TEST(test("1.0100", trail_zeros, 1.010));
BOOST_TEST(test("1.1000", trail_zeros, 1.100));
BOOST_TEST(test("1.2345e-04", trail_zeros, 0.00012345));
BOOST_TEST(test("0.0012", trail_zeros, 0.0012345));
BOOST_TEST(test("0.0123", trail_zeros, 0.012345));
BOOST_TEST(test("0.1235", trail_zeros, 0.12345));
BOOST_TEST(test("1.2345", trail_zeros, 1.2345));
BOOST_TEST(test("12.3460", trail_zeros, 12.346));
BOOST_TEST(test("123.4600", trail_zeros, 123.46));
BOOST_TEST(test("1234.5000", trail_zeros, 1234.5));
BOOST_TEST(test("12342.0000", trail_zeros, 12342.));
BOOST_TEST(test("1.2342e05", trail_zeros, 123420.));
BOOST_TEST(test("-1.0000", trail_zeros, -1.0));
BOOST_TEST(test("-1.2345", trail_zeros, -1.2345));
BOOST_TEST(test("-1.2346", trail_zeros, -1.2346));
BOOST_TEST(test("-1234.2000", trail_zeros, -1234.2));
BOOST_TEST(test("1.0000", trail_zeros(1.0)));
BOOST_TEST(test("1.0001", trail_zeros(1.0001)));
BOOST_TEST(test("1.0010", trail_zeros(1.001)));
BOOST_TEST(test("1.0100", trail_zeros(1.010)));
BOOST_TEST(test("1.1000", trail_zeros(1.100)));
BOOST_TEST(test("1.2345e-04", trail_zeros(0.00012345)));
BOOST_TEST(test("0.0012", trail_zeros(0.0012345)));
BOOST_TEST(test("0.0123", trail_zeros(0.012345)));
BOOST_TEST(test("0.1235", trail_zeros(0.12345)));
BOOST_TEST(test("1.2345", trail_zeros(1.2345)));
BOOST_TEST(test("12.3460", trail_zeros(12.346)));
BOOST_TEST(test("123.4600", trail_zeros(123.46)));
BOOST_TEST(test("1234.5000", trail_zeros(1234.5)));
BOOST_TEST(test("12342.0000", trail_zeros(12342.)));
BOOST_TEST(test("1.2342e05", trail_zeros(123420.)));
}
{
using namespace boost::spirit::ascii;
///////////////////////////////////////////////////////////////////////
// test NaN and Inf
BOOST_TEST(test("NAN", upper[double_],
std::numeric_limits<double>::quiet_NaN()));
BOOST_TEST(test("-NAN", upper[double_],
-std::numeric_limits<double>::quiet_NaN()));
BOOST_TEST(test("INF", upper[double_],
std::numeric_limits<double>::infinity()));
BOOST_TEST(test("-INF", upper[double_],
-std::numeric_limits<double>::infinity()));
typedef karma::real_generator<double, signed_policy<double> > signed_type;
signed_type const signed_ = signed_type();
BOOST_TEST(test("+NAN", upper[signed_],
std::numeric_limits<double>::quiet_NaN()));
BOOST_TEST(test("-NAN", upper[signed_],
-std::numeric_limits<double>::quiet_NaN()));
BOOST_TEST(test("+INF", upper[signed_],
std::numeric_limits<double>::infinity()));
BOOST_TEST(test("-INF", upper[signed_],
-std::numeric_limits<double>::infinity()));
#if defined(BOOST_SPIRIT_ZERO_PROBLEM)
BOOST_TEST(test(" 0.0", upper[signed_], 0.0));
#endif
}
return boost::report_errors();
}
|