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