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