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