Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
number_rules.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//bertini2/io/parsers.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//bertini2/io/parsing/number_rules.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with bertini2/io/parsing/number_rules.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
22
28
29#pragma once
30
31
32
33
35
37
39
40
43 (obj.real(), obj.real(val))
44 (obj.imag(), obj.imag(val)))
45
46
47namespace bertini{
48 namespace parsing{
49
50
51
52 namespace qi = ::boost::spirit::qi;
53 namespace ascii = ::boost::spirit::ascii;
54
55 namespace rules{
61 template<typename Iterator>
62 struct LongNum
63 {
64 LongNum()
65 {
66 namespace phx = boost::phoenix;
67 using qi::_1;
68 using qi::_2;
69 using qi::_3;
70 using qi::_4;
71 using qi::_val;
72 using qi::eps;
73 using qi::lit;
74 using qi::char_;
75 using qi::omit;
76 using boost::spirit::lexeme;
77 using boost::spirit::as_string;
78 using boost::spirit::ascii::no_case;
79
80 number_string_.name("number_");
81 number_string_ =
82 long_number_string_
83 |
84 integer_string_;
85
86 integer_string_.name("integer_string_");
87 integer_string_ = eps[_val = std::string()] >>
88 -(qi::lit('-'))[_val += "-"] >>
89 number_with_no_point_ [_val += _1]
90 >> -exponent_notation_ [_val += _1];
91
92
93 long_number_string_.name("long_number_string_");
94 long_number_string_ = eps[_val = std::string()] >>
95 -(qi::lit('-'))[_val += "-"] >>
96 (
97 // 1. Read possible numbers before decimal, with possible negative
98 (number_with_digits_after_point_ [_val += _1]
99 |
100 number_with_digits_before_point_ [_val += _1] )
101 >> // reminder -- the - before the exponent_notation here means optional
102 -exponent_notation_ [_val+=_1]// Possible scientific notation, with possible negative in exponent.
103 );
104
105
106
107 number_with_digits_after_point_.name("number_with_digits_after_point_");
108 number_with_digits_after_point_ = eps[_val = std::string()]
109 >>
110 *(qi::char_(L'0',L'9')[_val += _1])
111 >>
112 qi::lit('.')[_val += "."] // find a decimal point
113 >>
114 +(qi::char_(L'0',L'9')[_val += _1]) // find at least one digit after the point
115 ;
116
117
118
119
120
121 number_with_digits_before_point_.name("number_with_digits_before_point_");
122 number_with_digits_before_point_ = eps[_val = std::string()]
123 >>
124 +(qi::char_(L'0',L'9')[_val += _1])
125 >>
126 qi::lit('.')[_val += "."] // find a decimal point
127 >>
128 *(qi::char_(L'0',L'9')[_val += _1]) // find any number of digits after the point
129 ;
130
131
132 number_with_no_point_.name("number_with_no_point_");
133 number_with_no_point_ = eps[_val = std::string()]
134 >>
135 (-(qi::lit('-')[_val += "-"]) // then an optional minus sign
136 >>
137 +(qi::char_(L'0',L'9'))[_val += _1])
138 ;
139
140
141
142
143 exponent_notation_.name("exponent_notation_");
144 exponent_notation_ = eps[_val = std::string()]
145 >> ( // start what the rule actually does
146 (
147 qi::lit('e')[_val += "e"] // get an opening 'e'
148 |
149 qi::lit('E')[_val += "e"] // get an opening 'e'
150 )
151 >>
152 -(qi::lit('-')[_val += "-"]) // then an optional minus sign
153 >>
154 +(qi::char_(L'0',L'9')[_val += _1]) // then at least one number
155 ); // finish the rule off
156
157 rational.name("long_rational");
158 rational =
159 (number_string_
160 |
161 (number_string_ >> char_('/') >> number_string_));
162
163 }
164
165
166
167 // these rules all produce strings which are fed into numbers.
168 qi::rule<Iterator, std::string()> number_string_, integer_string_, long_number_string_, number_with_digits_before_point_,
169 number_with_digits_after_point_, number_with_no_point_, exponent_notation_, rational;
170
171
172 }; //re: LongNum
173
174
175 } // namespace rules
176
177
178
179
180 }
181}
The main multiprecision complex number type.
Definition algorithm_builder.hpp:36
bmp::number< mpc_complex_backend< 0 >, bmp::et_on > complex_mp
The arbitrary-precision complex number type.
Definition mpfr_complex.hpp:58
Provides an Eigen-like NumTraits struct for querying traits of a number type.
BOOST_FUSION_ADAPT_ADT(bertini::complex_mp,(obj.real(), obj.real(val))(obj.imag(), obj.imag(val))) namespace bertini
Definition number_rules.hpp:41
Provides all the include files needed to develop a parsing file that uses boost qi.