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