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