523
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
523
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
523
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
523
|
25 #endif |
|
26 |
2184
|
27 #include <cfloat> |
|
28 #include <cmath> |
|
29 |
1728
|
30 #include <string> |
|
31 |
2184
|
32 #include "lo-ieee.h" |
1755
|
33 #include "str-vec.h" |
4153
|
34 #include "quit.h" |
1755
|
35 |
1352
|
36 #include "defun.h" |
|
37 #include "error.h" |
|
38 #include "gripes.h" |
|
39 #include "oct-map.h" |
2366
|
40 #include "ov.h" |
3665
|
41 #include "ov-re-nd-array.h" |
2366
|
42 #include "variables.h" |
1742
|
43 #include "oct-obj.h" |
523
|
44 #include "utils.h" |
|
45 |
|
46 #ifndef MIN |
|
47 #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
|
48 #endif |
|
49 |
767
|
50 #ifndef ABS |
|
51 #define ABS(x) (((x) < 0) ? (-x) : (x)) |
|
52 #endif |
|
53 |
4015
|
54 #define ANY_ALL(FCN) \ |
|
55 \ |
4233
|
56 octave_value retval; \ |
4015
|
57 \ |
|
58 int nargin = args.length (); \ |
|
59 \ |
4021
|
60 if (nargin == 1 || nargin == 2) \ |
4015
|
61 { \ |
4021
|
62 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ |
|
63 \ |
|
64 if (! error_state) \ |
|
65 { \ |
|
66 if (dim <= 1 && dim >= -1) \ |
4015
|
67 retval = args(0).FCN (dim); \ |
4021
|
68 else \ |
|
69 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
|
70 } \ |
4015
|
71 else \ |
4021
|
72 error (#FCN ": expecting dimension argument to be an integer"); \ |
4015
|
73 } \ |
4021
|
74 else \ |
|
75 print_usage (#FCN); \ |
4015
|
76 \ |
|
77 return retval |
|
78 |
1957
|
79 DEFUN (all, args, , |
3369
|
80 "-*- texinfo -*-\n\ |
4015
|
81 @deftypefn {Built-in Function} {} all (@var{x}, @var{dim})\n\ |
3369
|
82 The function @code{all} behaves like the function @code{any}, except\n\ |
|
83 that it returns true only if all the elements of a vector, or all the\n\ |
4015
|
84 elements along dimension @var{dim} of a matrix, are nonzero.\n\ |
3369
|
85 @end deftypefn") |
523
|
86 { |
4015
|
87 ANY_ALL (all); |
523
|
88 } |
|
89 |
1957
|
90 DEFUN (any, args, , |
3369
|
91 "-*- texinfo -*-\n\ |
4015
|
92 @deftypefn {Built-in Function} {} any (@var{x}, @var{dim})\n\ |
3369
|
93 For a vector argument, return 1 if any element of the vector is\n\ |
|
94 nonzero.\n\ |
|
95 \n\ |
|
96 For a matrix argument, return a row vector of ones and\n\ |
|
97 zeros with each element indicating whether any of the elements of the\n\ |
|
98 corresponding column of the matrix are nonzero. For example,\n\ |
|
99 \n\ |
|
100 @example\n\ |
|
101 @group\n\ |
|
102 any (eye (2, 4))\n\ |
|
103 @result{} [ 1, 1, 0, 0 ]\n\ |
|
104 @end group\n\ |
|
105 @end example\n\ |
|
106 \n\ |
4015
|
107 If the optional argument @var{dim} is supplied, work along dimension\n\ |
|
108 @var{dim}. For example,\n\ |
3369
|
109 \n\ |
|
110 @example\n\ |
4015
|
111 @group\n\ |
|
112 any (eye (2, 4), 2)\n\ |
|
113 @result{} [ 1; 1 ]\n\ |
|
114 @end group\n\ |
3369
|
115 @end example\n\ |
|
116 @end deftypefn") |
523
|
117 { |
4015
|
118 ANY_ALL (any); |
523
|
119 } |
|
120 |
649
|
121 // These mapping functions may also be useful in other places, eh? |
|
122 |
|
123 typedef double (*d_dd_fcn) (double, double); |
|
124 |
|
125 static Matrix |
2672
|
126 map_d_m (d_dd_fcn f, double x, const Matrix& y) |
649
|
127 { |
|
128 int nr = y.rows (); |
|
129 int nc = y.columns (); |
|
130 |
|
131 Matrix retval (nr, nc); |
|
132 |
|
133 for (int j = 0; j < nc; j++) |
|
134 for (int i = 0; i < nr; i++) |
4153
|
135 { |
|
136 OCTAVE_QUIT; |
|
137 retval (i, j) = f (x, y (i, j)); |
|
138 } |
649
|
139 |
|
140 return retval; |
|
141 } |
|
142 |
|
143 static Matrix |
2672
|
144 map_m_d (d_dd_fcn f, const Matrix& x, double y) |
649
|
145 { |
|
146 int nr = x.rows (); |
|
147 int nc = x.columns (); |
|
148 |
|
149 Matrix retval (nr, nc); |
|
150 |
|
151 for (int j = 0; j < nc; j++) |
|
152 for (int i = 0; i < nr; i++) |
4153
|
153 { |
|
154 OCTAVE_QUIT; |
|
155 retval (i, j) = f (x (i, j), y); |
|
156 } |
649
|
157 |
|
158 return retval; |
|
159 } |
|
160 |
|
161 static Matrix |
2672
|
162 map_m_m (d_dd_fcn f, const Matrix& x, const Matrix& y) |
649
|
163 { |
|
164 int x_nr = x.rows (); |
|
165 int x_nc = x.columns (); |
|
166 |
|
167 int y_nr = y.rows (); |
|
168 int y_nc = y.columns (); |
|
169 |
719
|
170 assert (x_nr == y_nr && x_nc == y_nc); |
649
|
171 |
|
172 Matrix retval (x_nr, x_nc); |
|
173 |
|
174 for (int j = 0; j < x_nc; j++) |
|
175 for (int i = 0; i < x_nr; i++) |
4153
|
176 { |
|
177 OCTAVE_QUIT; |
|
178 retval (i, j) = f (x (i, j), y (i, j)); |
|
179 } |
649
|
180 |
|
181 return retval; |
|
182 } |
|
183 |
1957
|
184 DEFUN (atan2, args, , |
3428
|
185 "-*- texinfo -*-\n\ |
|
186 @deftypefn {Mapping Function} {} atan2 (@var{y}, @var{x})\n\ |
|
187 Compute atan (@var{y} / @var{x}) for corresponding elements of @var{y}\n\ |
|
188 and @var{x}. The result is in range -pi to pi.\n\ |
3439
|
189 @end deftypefn") |
649
|
190 { |
4233
|
191 octave_value retval; |
649
|
192 |
712
|
193 int nargin = args.length (); |
|
194 |
|
195 if (nargin == 2 && args(0).is_defined () && args(1).is_defined ()) |
649
|
196 { |
2086
|
197 octave_value arg_y = args(0); |
|
198 octave_value arg_x = args(1); |
649
|
199 |
|
200 int y_nr = arg_y.rows (); |
|
201 int y_nc = arg_y.columns (); |
|
202 |
|
203 int x_nr = arg_x.rows (); |
|
204 int x_nc = arg_x.columns (); |
|
205 |
|
206 int arg_y_empty = empty_arg ("atan2", y_nr, y_nc); |
|
207 int arg_x_empty = empty_arg ("atan2", x_nr, x_nc); |
|
208 |
719
|
209 if (arg_y_empty > 0 && arg_x_empty > 0) |
4233
|
210 return octave_value (Matrix ()); |
719
|
211 else if (arg_y_empty || arg_x_empty) |
649
|
212 return retval; |
|
213 |
|
214 int y_is_scalar = (y_nr == 1 && y_nc == 1); |
|
215 int x_is_scalar = (x_nr == 1 && x_nc == 1); |
|
216 |
|
217 if (y_is_scalar && x_is_scalar) |
|
218 { |
|
219 double y = arg_y.double_value (); |
|
220 |
|
221 if (! error_state) |
|
222 { |
|
223 double x = arg_x.double_value (); |
|
224 |
|
225 if (! error_state) |
|
226 retval = atan2 (y, x); |
|
227 } |
|
228 } |
|
229 else if (y_is_scalar) |
|
230 { |
|
231 double y = arg_y.double_value (); |
|
232 |
|
233 if (! error_state) |
|
234 { |
|
235 Matrix x = arg_x.matrix_value (); |
|
236 |
|
237 if (! error_state) |
2672
|
238 retval = map_d_m (atan2, y, x); |
649
|
239 } |
|
240 } |
|
241 else if (x_is_scalar) |
|
242 { |
|
243 Matrix y = arg_y.matrix_value (); |
|
244 |
|
245 if (! error_state) |
|
246 { |
|
247 double x = arg_x.double_value (); |
|
248 |
|
249 if (! error_state) |
2672
|
250 retval = map_m_d (atan2, y, x); |
649
|
251 } |
|
252 } |
|
253 else if (y_nr == x_nr && y_nc == x_nc) |
|
254 { |
|
255 Matrix y = arg_y.matrix_value (); |
|
256 |
|
257 if (! error_state) |
|
258 { |
|
259 Matrix x = arg_x.matrix_value (); |
|
260 |
|
261 if (! error_state) |
2672
|
262 retval = map_m_m (atan2, y, x); |
649
|
263 } |
|
264 } |
|
265 else |
|
266 error ("atan2: nonconformant matrices"); |
|
267 } |
712
|
268 else |
|
269 print_usage ("atan2"); |
649
|
270 |
|
271 return retval; |
|
272 } |
|
273 |
3723
|
274 #define DATA_REDUCTION(FCN) \ |
|
275 \ |
4233
|
276 octave_value retval; \ |
3723
|
277 \ |
|
278 int nargin = args.length (); \ |
|
279 \ |
|
280 if (nargin == 1 || nargin == 2) \ |
|
281 { \ |
|
282 octave_value arg = args(0); \ |
|
283 \ |
3864
|
284 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ |
3723
|
285 \ |
|
286 if (! error_state) \ |
|
287 { \ |
3864
|
288 if (dim <= 1 && dim >= -1) \ |
3723
|
289 { \ |
|
290 if (arg.is_real_type ()) \ |
|
291 { \ |
|
292 Matrix tmp = arg.matrix_value (); \ |
|
293 \ |
|
294 if (! error_state) \ |
4233
|
295 retval = tmp.FCN (dim); \ |
3723
|
296 } \ |
|
297 else if (arg.is_complex_type ()) \ |
|
298 { \ |
|
299 ComplexMatrix tmp = arg.complex_matrix_value (); \ |
|
300 \ |
|
301 if (! error_state) \ |
4233
|
302 retval = tmp.FCN (dim); \ |
3723
|
303 } \ |
|
304 else \ |
|
305 { \ |
|
306 gripe_wrong_type_arg (#FCN, arg); \ |
|
307 return retval; \ |
|
308 } \ |
|
309 } \ |
|
310 else \ |
|
311 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
|
312 } \ |
|
313 } \ |
|
314 else \ |
|
315 print_usage (#FCN); \ |
|
316 \ |
|
317 return retval |
|
318 |
1957
|
319 DEFUN (cumprod, args, , |
3428
|
320 "-*- texinfo -*-\n\ |
3723
|
321 @deftypefn {Built-in Function} {} cumprod (@var{x}, @var{dim})\n\ |
|
322 Cumulative product of elements along dimension @var{dim}. If\n\ |
|
323 @var{dim} is omitted, it defaults to 1 (column-wise cumulative\n\ |
|
324 products).\n\ |
3428
|
325 @end deftypefn") |
523
|
326 { |
3723
|
327 DATA_REDUCTION (cumprod); |
523
|
328 } |
|
329 |
1957
|
330 DEFUN (cumsum, args, , |
3428
|
331 "-*- texinfo -*-\n\ |
3723
|
332 @deftypefn {Built-in Function} {} cumsum (@var{x}, @var{dim})\n\ |
|
333 Cumulative sum of elements along dimension @var{dim}. If @var{dim}\n\ |
|
334 is omitted, it defaults to 1 (column-wise cumulative sums).\n\ |
3428
|
335 @end deftypefn") |
523
|
336 { |
3723
|
337 DATA_REDUCTION (cumsum); |
523
|
338 } |
|
339 |
3972
|
340 // XXX FIXME XXX -- we could eliminate some duplicate code here with |
|
341 // some template functions or macros. |
|
342 |
2086
|
343 static octave_value |
767
|
344 make_diag (const Matrix& v, int k) |
|
345 { |
|
346 int nr = v.rows (); |
|
347 int nc = v.columns (); |
|
348 assert (nc == 1 || nr == 1); |
|
349 |
2086
|
350 octave_value retval; |
767
|
351 |
|
352 int roff = 0; |
|
353 int coff = 0; |
|
354 if (k > 0) |
|
355 { |
|
356 roff = 0; |
|
357 coff = k; |
|
358 } |
|
359 else if (k < 0) |
|
360 { |
|
361 roff = -k; |
|
362 coff = 0; |
|
363 } |
|
364 |
|
365 if (nr == 1) |
|
366 { |
|
367 int n = nc + ABS (k); |
|
368 Matrix m (n, n, 0.0); |
|
369 for (int i = 0; i < nc; i++) |
2305
|
370 m (i+roff, i+coff) = v (0, i); |
4233
|
371 retval = m; |
767
|
372 } |
|
373 else |
|
374 { |
|
375 int n = nr + ABS (k); |
|
376 Matrix m (n, n, 0.0); |
|
377 for (int i = 0; i < nr; i++) |
2305
|
378 m (i+roff, i+coff) = v (i, 0); |
4233
|
379 retval = m; |
767
|
380 } |
|
381 |
|
382 return retval; |
|
383 } |
|
384 |
2086
|
385 static octave_value |
767
|
386 make_diag (const ComplexMatrix& v, int k) |
|
387 { |
|
388 int nr = v.rows (); |
|
389 int nc = v.columns (); |
|
390 assert (nc == 1 || nr == 1); |
|
391 |
2086
|
392 octave_value retval; |
767
|
393 |
|
394 int roff = 0; |
|
395 int coff = 0; |
|
396 if (k > 0) |
|
397 { |
|
398 roff = 0; |
|
399 coff = k; |
|
400 } |
|
401 else if (k < 0) |
|
402 { |
|
403 roff = -k; |
|
404 coff = 0; |
|
405 } |
|
406 |
|
407 if (nr == 1) |
|
408 { |
|
409 int n = nc + ABS (k); |
|
410 ComplexMatrix m (n, n, 0.0); |
|
411 for (int i = 0; i < nc; i++) |
2305
|
412 m (i+roff, i+coff) = v (0, i); |
4233
|
413 retval = m; |
767
|
414 } |
|
415 else |
|
416 { |
|
417 int n = nr + ABS (k); |
|
418 ComplexMatrix m (n, n, 0.0); |
|
419 for (int i = 0; i < nr; i++) |
2305
|
420 m (i+roff, i+coff) = v (i, 0); |
4233
|
421 retval = m; |
767
|
422 } |
|
423 |
|
424 return retval; |
|
425 } |
|
426 |
2086
|
427 static octave_value |
|
428 make_diag (const octave_value& arg) |
767
|
429 { |
2086
|
430 octave_value retval; |
767
|
431 |
|
432 if (arg.is_real_type ()) |
|
433 { |
|
434 Matrix m = arg.matrix_value (); |
|
435 |
|
436 if (! error_state) |
|
437 { |
|
438 int nr = m.rows (); |
|
439 int nc = m.columns (); |
|
440 |
|
441 if (nr == 0 || nc == 0) |
|
442 retval = Matrix (); |
|
443 else if (nr == 1 || nc == 1) |
|
444 retval = make_diag (m, 0); |
|
445 else |
|
446 { |
|
447 ColumnVector v = m.diag (); |
|
448 if (v.capacity () > 0) |
|
449 retval = v; |
|
450 } |
|
451 } |
|
452 else |
|
453 gripe_wrong_type_arg ("diag", arg); |
|
454 } |
|
455 else if (arg.is_complex_type ()) |
|
456 { |
|
457 ComplexMatrix cm = arg.complex_matrix_value (); |
|
458 |
|
459 if (! error_state) |
|
460 { |
|
461 int nr = cm.rows (); |
|
462 int nc = cm.columns (); |
|
463 |
|
464 if (nr == 0 || nc == 0) |
|
465 retval = Matrix (); |
|
466 else if (nr == 1 || nc == 1) |
|
467 retval = make_diag (cm, 0); |
|
468 else |
|
469 { |
|
470 ComplexColumnVector v = cm.diag (); |
|
471 if (v.capacity () > 0) |
|
472 retval = v; |
|
473 } |
|
474 } |
|
475 else |
|
476 gripe_wrong_type_arg ("diag", arg); |
|
477 } |
|
478 else |
|
479 gripe_wrong_type_arg ("diag", arg); |
|
480 |
|
481 return retval; |
|
482 } |
|
483 |
2086
|
484 static octave_value |
|
485 make_diag (const octave_value& a, const octave_value& b) |
767
|
486 { |
2086
|
487 octave_value retval; |
767
|
488 |
3202
|
489 int k = b.nint_value (); |
767
|
490 |
|
491 if (error_state) |
|
492 { |
|
493 error ("diag: invalid second argument"); |
|
494 return retval; |
|
495 } |
|
496 |
|
497 if (a.is_real_type ()) |
|
498 { |
3307
|
499 Matrix m = a.matrix_value (); |
767
|
500 |
3307
|
501 if (! error_state) |
767
|
502 { |
|
503 int nr = m.rows (); |
|
504 int nc = m.columns (); |
|
505 |
3972
|
506 if (nr == 1 || nc == 1) |
|
507 retval = make_diag (m, k); |
|
508 else if (nr == 0 || nc == 0) |
767
|
509 retval = Matrix (); |
|
510 else |
|
511 { |
|
512 ColumnVector d = m.diag (k); |
|
513 retval = d; |
|
514 } |
|
515 } |
|
516 } |
|
517 else if (a.is_complex_type ()) |
|
518 { |
3307
|
519 ComplexMatrix cm = a.complex_matrix_value (); |
767
|
520 |
3307
|
521 if (! error_state) |
767
|
522 { |
|
523 int nr = cm.rows (); |
|
524 int nc = cm.columns (); |
|
525 |
3972
|
526 if (nr == 1 || nc == 1) |
|
527 retval = make_diag (cm, k); |
|
528 else if (nr == 0 || nc == 0) |
767
|
529 retval = Matrix (); |
|
530 else |
|
531 { |
|
532 ComplexColumnVector d = cm.diag (k); |
|
533 retval = d; |
|
534 } |
|
535 } |
|
536 } |
|
537 else |
|
538 gripe_wrong_type_arg ("diag", a); |
|
539 |
|
540 return retval; |
|
541 } |
|
542 |
1957
|
543 DEFUN (diag, args, , |
3369
|
544 "-*- texinfo -*-\n\ |
|
545 @deftypefn {Built-in Function} {} diag (@var{v}, @var{k})\n\ |
|
546 Return a diagonal matrix with vector @var{v} on diagonal @var{k}. The\n\ |
|
547 second argument is optional. If it is positive, the vector is placed on\n\ |
|
548 the @var{k}-th super-diagonal. If it is negative, it is placed on the\n\ |
|
549 @var{-k}-th sub-diagonal. The default value of @var{k} is 0, and the\n\ |
|
550 vector is placed on the main diagonal. For example,\n\ |
|
551 \n\ |
|
552 @example\n\ |
|
553 @group\n\ |
|
554 diag ([1, 2, 3], 1)\n\ |
|
555 @result{} 0 1 0 0\n\ |
|
556 0 0 2 0\n\ |
|
557 0 0 0 3\n\ |
|
558 0 0 0 0\n\ |
|
559 @end group\n\ |
|
560 @end example\n\ |
|
561 @end deftypefn") |
523
|
562 { |
4233
|
563 octave_value retval; |
523
|
564 |
|
565 int nargin = args.length (); |
|
566 |
712
|
567 if (nargin == 1 && args(0).is_defined ()) |
767
|
568 retval = make_diag (args(0)); |
712
|
569 else if (nargin == 2 && args(0).is_defined () && args(1).is_defined ()) |
767
|
570 retval = make_diag (args(0), args(1)); |
523
|
571 else |
|
572 print_usage ("diag"); |
|
573 |
|
574 return retval; |
|
575 } |
|
576 |
1957
|
577 DEFUN (prod, args, , |
3428
|
578 "-*- texinfo -*-\n\ |
3723
|
579 @deftypefn {Built-in Function} {} prod (@var{x}, @var{dim})\n\ |
|
580 Product of elements along dimension @var{dim}. If @var{dim} is\n\ |
|
581 omitted, it defaults to 1 (column-wise products).\n\ |
3428
|
582 @end deftypefn") |
523
|
583 { |
3723
|
584 DATA_REDUCTION (prod); |
523
|
585 } |
|
586 |
3195
|
587 DEFUN (length, args, , |
3373
|
588 "-*- texinfo -*-\n\ |
|
589 @deftypefn {Built-in Function} {} length (@var{a})\n\ |
4176
|
590 Return the `length' of the object @var{a}. For matrix objects, the\n\ |
3373
|
591 length is the number of rows or columns, whichever is greater (this\n\ |
|
592 odd definition is used for compatibility with Matlab).\n\ |
|
593 @end deftypefn") |
3195
|
594 { |
|
595 octave_value retval; |
|
596 |
|
597 if (args.length () == 1) |
|
598 { |
|
599 int len = args(0).length (); |
|
600 |
|
601 if (! error_state) |
4233
|
602 retval = len; |
3195
|
603 } |
|
604 else |
|
605 print_usage ("length"); |
|
606 |
|
607 return retval; |
|
608 } |
|
609 |
1957
|
610 DEFUN (size, args, nargout, |
3373
|
611 "-*- texinfo -*-\n\ |
|
612 @deftypefn {Built-in Function} {} size (@var{a}, @var{n})\n\ |
|
613 Return the number rows and columns of @var{a}.\n\ |
|
614 \n\ |
|
615 With one input argument and one output argument, the result is returned\n\ |
|
616 in a 2 element row vector. If there are two output arguments, the\n\ |
|
617 number of rows is assigned to the first, and the number of columns to\n\ |
|
618 the second. For example,\n\ |
|
619 \n\ |
|
620 @example\n\ |
|
621 @group\n\ |
|
622 size ([1, 2; 3, 4; 5, 6])\n\ |
|
623 @result{} [ 3, 2 ]\n\ |
1031
|
624 \n\ |
3373
|
625 [nr, nc] = size ([1, 2; 3, 4; 5, 6])\n\ |
|
626 @result{} nr = 3\n\ |
|
627 @result{} nc = 2\n\ |
|
628 @end group\n\ |
|
629 @end example\n\ |
|
630 \n\ |
|
631 If given a second argument of either 1 or 2, @code{size} will return\n\ |
|
632 only the row or column dimension. For example\n\ |
1031
|
633 \n\ |
3373
|
634 @example\n\ |
|
635 size ([1, 2; 3, 4; 5, 6], 2)\n\ |
|
636 @result{} 2\n\ |
|
637 @end example\n\ |
|
638 \n\ |
|
639 @noindent\n\ |
|
640 returns the number of columns in the given matrix.\n\ |
|
641 @end deftypefn") |
523
|
642 { |
2086
|
643 octave_value_list retval; |
523
|
644 |
|
645 int nargin = args.length (); |
|
646 |
1031
|
647 if (nargin == 1 && nargout < 3) |
523
|
648 { |
712
|
649 int nr = args(0).rows (); |
|
650 int nc = args(0).columns (); |
1031
|
651 |
712
|
652 if (nargout == 0 || nargout == 1) |
523
|
653 { |
712
|
654 Matrix m (1, 2); |
2305
|
655 m (0, 0) = nr; |
|
656 m (0, 1) = nc; |
4233
|
657 retval(0) = m; |
523
|
658 } |
712
|
659 else if (nargout == 2) |
|
660 { |
4233
|
661 retval(1) = nc; |
|
662 retval(0) = nr; |
712
|
663 } |
1031
|
664 } |
|
665 else if (nargin == 2 && nargout < 2) |
|
666 { |
3202
|
667 int nd = args(1).nint_value (); |
1031
|
668 |
|
669 if (error_state) |
|
670 error ("size: expecting scalar as second argument"); |
712
|
671 else |
1031
|
672 { |
|
673 if (nd == 1) |
4233
|
674 retval(0) = args(0).rows (); |
1031
|
675 else if (nd == 2) |
4233
|
676 retval(0) = args(0).columns (); |
1031
|
677 else |
|
678 error ("size: invalid second argument -- expecting 1 or 2"); |
|
679 } |
523
|
680 } |
712
|
681 else |
|
682 print_usage ("size"); |
523
|
683 |
|
684 return retval; |
|
685 } |
|
686 |
1957
|
687 DEFUN (sum, args, , |
3428
|
688 "-*- texinfo -*-\n\ |
3723
|
689 @deftypefn {Built-in Function} {} sum (@var{x}, @var{dim})\n\ |
|
690 Sum of elements along dimension @var{dim}. If @var{dim} is\n\ |
|
691 omitted, it defaults to 1 (column-wise sum).\n\ |
3428
|
692 @end deftypefn") |
523
|
693 { |
3723
|
694 DATA_REDUCTION (sum); |
523
|
695 } |
|
696 |
1957
|
697 DEFUN (sumsq, args, , |
3428
|
698 "-*- texinfo -*-\n\ |
3723
|
699 @deftypefn {Built-in Function} {} sumsq (@var{x}, @var{dim})\n\ |
|
700 Sum of squares of elements along dimension @var{dim}. If @var{dim}\n\ |
|
701 is omitted, it defaults to 1 (column-wise sum of squares).\n\ |
3095
|
702 \n\ |
|
703 This function is equivalent to computing\n\ |
3723
|
704 @example\n\ |
|
705 sum (x .* conj (x), dim)\n\ |
|
706 @end example\n\ |
|
707 but it uses less memory and avoids calling conj if @var{x} is real.\n\ |
3428
|
708 @end deftypefn") |
523
|
709 { |
3723
|
710 DATA_REDUCTION (sumsq); |
523
|
711 } |
|
712 |
4028
|
713 DEFUN (isbool, args, , |
3428
|
714 "-*- texinfo -*-\n\ |
4028
|
715 @deftypefn {Built-in Functio} {} isbool (@var{x})\n\ |
3428
|
716 Return true if @var{x} is a boolean object.\n\ |
3439
|
717 @end deftypefn") |
3209
|
718 { |
|
719 octave_value retval; |
|
720 |
|
721 if (args.length () == 1) |
3258
|
722 retval = args(0).is_bool_type (); |
3209
|
723 else |
4028
|
724 print_usage ("isbool"); |
3209
|
725 |
|
726 return retval; |
|
727 } |
|
728 |
4028
|
729 DEFALIAS (islogical, isbool); |
3209
|
730 |
4028
|
731 DEFUN (iscomplex, args, , |
3428
|
732 "-*- texinfo -*-\n\ |
4028
|
733 @deftypefn {Built-in Function} {} iscomplex (@var{x})\n\ |
3428
|
734 Return true if @var{x} is a complex-valued numeric object.\n\ |
|
735 @end deftypefn") |
3186
|
736 { |
|
737 octave_value retval; |
|
738 |
|
739 if (args.length () == 1) |
3258
|
740 retval = args(0).is_complex_type (); |
3186
|
741 else |
4028
|
742 print_usage ("iscomplex"); |
3186
|
743 |
|
744 return retval; |
|
745 } |
|
746 |
3258
|
747 DEFUN (isreal, args, , |
3428
|
748 "-*- texinfo -*-\n\ |
|
749 @deftypefn {Built-in Function} {} isreal (@var{x})\n\ |
|
750 Return true if @var{x} is a real-valued numeric object.\n\ |
|
751 @end deftypefn") |
3258
|
752 { |
|
753 octave_value retval; |
|
754 |
|
755 if (args.length () == 1) |
|
756 retval = args(0).is_real_type (); |
|
757 else |
|
758 print_usage ("isreal"); |
|
759 |
|
760 return retval; |
|
761 } |
|
762 |
3202
|
763 DEFUN (isempty, args, , |
3373
|
764 "-*- texinfo -*-\n\ |
|
765 @deftypefn {Built-in Function} {} isempty (@var{a})\n\ |
|
766 Return 1 if @var{a} is an empty matrix (either the number of rows, or\n\ |
|
767 the number of columns, or both are zero). Otherwise, return 0.\n\ |
|
768 @end deftypefn") |
3202
|
769 { |
4233
|
770 octave_value retval = false; |
3202
|
771 |
|
772 if (args.length () == 1) |
|
773 { |
|
774 octave_value arg = args(0); |
|
775 |
|
776 if (arg.is_matrix_type ()) |
4233
|
777 retval = (arg.rows () == 0 || arg.columns () == 0); |
3215
|
778 else if (arg.is_list () || arg.is_string ()) |
4233
|
779 retval = (arg.length () == 0); |
3202
|
780 } |
|
781 else |
|
782 print_usage ("isempty"); |
|
783 |
|
784 return retval; |
|
785 } |
|
786 |
3206
|
787 DEFUN (isnumeric, args, , |
3428
|
788 "-*- texinfo -*-\n\ |
|
789 @deftypefn {Built-in Function} {} isnumeric (@var{x})\n\ |
|
790 Return nonzero if @var{x} is a numeric object.\n\ |
|
791 @end deftypefn") |
3206
|
792 { |
|
793 octave_value retval; |
|
794 |
|
795 if (args.length () == 1) |
3258
|
796 retval = args(0).is_numeric_type (); |
3206
|
797 else |
3238
|
798 print_usage ("isnumeric"); |
3206
|
799 |
|
800 return retval; |
|
801 } |
|
802 |
4028
|
803 DEFUN (islist, args, , |
3526
|
804 "-*- texinfo -*-\n\ |
4028
|
805 @deftypefn {Built-in Function} {} islist (@var{x})\n\ |
3428
|
806 Return nonzero if @var{x} is a list.\n\ |
|
807 @end deftypefn") |
3204
|
808 { |
|
809 octave_value retval; |
|
810 |
|
811 if (args.length () == 1) |
3258
|
812 retval = args(0).is_list (); |
3204
|
813 else |
4028
|
814 print_usage ("islist"); |
3204
|
815 |
|
816 return retval; |
|
817 } |
|
818 |
4028
|
819 DEFUN (ismatrix, args, , |
3321
|
820 "-*- texinfo -*-\n\ |
4028
|
821 @deftypefn {Built-in Function} {} ismatrix (@var{a})\n\ |
3321
|
822 Return 1 if @var{a} is a matrix. Otherwise, return 0.\n\ |
3333
|
823 @end deftypefn") |
3202
|
824 { |
4233
|
825 octave_value retval = false; |
3202
|
826 |
|
827 if (args.length () == 1) |
|
828 { |
|
829 octave_value arg = args(0); |
|
830 |
3212
|
831 if (arg.is_scalar_type () || arg.is_range ()) |
4233
|
832 retval = true; |
3202
|
833 else if (arg.is_matrix_type ()) |
4233
|
834 retval = (arg.rows () >= 1 && arg.columns () >= 1); |
3202
|
835 } |
|
836 else |
4028
|
837 print_usage ("ismatrix"); |
3202
|
838 |
|
839 return retval; |
|
840 } |
|
841 |
4028
|
842 DEFUN (isstruct, args, , |
3361
|
843 "-*- texinfo -*-\n\ |
4028
|
844 @deftypefn {Built-in Function} {} isstruct (@var{expr})\n\ |
3361
|
845 Return 1 if the value of the expression @var{expr} is a structure.\n\ |
|
846 @end deftypefn") |
939
|
847 { |
3186
|
848 octave_value retval; |
939
|
849 |
3186
|
850 if (args.length () == 1) |
3258
|
851 retval = args(0).is_map (); |
939
|
852 else |
4028
|
853 print_usage ("isstruct"); |
939
|
854 |
|
855 return retval; |
|
856 } |
|
857 |
1957
|
858 DEFUN (struct_elements, args, , |
3361
|
859 "-*- texinfo -*-\n\ |
|
860 @deftypefn {Built-in Function} {} struct_elements (@var{struct})\n\ |
|
861 Return a list of strings naming the elements of the structure\n\ |
|
862 @var{struct}. It is an error to call @code{struct_elements} with an\n\ |
|
863 argument that is not a structure.\n\ |
|
864 @end deftypefn") |
1402
|
865 { |
4233
|
866 octave_value retval; |
1402
|
867 |
|
868 int nargin = args.length (); |
|
869 |
|
870 if (nargin == 1) |
|
871 { |
|
872 if (args (0).is_map ()) |
|
873 { |
|
874 Octave_map m = args(0).map_value (); |
4233
|
875 retval = m.keys (); |
1402
|
876 } |
|
877 else |
|
878 gripe_wrong_type_arg ("struct_elements", args (0)); |
|
879 } |
|
880 else |
|
881 print_usage ("struct_elements"); |
|
882 |
|
883 return retval; |
|
884 } |
|
885 |
1957
|
886 DEFUN (struct_contains, args, , |
3361
|
887 "-*- texinfo -*-\n\ |
|
888 @deftypefn {Built-in Function} {} struct_contains (@var{expr}, @var{name})\n\ |
|
889 Return 1 if the expression @var{expr} is a structure and it includes an\n\ |
|
890 element named @var{name}. The first argument must be a structure and\n\ |
|
891 the second must be a string.\n\ |
|
892 @end deftypefn") |
1216
|
893 { |
4233
|
894 octave_value retval; |
1216
|
895 |
|
896 int nargin = args.length (); |
|
897 |
|
898 if (nargin == 2) |
|
899 { |
4233
|
900 retval = false; |
2420
|
901 |
2963
|
902 // XXX FIXME XXX -- should this work for all types that can do |
|
903 // structure reference operations? |
|
904 |
1277
|
905 if (args(0).is_map () && args(1).is_string ()) |
1216
|
906 { |
3933
|
907 std::string key = args(1).string_value (); |
|
908 |
|
909 Octave_map m = args(0).map_value (); |
|
910 |
4233
|
911 retval = m.contains (key); |
1216
|
912 } |
2420
|
913 else |
|
914 print_usage ("struct_contains"); |
1216
|
915 } |
|
916 else |
|
917 print_usage ("struct_contains"); |
|
918 |
|
919 return retval; |
|
920 } |
|
921 |
3354
|
922 static octave_value |
|
923 fill_matrix (const octave_value_list& args, double val, const char *fcn) |
523
|
924 { |
3354
|
925 octave_value retval; |
523
|
926 |
|
927 int nargin = args.length (); |
|
928 |
|
929 switch (nargin) |
|
930 { |
712
|
931 case 0: |
4114
|
932 retval = val; |
712
|
933 break; |
777
|
934 |
610
|
935 case 1: |
3354
|
936 { |
|
937 int nr, nc; |
|
938 get_dimensions (args(0), fcn, nr, nc); |
|
939 |
|
940 if (! error_state) |
|
941 retval = Matrix (nr, nc, val); |
|
942 } |
610
|
943 break; |
777
|
944 |
523
|
945 case 2: |
3354
|
946 { |
|
947 int nr, nc; |
|
948 get_dimensions (args(0), args(1), fcn, nr, nc); |
|
949 |
|
950 if (! error_state) |
|
951 retval = Matrix (nr, nc, val); |
|
952 } |
523
|
953 break; |
777
|
954 |
523
|
955 default: |
3354
|
956 print_usage (fcn); |
523
|
957 break; |
|
958 } |
|
959 |
|
960 return retval; |
|
961 } |
|
962 |
3354
|
963 DEFUN (ones, args, , |
3369
|
964 "-*- texinfo -*-\n\ |
|
965 @deftypefn {Built-in Function} {} ones (@var{x})\n\ |
|
966 @deftypefnx {Built-in Function} {} ones (@var{n}, @var{m})\n\ |
|
967 Return a matrix whose elements are all 1. The arguments are handled\n\ |
|
968 the same as the arguments for @code{eye}.\n\ |
|
969 \n\ |
|
970 If you need to create a matrix whose values are all the same, you should\n\ |
|
971 use an expression like\n\ |
|
972 \n\ |
|
973 @example\n\ |
|
974 val_matrix = val * ones (n, m)\n\ |
|
975 @end example\n\ |
|
976 @end deftypefn") |
523
|
977 { |
3354
|
978 return fill_matrix (args, 1.0, "ones"); |
523
|
979 } |
|
980 |
3354
|
981 DEFUN (zeros, args, , |
3369
|
982 "-*- texinfo -*-\n\ |
|
983 @deftypefn {Built-in Function} {} zeros (@var{x})\n\ |
|
984 @deftypefnx {Built-in Function} {} zeros (@var{n}, @var{m})\n\ |
|
985 Return a matrix whose elements are all 0. The arguments are handled\n\ |
|
986 the same as the arguments for @code{eye}.\n\ |
|
987 @end deftypefn") |
523
|
988 { |
3354
|
989 return fill_matrix (args, 0.0, "zeros"); |
|
990 } |
523
|
991 |
3354
|
992 static Matrix |
|
993 identity_matrix (int nr, int nc) |
|
994 { |
523
|
995 Matrix m (nr, nc, 0.0); |
|
996 |
|
997 if (nr > 0 && nc > 0) |
|
998 { |
|
999 int n = MIN (nr, nc); |
|
1000 for (int i = 0; i < n; i++) |
2305
|
1001 m (i, i) = 1.0; |
523
|
1002 } |
|
1003 |
|
1004 return m; |
|
1005 } |
|
1006 |
1957
|
1007 DEFUN (eye, args, , |
3369
|
1008 "-*- texinfo -*-\n\ |
|
1009 @deftypefn {Built-in Function} {} eye (@var{x})\n\ |
|
1010 @deftypefnx {Built-in Function} {} eye (@var{n}, @var{m})\n\ |
|
1011 Return an identity matrix. If invoked with a single scalar argument,\n\ |
|
1012 @code{eye} returns a square matrix with the dimension specified. If you\n\ |
|
1013 supply two scalar arguments, @code{eye} takes them to be the number of\n\ |
|
1014 rows and columns. If given a vector with two elements, @code{eye} uses\n\ |
|
1015 the values of the elements as the number of rows and columns,\n\ |
|
1016 respectively. For example,\n\ |
|
1017 \n\ |
|
1018 @example\n\ |
|
1019 @group\n\ |
|
1020 eye (3)\n\ |
|
1021 @result{} 1 0 0\n\ |
|
1022 0 1 0\n\ |
|
1023 0 0 1\n\ |
|
1024 @end group\n\ |
|
1025 @end example\n\ |
|
1026 \n\ |
|
1027 The following expressions all produce the same result:\n\ |
|
1028 \n\ |
|
1029 @example\n\ |
|
1030 @group\n\ |
|
1031 eye (2)\n\ |
|
1032 @equiv{}\n\ |
|
1033 eye (2, 2)\n\ |
|
1034 @equiv{}\n\ |
|
1035 eye (size ([1, 2; 3, 4])\n\ |
|
1036 @end group\n\ |
|
1037 @end example\n\ |
|
1038 \n\ |
|
1039 For compatibility with @sc{Matlab}, calling @code{eye} with no arguments\n\ |
|
1040 is equivalent to calling it with an argument of 1.\n\ |
|
1041 @end deftypefn") |
523
|
1042 { |
3354
|
1043 octave_value retval; |
523
|
1044 |
|
1045 int nargin = args.length (); |
|
1046 |
|
1047 switch (nargin) |
|
1048 { |
712
|
1049 case 0: |
|
1050 retval = 1.0; |
|
1051 break; |
777
|
1052 |
610
|
1053 case 1: |
3354
|
1054 { |
|
1055 int nr, nc; |
|
1056 get_dimensions (args(0), "eye", nr, nc); |
|
1057 |
|
1058 if (! error_state) |
|
1059 retval = identity_matrix (nr, nc); |
|
1060 } |
610
|
1061 break; |
777
|
1062 |
523
|
1063 case 2: |
3354
|
1064 { |
|
1065 int nr, nc; |
|
1066 get_dimensions (args(0), args(1), "eye", nr, nc); |
|
1067 |
|
1068 if (! error_state) |
|
1069 retval = identity_matrix (nr, nc); |
|
1070 } |
523
|
1071 break; |
777
|
1072 |
523
|
1073 default: |
|
1074 print_usage ("eye"); |
|
1075 break; |
|
1076 } |
|
1077 |
|
1078 return retval; |
|
1079 } |
|
1080 |
1957
|
1081 DEFUN (linspace, args, , |
3369
|
1082 "-*- texinfo -*-\n\ |
|
1083 @deftypefn {Built-in Function} {} linspace (@var{base}, @var{limit}, @var{n})\n\ |
|
1084 Return a row vector with @var{n} linearly spaced elements between\n\ |
|
1085 @var{base} and @var{limit}. The number of elements, @var{n}, must be\n\ |
|
1086 greater than 1. The @var{base} and @var{limit} are always included in\n\ |
|
1087 the range. If @var{base} is greater than @var{limit}, the elements are\n\ |
|
1088 stored in decreasing order. If the number of points is not specified, a\n\ |
|
1089 value of 100 is used.\n\ |
1100
|
1090 \n\ |
3369
|
1091 The @code{linspace} function always returns a row vector, regardless of\n\ |
|
1092 the value of @code{prefer_column_vectors}.\n\ |
|
1093 @end deftypefn") |
1100
|
1094 { |
3418
|
1095 octave_value retval; |
1100
|
1096 |
|
1097 int nargin = args.length (); |
|
1098 |
|
1099 int npoints = 100; |
|
1100 |
1940
|
1101 if (nargin != 2 && nargin != 3) |
|
1102 { |
|
1103 print_usage ("linspace"); |
|
1104 return retval; |
|
1105 } |
|
1106 |
1100
|
1107 if (nargin == 3) |
3202
|
1108 npoints = args(2).nint_value (); |
1100
|
1109 |
|
1110 if (! error_state) |
|
1111 { |
3322
|
1112 octave_value arg_1 = args(0); |
|
1113 octave_value arg_2 = args(1); |
1100
|
1114 |
3322
|
1115 if (arg_1.is_complex_type () || arg_2.is_complex_type ()) |
|
1116 { |
|
1117 Complex x1 = arg_1.complex_value (); |
|
1118 Complex x2 = arg_2.complex_value (); |
|
1119 |
|
1120 if (! error_state) |
1100
|
1121 { |
3322
|
1122 ComplexRowVector rv = linspace (x1, x2, npoints); |
1100
|
1123 |
|
1124 if (! error_state) |
3418
|
1125 retval = rv; |
1100
|
1126 } |
|
1127 } |
|
1128 else |
3322
|
1129 { |
|
1130 double x1 = arg_1.double_value (); |
|
1131 double x2 = arg_2.double_value (); |
|
1132 |
|
1133 if (! error_state) |
|
1134 { |
|
1135 RowVector rv = linspace (x1, x2, npoints); |
|
1136 |
|
1137 if (! error_state) |
3418
|
1138 retval = rv; |
3322
|
1139 } |
|
1140 } |
1100
|
1141 } |
|
1142 |
|
1143 return retval; |
|
1144 } |
|
1145 |
2184
|
1146 void |
|
1147 symbols_of_data (void) |
|
1148 { |
3321
|
1149 |
|
1150 #define IMAGINARY_DOC_STRING "-*- texinfo -*-\n\ |
|
1151 @defvr {Built-in Variable} I\n\ |
|
1152 @defvrx {Built-in Variable} J\n\ |
|
1153 @defvrx {Built-in Variable} i\n\ |
|
1154 @defvrx {Built-in Variable} j\n\ |
|
1155 A pure imaginary number, defined as\n\ |
|
1156 @iftex\n\ |
|
1157 @tex\n\ |
|
1158 $\\sqrt{-1}$.\n\ |
|
1159 @end tex\n\ |
|
1160 @end iftex\n\ |
|
1161 @ifinfo\n\ |
|
1162 @code{sqrt (-1)}.\n\ |
|
1163 @end ifinfo\n\ |
|
1164 The @code{I} and @code{J} forms are true constants, and cannot be\n\ |
|
1165 modified. The @code{i} and @code{j} forms are like ordinary variables,\n\ |
|
1166 and may be used for other purposes. However, unlike other variables,\n\ |
|
1167 they once again assume their special predefined values if they are\n\ |
|
1168 cleared @xref{Status of Variables}.\n\ |
|
1169 @end defvr" |
|
1170 |
|
1171 #define INFINITY_DOC_STRING "-*- texinfo -*-\n\ |
|
1172 @defvr {Built-in Variable} Inf\n\ |
|
1173 @defvrx {Built-in Variable} inf\n\ |
|
1174 Infinity. This is the result of an operation like 1/0, or an operation\n\ |
|
1175 that results in a floating point overflow.\n\ |
|
1176 @end defvr" |
|
1177 |
|
1178 #define NAN_DOC_STRING "-*- texinfo -*-\n\ |
|
1179 @defvr {Built-in Variable} NaN\n\ |
|
1180 @defvrx {Built-in Variable} nan\n\ |
|
1181 Not a number. This is the result of an operation like\n\ |
|
1182 @iftex\n\ |
|
1183 @tex\n\ |
|
1184 $0/0$, or $\\infty - \\infty$,\n\ |
|
1185 @end tex\n\ |
|
1186 @end iftex\n\ |
|
1187 @ifinfo\n\ |
|
1188 0/0, or @samp{Inf - Inf},\n\ |
|
1189 @end ifinfo\n\ |
|
1190 or any operation with a NaN.\n\ |
|
1191 \n\ |
|
1192 Note that NaN always compares not equal to NaN. This behavior is\n\ |
|
1193 specified by the IEEE standard for floating point arithmetic. To\n\ |
|
1194 find NaN values, you must use the @code{isnan} function.\n\ |
|
1195 @end defvr" |
|
1196 |
3141
|
1197 DEFCONST (I, Complex (0.0, 1.0), |
3321
|
1198 IMAGINARY_DOC_STRING); |
2184
|
1199 |
4102
|
1200 DEFCONST (Inf, lo_ieee_inf_value (), |
3321
|
1201 INFINITY_DOC_STRING); |
2184
|
1202 |
3141
|
1203 DEFCONST (J, Complex (0.0, 1.0), |
3321
|
1204 IMAGINARY_DOC_STRING); |
2184
|
1205 |
4102
|
1206 DEFCONST (NA, lo_ieee_na_value (), |
4025
|
1207 "-*- texinfo -*-\n\ |
|
1208 @defvr {Built-in Variable} NA\n\ |
|
1209 Missing value.\n\ |
|
1210 @end defvr"); |
|
1211 |
4102
|
1212 DEFCONST (NaN, lo_ieee_nan_value (), |
3321
|
1213 NAN_DOC_STRING); |
2184
|
1214 |
|
1215 #if defined (M_E) |
|
1216 double e_val = M_E; |
|
1217 #else |
|
1218 double e_val = exp (1.0); |
|
1219 #endif |
|
1220 |
3141
|
1221 DEFCONST (e, e_val, |
3321
|
1222 "-*- texinfo -*-\n\ |
|
1223 @defvr {Built-in Variable} e\n\ |
|
1224 The base of natural logarithms. The constant\n\ |
|
1225 @iftex\n\ |
|
1226 @tex\n\ |
|
1227 $e$\n\ |
|
1228 @end tex\n\ |
|
1229 @end iftex\n\ |
|
1230 @ifinfo\n\ |
|
1231 @var{e}\n\ |
|
1232 @end ifinfo\n\ |
|
1233 satisfies the equation\n\ |
|
1234 @iftex\n\ |
|
1235 @tex\n\ |
|
1236 $\\log (e) = 1$.\n\ |
|
1237 @end tex\n\ |
|
1238 @end iftex\n\ |
|
1239 @ifinfo\n\ |
|
1240 @code{log} (@var{e}) = 1.\n\ |
|
1241 @end ifinfo\n\ |
|
1242 @end defvr"); |
2184
|
1243 |
3141
|
1244 DEFCONST (eps, DBL_EPSILON, |
3321
|
1245 "-*- texinfo -*-\n\ |
|
1246 @defvr {Built-in Variable} eps\n\ |
|
1247 The machine precision. More precisely, @code{eps} is the largest\n\ |
|
1248 relative spacing between any two adjacent numbers in the machine's\n\ |
|
1249 floating point system. This number is obviously system-dependent. On\n\ |
|
1250 machines that support 64 bit IEEE floating point arithmetic, @code{eps}\n\ |
|
1251 is approximately\n\ |
|
1252 @ifinfo\n\ |
|
1253 2.2204e-16.\n\ |
|
1254 @end ifinfo\n\ |
|
1255 @iftex\n\ |
|
1256 @tex\n\ |
|
1257 $2.2204\\times10^{-16}$.\n\ |
|
1258 @end tex\n\ |
|
1259 @end iftex\n\ |
|
1260 @end defvr"); |
2184
|
1261 |
3258
|
1262 DEFCONST (false, false, |
3443
|
1263 "-*- texinfo -*-\n\ |
|
1264 @defvr {Built-in Variable} false\n\ |
|
1265 Logical false value.\n\ |
|
1266 @end defvr"); |
3258
|
1267 |
3141
|
1268 DEFCONST (i, Complex (0.0, 1.0), |
3321
|
1269 IMAGINARY_DOC_STRING); |
2184
|
1270 |
4102
|
1271 DEFCONST (inf, lo_ieee_inf_value (), |
3321
|
1272 INFINITY_DOC_STRING); |
2184
|
1273 |
3141
|
1274 DEFCONST (j, Complex (0.0, 1.0), |
3321
|
1275 IMAGINARY_DOC_STRING); |
2184
|
1276 |
4102
|
1277 DEFCONST (nan, lo_ieee_nan_value (), |
3321
|
1278 NAN_DOC_STRING); |
2184
|
1279 |
|
1280 #if defined (M_PI) |
|
1281 double pi_val = M_PI; |
|
1282 #else |
|
1283 double pi_val = 4.0 * atan (1.0); |
|
1284 #endif |
|
1285 |
3141
|
1286 DEFCONST (pi, pi_val, |
3321
|
1287 "-*- texinfo -*-\n\ |
|
1288 @defvr {Built-in Variable} pi\n\ |
|
1289 The ratio of the circumference of a circle to its diameter.\n\ |
|
1290 Internally, @code{pi} is computed as @samp{4.0 * atan (1.0)}.\n\ |
|
1291 @end defvr"); |
2184
|
1292 |
3141
|
1293 DEFCONST (realmax, DBL_MAX, |
3321
|
1294 "-*- texinfo -*-\n\ |
|
1295 @defvr {Built-in Variable} realmax\n\ |
|
1296 The largest floating point number that is representable. The actual\n\ |
|
1297 value is system-dependent. On machines that support 64 bit IEEE\n\ |
|
1298 floating point arithmetic, @code{realmax} is approximately\n\ |
|
1299 @ifinfo\n\ |
|
1300 1.7977e+308\n\ |
|
1301 @end ifinfo\n\ |
|
1302 @iftex\n\ |
|
1303 @tex\n\ |
|
1304 $1.7977\\times10^{308}$.\n\ |
|
1305 @end tex\n\ |
|
1306 @end iftex\n\ |
|
1307 @end defvr"); |
2184
|
1308 |
3141
|
1309 DEFCONST (realmin, DBL_MIN, |
3321
|
1310 "-*- texinfo -*-\n\ |
|
1311 @defvr {Built-in Variable} realmin\n\ |
|
1312 The smallest floating point number that is representable. The actual\n\ |
|
1313 value is system-dependent. On machines that support 64 bit IEEE\n\ |
|
1314 floating point arithmetic, @code{realmin} is approximately\n\ |
|
1315 @ifinfo\n\ |
|
1316 2.2251e-308\n\ |
|
1317 @end ifinfo\n\ |
|
1318 @iftex\n\ |
|
1319 @tex\n\ |
|
1320 $2.2251\\times10^{-308}$.\n\ |
|
1321 @end tex\n\ |
|
1322 @end iftex\n\ |
|
1323 @end defvr"); |
2188
|
1324 |
3258
|
1325 DEFCONST (true, true, |
3443
|
1326 "-*- texinfo -*-\n\ |
|
1327 @defvr {Built-in Variable} true\n\ |
|
1328 Logical true value.\n\ |
|
1329 @end defvr"); |
3354
|
1330 |
2184
|
1331 } |
|
1332 |
523
|
1333 /* |
|
1334 ;;; Local Variables: *** |
|
1335 ;;; mode: C++ *** |
|
1336 ;;; End: *** |
|
1337 */ |