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