1 // DO NOT EDIT!
2 // Generated automatically from ../liboctave/numeric/Quad-opts.in.
3
4 // This file should not include config.h. It is only included in other
5 // C++ source files that should have included config.h before including
6 // this file.
7
8 #include <iomanip>
9 #include <ostream>
10 #include <sstream>
11
12 #include "Quad-opts.h"
13
14 #include "defun.h"
15 #include "pr-output.h"
16
17 #include "ovl.h"
18 #include "utils.h"
19 #include "pager.h"
20
21 static Quad_options quad_opts;
22
23 #define MAX_TOKENS 4
24
25 struct Quad_options_struct
26 {
27 const char *keyword;
28 const char *kw_tok[MAX_TOKENS + 1];
29 int min_len[MAX_TOKENS + 1];
30 int min_toks_to_match;
31 };
32
33 #define NUM_OPTIONS 4
34
35 static Quad_options_struct Quad_options_table [] =
36 {
37 { "absolute tolerance",
38 { "absolute", "tolerance", nullptr, nullptr, nullptr, },
39 { 1, 0, 0, 0, 0, }, 1, },
40
41 { "relative tolerance",
42 { "relative", "tolerance", nullptr, nullptr, nullptr, },
43 { 1, 0, 0, 0, 0, }, 1, },
44
45 { "single precision absolute tolerance",
46 { "single", "precision", "absolute", "tolerance", nullptr, },
47 { 1, 1, 1, 0, 0, }, 3, },
48
49 { "single precision relative tolerance",
50 { "single", "precision", "relative", "tolerance", nullptr, },
51 { 1, 1, 1, 0, 0, }, 3, },
52 };
53
54 static void
print_Quad_options(std::ostream & os)55 print_Quad_options (std::ostream& os)
56 {
57 std::ostringstream buf;
58
59 os << "\n"
60 << "Options for Quad include:\n\n"
61 << " keyword value\n"
62 << " ------- -----\n";
63
64 Quad_options_struct *list = Quad_options_table;
65
66 {
67 os << " "
68 << std::setiosflags (std::ios::left) << std::setw (50)
69 << list[0].keyword
70 << std::resetiosflags (std::ios::left)
71 << " ";
72
73 double val = quad_opts.absolute_tolerance ();
74
75 os << val << "\n";
76 }
77
78 {
79 os << " "
80 << std::setiosflags (std::ios::left) << std::setw (50)
81 << list[1].keyword
82 << std::resetiosflags (std::ios::left)
83 << " ";
84
85 double val = quad_opts.relative_tolerance ();
86
87 os << val << "\n";
88 }
89
90 {
91 os << " "
92 << std::setiosflags (std::ios::left) << std::setw (50)
93 << list[2].keyword
94 << std::resetiosflags (std::ios::left)
95 << " ";
96
97 float val = quad_opts.single_precision_absolute_tolerance ();
98
99 os << val << "\n";
100 }
101
102 {
103 os << " "
104 << std::setiosflags (std::ios::left) << std::setw (50)
105 << list[3].keyword
106 << std::resetiosflags (std::ios::left)
107 << " ";
108
109 float val = quad_opts.single_precision_relative_tolerance ();
110
111 os << val << "\n";
112 }
113
114 os << "\n";
115 }
116
117 static void
set_Quad_options(const std::string & keyword,const octave_value & val)118 set_Quad_options (const std::string& keyword, const octave_value& val)
119 {
120 Quad_options_struct *list = Quad_options_table;
121
122 if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
123 keyword, list[0].min_toks_to_match, MAX_TOKENS))
124 {
125 double tmp = val.double_value ();
126
127 quad_opts.set_absolute_tolerance (tmp);
128 }
129 else if (octave::keyword_almost_match (list[1].kw_tok, list[1].min_len,
130 keyword, list[1].min_toks_to_match, MAX_TOKENS))
131 {
132 double tmp = val.double_value ();
133
134 quad_opts.set_relative_tolerance (tmp);
135 }
136 else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
137 keyword, list[2].min_toks_to_match, MAX_TOKENS))
138 {
139 float tmp = val.float_value ();
140
141 quad_opts.set_single_precision_absolute_tolerance (tmp);
142 }
143 else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
144 keyword, list[3].min_toks_to_match, MAX_TOKENS))
145 {
146 float tmp = val.float_value ();
147
148 quad_opts.set_single_precision_relative_tolerance (tmp);
149 }
150 else
151 {
152 warning ("quad_options: no match for `%s'", keyword.c_str ());
153 }
154 }
155
156 static octave_value_list
show_Quad_options(const std::string & keyword)157 show_Quad_options (const std::string& keyword)
158 {
159 octave_value retval;
160
161 Quad_options_struct *list = Quad_options_table;
162
163 if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
164 keyword, list[0].min_toks_to_match, MAX_TOKENS))
165 {
166 double val = quad_opts.absolute_tolerance ();
167
168 retval = val;
169 }
170 else if (octave::keyword_almost_match (list[1].kw_tok, list[1].min_len,
171 keyword, list[1].min_toks_to_match, MAX_TOKENS))
172 {
173 double val = quad_opts.relative_tolerance ();
174
175 retval = val;
176 }
177 else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
178 keyword, list[2].min_toks_to_match, MAX_TOKENS))
179 {
180 float val = quad_opts.single_precision_absolute_tolerance ();
181
182 retval = val;
183 }
184 else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
185 keyword, list[3].min_toks_to_match, MAX_TOKENS))
186 {
187 float val = quad_opts.single_precision_relative_tolerance ();
188
189 retval = val;
190 }
191 else
192 {
193 warning ("quad_options: no match for `%s'", keyword.c_str ());
194 }
195
196 return retval;
197 }
198
199 DEFUN (quad_options, args, ,
200 doc: /* -*- texinfo -*-
201 @deftypefn {} {} quad_options ()
202 @deftypefnx {} {val =} quad_options (@var{opt})
203 @deftypefnx {} {} quad_options (@var{opt}, @var{val})
204 Query or set options for the function @code{quad}.
205
206 When called with no arguments, the names of all available options and
207 their current values are displayed.
208
209 Given one argument, return the value of the option @var{opt}.
210
211 When called with two arguments, @code{quad_options} sets the option
212 @var{opt} to value @var{val}.
213
214 Options include
215
216 @table @asis
217 @item @qcode{"absolute tolerance"}
218 Absolute tolerance; may be zero for pure relative error test.
219
220 @item @qcode{"relative tolerance"}
221 Non-negative relative tolerance. If the absolute tolerance is zero,
222 the relative tolerance must be greater than or equal to
223 @w{@code{max (50*eps, 0.5e-28)}}.
224
225 @item @qcode{"single precision absolute tolerance"}
226 Absolute tolerance for single precision; may be zero for pure relative
227 error test.
228
229 @item @qcode{"single precision relative tolerance"}
230 Non-negative relative tolerance for single precision. If the absolute
231 tolerance is zero, the relative tolerance must be greater than or equal to
232 @w{@code{max (50*eps, 0.5e-28)}}.
233 @end table
234 @end deftypefn */)
235 {
236 octave_value_list retval;
237
238 int nargin = args.length ();
239
240 if (nargin > 2)
241 print_usage ();
242
243 if (nargin == 0)
244 {
245 print_Quad_options (octave_stdout);
246 }
247 else
248 {
249 std::string keyword = args(0).xstring_value ("quad_options: expecting keyword as first argument");
250
251 if (nargin == 1)
252 retval = show_Quad_options (keyword);
253 else
254 set_Quad_options (keyword, args(1));
255 }
256
257 return retval;
258 }
259