GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7 
8 #include <iomanip>
9 #include <iostream>
10 
11 #include "Quad-opts.h"
12 
13 #include "defun.h"
14 #include "pr-output.h"
15 
16 #include "oct-obj.h"
17 #include "utils.h"
18 #include "pager.h"
19 
21 
22 #define MAX_TOKENS 4
23 
25 {
26  const char *keyword;
27  const char *kw_tok[MAX_TOKENS + 1];
28  int min_len[MAX_TOKENS + 1];
30 };
31 
32 #define NUM_OPTIONS 4
33 
35 {
36  { "absolute tolerance",
37  { "absolute", "tolerance", 0, 0, 0, },
38  { 1, 0, 0, 0, 0, }, 1, },
39 
40  { "relative tolerance",
41  { "relative", "tolerance", 0, 0, 0, },
42  { 1, 0, 0, 0, 0, }, 1, },
43 
44  { "single precision absolute tolerance",
45  { "single", "precision", "absolute", "tolerance", 0, },
46  { 1, 1, 1, 0, 0, }, 3, },
47 
48  { "single precision relative tolerance",
49  { "single", "precision", "relative", "tolerance", 0, },
50  { 1, 1, 1, 0, 0, }, 3, },
51 };
52 
53 static void
54 print_Quad_options (std::ostream& os)
55 {
56  std::ostringstream buf;
57 
58  os << "\n"
59  << "Options for Quad include:\n\n"
60  << " keyword value\n"
61  << " ------- -----\n";
62 
64 
65  {
66  os << " "
67  << std::setiosflags (std::ios::left) << std::setw (50)
68  << list[0].keyword
69  << std::resetiosflags (std::ios::left)
70  << " ";
71 
72  double val = quad_opts.absolute_tolerance ();
73 
74  os << val << "\n";
75  }
76 
77  {
78  os << " "
79  << std::setiosflags (std::ios::left) << std::setw (50)
80  << list[1].keyword
81  << std::resetiosflags (std::ios::left)
82  << " ";
83 
84  double val = quad_opts.relative_tolerance ();
85 
86  os << val << "\n";
87  }
88 
89  {
90  os << " "
91  << std::setiosflags (std::ios::left) << std::setw (50)
92  << list[2].keyword
93  << std::resetiosflags (std::ios::left)
94  << " ";
95 
96  float val = quad_opts.single_precision_absolute_tolerance ();
97 
98  os << val << "\n";
99  }
100 
101  {
102  os << " "
103  << std::setiosflags (std::ios::left) << std::setw (50)
104  << list[3].keyword
105  << std::resetiosflags (std::ios::left)
106  << " ";
107 
108  float val = quad_opts.single_precision_relative_tolerance ();
109 
110  os << val << "\n";
111  }
112 
113  os << "\n";
114 }
115 
116 static void
117 set_Quad_options (const std::string& keyword, const octave_value& val)
118 {
120 
121  if (keyword_almost_match (list[0].kw_tok, list[0].min_len,
122  keyword, list[0].min_toks_to_match, MAX_TOKENS))
123  {
124  double tmp = val.double_value ();
125 
126  if (! error_state)
127  quad_opts.set_absolute_tolerance (tmp);
128  }
129  else if (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  if (! error_state)
135  quad_opts.set_relative_tolerance (tmp);
136  }
137  else if (keyword_almost_match (list[2].kw_tok, list[2].min_len,
138  keyword, list[2].min_toks_to_match, MAX_TOKENS))
139  {
140  float tmp = val.float_value ();
141 
142  if (! error_state)
144  }
145  else if (keyword_almost_match (list[3].kw_tok, list[3].min_len,
146  keyword, list[3].min_toks_to_match, MAX_TOKENS))
147  {
148  float tmp = val.float_value ();
149 
150  if (! error_state)
152  }
153  else
154  {
155  warning ("quad_options: no match for `%s'", keyword.c_str ());
156  }
157 }
158 
159 static octave_value_list
160 show_Quad_options (const std::string& keyword)
161 {
162  octave_value retval;
163 
165 
166  if (keyword_almost_match (list[0].kw_tok, list[0].min_len,
167  keyword, list[0].min_toks_to_match, MAX_TOKENS))
168  {
169  double val = quad_opts.absolute_tolerance ();
170 
171  retval = val;
172  }
173  else if (keyword_almost_match (list[1].kw_tok, list[1].min_len,
174  keyword, list[1].min_toks_to_match, MAX_TOKENS))
175  {
176  double val = quad_opts.relative_tolerance ();
177 
178  retval = val;
179  }
180  else if (keyword_almost_match (list[2].kw_tok, list[2].min_len,
181  keyword, list[2].min_toks_to_match, MAX_TOKENS))
182  {
183  float val = quad_opts.single_precision_absolute_tolerance ();
184 
185  retval = val;
186  }
187  else if (keyword_almost_match (list[3].kw_tok, list[3].min_len,
188  keyword, list[3].min_toks_to_match, MAX_TOKENS))
189  {
190  float val = quad_opts.single_precision_relative_tolerance ();
191 
192  retval = val;
193  }
194  else
195  {
196  warning ("quad_options: no match for `%s'", keyword.c_str ());
197  }
198 
199  return retval;
200 }
201 
202 DEFUN (quad_options, args, ,
203  "-*- texinfo -*-\n\
204 @deftypefn {Built-in Function} {} quad_options ()\n\
205 @deftypefnx {Built-in Function} {val =} quad_options (@var{opt})\n\
206 @deftypefnx {Built-in Function} {} quad_options (@var{opt}, @var{val})\n\
207 Query or set options for the function @code{quad}.\n\
208 \n\
209 When called with no arguments, the names of all available options and\n\
210 their current values are displayed.\n\
211 \n\
212 Given one argument, return the value of the option @var{opt}.\n\
213 \n\
214 When called with two arguments, @code{quad_options} sets the option\n\
215 @var{opt} to value @var{val}.\n\
216 \n\
217 Options include\n\
218 \n\
219 @table @code\n\
220 @item @qcode{\"absolute tolerance\"}\n\
221 Absolute tolerance; may be zero for pure relative error test.\n\
222 \n\
223 @item @qcode{\"relative tolerance\"}\n\
224 Non-negative relative tolerance. If the absolute tolerance is zero,\n\
225 the relative tolerance must be greater than or equal to\n\
226 @w{@code{max (50*eps, 0.5e-28)}}.\n\
227 \n\
228 @item @qcode{\"single precision absolute tolerance\"}\n\
229 Absolute tolerance for single precision; may be zero for pure relative\n\
230 error test.\n\
231 \n\
232 @item @qcode{\"single precision relative tolerance\"}\n\
233 Non-negative relative tolerance for single precision. If the absolute\n\
234 tolerance is zero, the relative tolerance must be greater than or equal to\n\
235 @w{@code{max (50*eps, 0.5e-28)}}.\n\
236 @end table\n\
237 @end deftypefn")
238 {
239  octave_value_list retval;
240 
241  int nargin = args.length ();
242 
243  if (nargin == 0)
244  {
246  }
247  else if (nargin == 1 || nargin == 2)
248  {
249  std::string keyword = args(0).string_value ();
250 
251  if (! error_state)
252  {
253  if (nargin == 1)
254  retval = show_Quad_options (keyword);
255  else
256  set_Quad_options (keyword, args(1));
257  }
258  else
259  error ("quad_options: expecting keyword as first argument");
260  }
261  else
262  print_usage ();
263 
264  return retval;
265 }
void set_single_precision_relative_tolerance(float val)
Definition: Quad-opts.h:80
OCTINTERP_API void print_usage(void)
Definition: defun.cc:51
float single_precision_absolute_tolerance(void) const
Definition: Quad-opts.h:88
void set_relative_tolerance(double val)
Definition: Quad-opts.h:74
octave_idx_type length(void) const
Definition: oct-obj.h:89
static Quad_options_struct Quad_options_table[]
Definition: Quad-opts.cc:34
static octave_value_list show_Quad_options(const std::string &keyword)
Definition: Quad-opts.cc:160
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:44
void error(const char *fmt,...)
Definition: error.cc:476
float float_value(bool frc_str_conv=false) const
Definition: ov.h:762
#define MAX_TOKENS
Definition: Quad-opts.cc:22
static int left
Definition: randmtzig.c:189
static Quad_options quad_opts
Definition: Quad-opts.cc:20
const char * kw_tok[4+1]
Definition: Quad-opts.cc:27
static void print_Quad_options(std::ostream &os)
Definition: Quad-opts.cc:54
void set_single_precision_absolute_tolerance(float val)
Definition: Quad-opts.h:77
static void set_Quad_options(const std::string &keyword, const octave_value &val)
Definition: Quad-opts.cc:117
int error_state
Definition: error.cc:101
const char * keyword
Definition: Quad-opts.cc:26
float single_precision_relative_tolerance(void) const
Definition: Quad-opts.h:91
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:155
void warning(const char *fmt,...)
Definition: error.cc:681
void set_absolute_tolerance(double val)
Definition: Quad-opts.h:71
#define octave_stdout
Definition: pager.h:144
double relative_tolerance(void) const
Definition: Quad-opts.h:85
double absolute_tolerance(void) const
Definition: Quad-opts.h:82
double double_value(bool frc_str_conv=false) const
Definition: ov.h:759