GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Quad-opts.cc
Go to the documentation of this file.
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
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
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 
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 
149  }
150  else
151  {
152  warning ("quad_options: no match for `%s'", keyword.c_str ());
153  }
154 }
155 
156 static octave_value_list
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 
200 
201 DEFUN (quad_options, args, ,
202  doc: /* -*- texinfo -*-
203 @deftypefn {} {} quad_options ()
204 @deftypefnx {} {val =} quad_options (@var{opt})
205 @deftypefnx {} {} quad_options (@var{opt}, @var{val})
206 Query or set options for the function @code{quad}.
207 
208 When called with no arguments, the names of all available options and
209 their current values are displayed.
210 
211 Given one argument, return the value of the option @var{opt}.
212 
213 When called with two arguments, @code{quad_options} sets the option
214 @var{opt} to value @var{val}.
215 
216 Options include
217 
218 @table @asis
219 @item @qcode{"absolute tolerance"}
220 Absolute tolerance; may be zero for pure relative error test.
221 
222 @item @qcode{"relative tolerance"}
223 Non-negative relative tolerance. If the absolute tolerance is zero,
224 the relative tolerance must be greater than or equal to
225 @w{@code{max (50*eps, 0.5e-28)}}.
226 
227 @item @qcode{"single precision absolute tolerance"}
228 Absolute tolerance for single precision; may be zero for pure relative
229 error test.
230 
231 @item @qcode{"single precision relative tolerance"}
232 Non-negative relative tolerance for single precision. If the absolute
233 tolerance is zero, the relative tolerance must be greater than or equal to
234 @w{@code{max (50*eps, 0.5e-28)}}.
235 @end table
236 @end deftypefn */)
237 {
238  octave_value_list retval;
239 
240  int nargin = args.length ();
241 
242  if (nargin > 2)
243  print_usage ();
244 
245  if (nargin == 0)
246  {
247  print_Quad_options (octave_stdout);
248  }
249  else
250  {
251  std::string keyword = args(0).xstring_value ("quad_options: expecting keyword as first argument");
252 
253  if (nargin == 1)
254  retval = show_Quad_options (keyword);
255  else
256  set_Quad_options (keyword, args(1));
257  }
258 
259  return retval;
260 }
261 
262 OCTAVE_END_NAMESPACE(octave)
263 
#define MAX_TOKENS
Definition: Quad-opts.cc:23
void set_single_precision_relative_tolerance(float val)
Definition: Quad-opts.h:81
float single_precision_relative_tolerance() const
Definition: Quad-opts.h:92
void set_single_precision_absolute_tolerance(float val)
Definition: Quad-opts.h:78
double absolute_tolerance() const
Definition: Quad-opts.h:83
void set_absolute_tolerance(double val)
Definition: Quad-opts.h:72
float single_precision_absolute_tolerance() const
Definition: Quad-opts.h:89
double relative_tolerance() const
Definition: Quad-opts.h:86
void set_relative_tolerance(double val)
Definition: Quad-opts.h:75
float float_value(bool frc_str_conv=false) const
Definition: ov.h:844
octave_idx_type length() const
double double_value(bool frc_str_conv=false) const
Definition: ov.h:841
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void print_usage(void)
Definition: defun-int.h:72
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:56
void warning(const char *fmt,...)
Definition: error.cc:1063
int keyword_almost_match(const char *const *std, int *min_len, const std::string &s, int min_toks_to_match, int max_toks)
Definition: utils.cc:428
#define octave_stdout
Definition: pager.h:309