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 |
4481
|
931 int ndim = 0; |
|
932 int type = 0; |
|
933 |
|
934 Array<int> dims; |
|
935 |
|
936 // Check for type information. |
|
937 |
|
938 if (nargin > 0 && args(nargin-1).is_string ()) |
|
939 { |
|
940 nargin--; |
|
941 |
|
942 // XXX FIXME XXX -- allow type of the resulting matrix to be |
|
943 // specified, e.g. |
|
944 // |
|
945 // zeros(n1, n2, ..., 'real') |
|
946 // zeros(n1, n2, ..., 'complex') |
|
947 // |
|
948 // type = get_type (args(nargin).string_value ()); |
|
949 } |
|
950 |
|
951 // determine matrix dimension |
|
952 |
523
|
953 switch (nargin) |
|
954 { |
712
|
955 case 0: |
4481
|
956 ndim = 0; |
|
957 type = 0; |
712
|
958 break; |
777
|
959 |
610
|
960 case 1: |
4481
|
961 get_dimensions (args(0), fcn, dims); |
610
|
962 break; |
777
|
963 |
4481
|
964 default: |
|
965 { |
|
966 dims.resize (nargin); |
|
967 |
|
968 for (int i = 0; i < nargin; i++) |
|
969 { |
|
970 dims(i) = args(i).is_empty () ? 0 : args(i).nint_value (); |
|
971 |
|
972 if (error_state) |
|
973 { |
|
974 error ("%s: expecting scalar arguments", fcn); |
|
975 break; |
|
976 } |
|
977 } |
|
978 } |
|
979 break; |
|
980 } |
|
981 |
|
982 if (! error_state) |
|
983 { |
|
984 ndim = dims.length (); |
|
985 |
|
986 check_dimensions (dims, fcn); |
3354
|
987 |
4481
|
988 if (! error_state) |
|
989 { |
|
990 // Construct either scalar, matrix or N-d array. |
|
991 |
|
992 switch (ndim) |
|
993 { |
|
994 case 0: |
|
995 retval = val; |
|
996 break; |
777
|
997 |
4481
|
998 case 1: |
|
999 retval = Matrix (dims(0), dims(0), val); |
|
1000 break; |
|
1001 |
|
1002 case 2: |
|
1003 retval = Matrix (dims(0), dims(1), val); |
|
1004 break; |
|
1005 |
|
1006 default: |
|
1007 retval = ArrayN<double> (dims, val); |
|
1008 break; |
|
1009 } |
|
1010 } |
523
|
1011 } |
|
1012 |
|
1013 return retval; |
|
1014 } |
|
1015 |
3354
|
1016 DEFUN (ones, args, , |
3369
|
1017 "-*- texinfo -*-\n\ |
|
1018 @deftypefn {Built-in Function} {} ones (@var{x})\n\ |
|
1019 @deftypefnx {Built-in Function} {} ones (@var{n}, @var{m})\n\ |
4481
|
1020 @deftypefnx {Built-in Function} {} ones (@var{n}, @var{m}, @var{k},...)\n\ |
|
1021 Return a matrix or N-dimensional array whose elements are all 1.\n\ |
|
1022 The arguments are handled the same as the arguments for @code{eye}.\n\ |
3369
|
1023 \n\ |
|
1024 If you need to create a matrix whose values are all the same, you should\n\ |
|
1025 use an expression like\n\ |
|
1026 \n\ |
|
1027 @example\n\ |
|
1028 val_matrix = val * ones (n, m)\n\ |
|
1029 @end example\n\ |
|
1030 @end deftypefn") |
523
|
1031 { |
3354
|
1032 return fill_matrix (args, 1.0, "ones"); |
523
|
1033 } |
|
1034 |
3354
|
1035 DEFUN (zeros, args, , |
3369
|
1036 "-*- texinfo -*-\n\ |
|
1037 @deftypefn {Built-in Function} {} zeros (@var{x})\n\ |
|
1038 @deftypefnx {Built-in Function} {} zeros (@var{n}, @var{m})\n\ |
4481
|
1039 @deftypefnx {Built-in Function} {} zeros (@var{n}, @var{m}, @var{k},...)\n\ |
|
1040 Return a matrix or N-dimensional array whose elements are all 0.\n\ |
|
1041 The arguments are handled the same as the arguments for @code{eye}.\n\ |
3369
|
1042 @end deftypefn") |
523
|
1043 { |
3354
|
1044 return fill_matrix (args, 0.0, "zeros"); |
|
1045 } |
523
|
1046 |
1957
|
1047 DEFUN (eye, args, , |
3369
|
1048 "-*- texinfo -*-\n\ |
|
1049 @deftypefn {Built-in Function} {} eye (@var{x})\n\ |
|
1050 @deftypefnx {Built-in Function} {} eye (@var{n}, @var{m})\n\ |
|
1051 Return an identity matrix. If invoked with a single scalar argument,\n\ |
|
1052 @code{eye} returns a square matrix with the dimension specified. If you\n\ |
|
1053 supply two scalar arguments, @code{eye} takes them to be the number of\n\ |
|
1054 rows and columns. If given a vector with two elements, @code{eye} uses\n\ |
|
1055 the values of the elements as the number of rows and columns,\n\ |
|
1056 respectively. For example,\n\ |
|
1057 \n\ |
|
1058 @example\n\ |
|
1059 @group\n\ |
|
1060 eye (3)\n\ |
|
1061 @result{} 1 0 0\n\ |
|
1062 0 1 0\n\ |
|
1063 0 0 1\n\ |
|
1064 @end group\n\ |
|
1065 @end example\n\ |
|
1066 \n\ |
|
1067 The following expressions all produce the same result:\n\ |
|
1068 \n\ |
|
1069 @example\n\ |
|
1070 @group\n\ |
|
1071 eye (2)\n\ |
|
1072 @equiv{}\n\ |
|
1073 eye (2, 2)\n\ |
|
1074 @equiv{}\n\ |
|
1075 eye (size ([1, 2; 3, 4])\n\ |
|
1076 @end group\n\ |
|
1077 @end example\n\ |
|
1078 \n\ |
|
1079 For compatibility with @sc{Matlab}, calling @code{eye} with no arguments\n\ |
|
1080 is equivalent to calling it with an argument of 1.\n\ |
|
1081 @end deftypefn") |
523
|
1082 { |
3354
|
1083 octave_value retval; |
523
|
1084 |
|
1085 int nargin = args.length (); |
|
1086 |
|
1087 switch (nargin) |
|
1088 { |
712
|
1089 case 0: |
|
1090 retval = 1.0; |
|
1091 break; |
777
|
1092 |
610
|
1093 case 1: |
3354
|
1094 { |
|
1095 int nr, nc; |
|
1096 get_dimensions (args(0), "eye", nr, nc); |
|
1097 |
|
1098 if (! error_state) |
|
1099 retval = identity_matrix (nr, nc); |
|
1100 } |
610
|
1101 break; |
777
|
1102 |
523
|
1103 case 2: |
3354
|
1104 { |
|
1105 int nr, nc; |
|
1106 get_dimensions (args(0), args(1), "eye", nr, nc); |
|
1107 |
|
1108 if (! error_state) |
|
1109 retval = identity_matrix (nr, nc); |
|
1110 } |
523
|
1111 break; |
777
|
1112 |
523
|
1113 default: |
|
1114 print_usage ("eye"); |
|
1115 break; |
|
1116 } |
|
1117 |
|
1118 return retval; |
|
1119 } |
|
1120 |
1957
|
1121 DEFUN (linspace, args, , |
3369
|
1122 "-*- texinfo -*-\n\ |
|
1123 @deftypefn {Built-in Function} {} linspace (@var{base}, @var{limit}, @var{n})\n\ |
|
1124 Return a row vector with @var{n} linearly spaced elements between\n\ |
|
1125 @var{base} and @var{limit}. The number of elements, @var{n}, must be\n\ |
|
1126 greater than 1. The @var{base} and @var{limit} are always included in\n\ |
|
1127 the range. If @var{base} is greater than @var{limit}, the elements are\n\ |
|
1128 stored in decreasing order. If the number of points is not specified, a\n\ |
|
1129 value of 100 is used.\n\ |
1100
|
1130 \n\ |
4455
|
1131 The @code{linspace} function always returns a row vector.\n\ |
3369
|
1132 @end deftypefn") |
1100
|
1133 { |
3418
|
1134 octave_value retval; |
1100
|
1135 |
|
1136 int nargin = args.length (); |
|
1137 |
|
1138 int npoints = 100; |
|
1139 |
1940
|
1140 if (nargin != 2 && nargin != 3) |
|
1141 { |
|
1142 print_usage ("linspace"); |
|
1143 return retval; |
|
1144 } |
|
1145 |
1100
|
1146 if (nargin == 3) |
3202
|
1147 npoints = args(2).nint_value (); |
1100
|
1148 |
|
1149 if (! error_state) |
|
1150 { |
3322
|
1151 octave_value arg_1 = args(0); |
|
1152 octave_value arg_2 = args(1); |
1100
|
1153 |
3322
|
1154 if (arg_1.is_complex_type () || arg_2.is_complex_type ()) |
|
1155 { |
|
1156 Complex x1 = arg_1.complex_value (); |
|
1157 Complex x2 = arg_2.complex_value (); |
|
1158 |
|
1159 if (! error_state) |
1100
|
1160 { |
3322
|
1161 ComplexRowVector rv = linspace (x1, x2, npoints); |
1100
|
1162 |
|
1163 if (! error_state) |
3418
|
1164 retval = rv; |
1100
|
1165 } |
|
1166 } |
|
1167 else |
3322
|
1168 { |
|
1169 double x1 = arg_1.double_value (); |
|
1170 double x2 = arg_2.double_value (); |
|
1171 |
|
1172 if (! error_state) |
|
1173 { |
|
1174 RowVector rv = linspace (x1, x2, npoints); |
|
1175 |
|
1176 if (! error_state) |
3418
|
1177 retval = rv; |
3322
|
1178 } |
|
1179 } |
1100
|
1180 } |
|
1181 |
|
1182 return retval; |
|
1183 } |
|
1184 |
2184
|
1185 void |
|
1186 symbols_of_data (void) |
|
1187 { |
3321
|
1188 |
|
1189 #define IMAGINARY_DOC_STRING "-*- texinfo -*-\n\ |
|
1190 @defvr {Built-in Variable} I\n\ |
|
1191 @defvrx {Built-in Variable} J\n\ |
|
1192 @defvrx {Built-in Variable} i\n\ |
|
1193 @defvrx {Built-in Variable} j\n\ |
|
1194 A pure imaginary number, defined as\n\ |
|
1195 @iftex\n\ |
|
1196 @tex\n\ |
|
1197 $\\sqrt{-1}$.\n\ |
|
1198 @end tex\n\ |
|
1199 @end iftex\n\ |
|
1200 @ifinfo\n\ |
|
1201 @code{sqrt (-1)}.\n\ |
|
1202 @end ifinfo\n\ |
|
1203 The @code{I} and @code{J} forms are true constants, and cannot be\n\ |
|
1204 modified. The @code{i} and @code{j} forms are like ordinary variables,\n\ |
|
1205 and may be used for other purposes. However, unlike other variables,\n\ |
|
1206 they once again assume their special predefined values if they are\n\ |
|
1207 cleared @xref{Status of Variables}.\n\ |
|
1208 @end defvr" |
|
1209 |
|
1210 #define INFINITY_DOC_STRING "-*- texinfo -*-\n\ |
|
1211 @defvr {Built-in Variable} Inf\n\ |
|
1212 @defvrx {Built-in Variable} inf\n\ |
|
1213 Infinity. This is the result of an operation like 1/0, or an operation\n\ |
|
1214 that results in a floating point overflow.\n\ |
|
1215 @end defvr" |
|
1216 |
|
1217 #define NAN_DOC_STRING "-*- texinfo -*-\n\ |
|
1218 @defvr {Built-in Variable} NaN\n\ |
|
1219 @defvrx {Built-in Variable} nan\n\ |
|
1220 Not a number. This is the result of an operation like\n\ |
|
1221 @iftex\n\ |
|
1222 @tex\n\ |
|
1223 $0/0$, or $\\infty - \\infty$,\n\ |
|
1224 @end tex\n\ |
|
1225 @end iftex\n\ |
|
1226 @ifinfo\n\ |
|
1227 0/0, or @samp{Inf - Inf},\n\ |
|
1228 @end ifinfo\n\ |
|
1229 or any operation with a NaN.\n\ |
|
1230 \n\ |
|
1231 Note that NaN always compares not equal to NaN. This behavior is\n\ |
|
1232 specified by the IEEE standard for floating point arithmetic. To\n\ |
|
1233 find NaN values, you must use the @code{isnan} function.\n\ |
|
1234 @end defvr" |
|
1235 |
3141
|
1236 DEFCONST (I, Complex (0.0, 1.0), |
3321
|
1237 IMAGINARY_DOC_STRING); |
2184
|
1238 |
4102
|
1239 DEFCONST (Inf, lo_ieee_inf_value (), |
3321
|
1240 INFINITY_DOC_STRING); |
2184
|
1241 |
3141
|
1242 DEFCONST (J, Complex (0.0, 1.0), |
3321
|
1243 IMAGINARY_DOC_STRING); |
2184
|
1244 |
4102
|
1245 DEFCONST (NA, lo_ieee_na_value (), |
4025
|
1246 "-*- texinfo -*-\n\ |
|
1247 @defvr {Built-in Variable} NA\n\ |
|
1248 Missing value.\n\ |
|
1249 @end defvr"); |
|
1250 |
4102
|
1251 DEFCONST (NaN, lo_ieee_nan_value (), |
3321
|
1252 NAN_DOC_STRING); |
2184
|
1253 |
|
1254 #if defined (M_E) |
|
1255 double e_val = M_E; |
|
1256 #else |
|
1257 double e_val = exp (1.0); |
|
1258 #endif |
|
1259 |
3141
|
1260 DEFCONST (e, e_val, |
3321
|
1261 "-*- texinfo -*-\n\ |
|
1262 @defvr {Built-in Variable} e\n\ |
|
1263 The base of natural logarithms. The constant\n\ |
|
1264 @iftex\n\ |
|
1265 @tex\n\ |
|
1266 $e$\n\ |
|
1267 @end tex\n\ |
|
1268 @end iftex\n\ |
|
1269 @ifinfo\n\ |
|
1270 @var{e}\n\ |
|
1271 @end ifinfo\n\ |
|
1272 satisfies the equation\n\ |
|
1273 @iftex\n\ |
|
1274 @tex\n\ |
|
1275 $\\log (e) = 1$.\n\ |
|
1276 @end tex\n\ |
|
1277 @end iftex\n\ |
|
1278 @ifinfo\n\ |
|
1279 @code{log} (@var{e}) = 1.\n\ |
|
1280 @end ifinfo\n\ |
|
1281 @end defvr"); |
2184
|
1282 |
3141
|
1283 DEFCONST (eps, DBL_EPSILON, |
3321
|
1284 "-*- texinfo -*-\n\ |
|
1285 @defvr {Built-in Variable} eps\n\ |
|
1286 The machine precision. More precisely, @code{eps} is the largest\n\ |
|
1287 relative spacing between any two adjacent numbers in the machine's\n\ |
|
1288 floating point system. This number is obviously system-dependent. On\n\ |
|
1289 machines that support 64 bit IEEE floating point arithmetic, @code{eps}\n\ |
|
1290 is approximately\n\ |
|
1291 @ifinfo\n\ |
|
1292 2.2204e-16.\n\ |
|
1293 @end ifinfo\n\ |
|
1294 @iftex\n\ |
|
1295 @tex\n\ |
|
1296 $2.2204\\times10^{-16}$.\n\ |
|
1297 @end tex\n\ |
|
1298 @end iftex\n\ |
|
1299 @end defvr"); |
2184
|
1300 |
3258
|
1301 DEFCONST (false, false, |
3443
|
1302 "-*- texinfo -*-\n\ |
|
1303 @defvr {Built-in Variable} false\n\ |
|
1304 Logical false value.\n\ |
|
1305 @end defvr"); |
3258
|
1306 |
3141
|
1307 DEFCONST (i, Complex (0.0, 1.0), |
3321
|
1308 IMAGINARY_DOC_STRING); |
2184
|
1309 |
4102
|
1310 DEFCONST (inf, lo_ieee_inf_value (), |
3321
|
1311 INFINITY_DOC_STRING); |
2184
|
1312 |
3141
|
1313 DEFCONST (j, Complex (0.0, 1.0), |
3321
|
1314 IMAGINARY_DOC_STRING); |
2184
|
1315 |
4102
|
1316 DEFCONST (nan, lo_ieee_nan_value (), |
3321
|
1317 NAN_DOC_STRING); |
2184
|
1318 |
|
1319 #if defined (M_PI) |
|
1320 double pi_val = M_PI; |
|
1321 #else |
|
1322 double pi_val = 4.0 * atan (1.0); |
|
1323 #endif |
|
1324 |
3141
|
1325 DEFCONST (pi, pi_val, |
3321
|
1326 "-*- texinfo -*-\n\ |
|
1327 @defvr {Built-in Variable} pi\n\ |
|
1328 The ratio of the circumference of a circle to its diameter.\n\ |
|
1329 Internally, @code{pi} is computed as @samp{4.0 * atan (1.0)}.\n\ |
|
1330 @end defvr"); |
2184
|
1331 |
3141
|
1332 DEFCONST (realmax, DBL_MAX, |
3321
|
1333 "-*- texinfo -*-\n\ |
|
1334 @defvr {Built-in Variable} realmax\n\ |
|
1335 The largest floating point number that is representable. The actual\n\ |
4303
|
1336 value is system-dependent. On machines that support 64-bit IEEE\n\ |
3321
|
1337 floating point arithmetic, @code{realmax} is approximately\n\ |
|
1338 @ifinfo\n\ |
|
1339 1.7977e+308\n\ |
|
1340 @end ifinfo\n\ |
|
1341 @iftex\n\ |
|
1342 @tex\n\ |
|
1343 $1.7977\\times10^{308}$.\n\ |
|
1344 @end tex\n\ |
|
1345 @end iftex\n\ |
|
1346 @end defvr"); |
2184
|
1347 |
3141
|
1348 DEFCONST (realmin, DBL_MIN, |
3321
|
1349 "-*- texinfo -*-\n\ |
|
1350 @defvr {Built-in Variable} realmin\n\ |
4303
|
1351 The smallest normalized floating point number that is representable.\n\ |
|
1352 The actual value is system-dependent. On machines that support\n\ |
|
1353 64-bit IEEE floating point arithmetic, @code{realmin} is approximately\n\ |
3321
|
1354 @ifinfo\n\ |
|
1355 2.2251e-308\n\ |
|
1356 @end ifinfo\n\ |
|
1357 @iftex\n\ |
|
1358 @tex\n\ |
|
1359 $2.2251\\times10^{-308}$.\n\ |
|
1360 @end tex\n\ |
|
1361 @end iftex\n\ |
|
1362 @end defvr"); |
2188
|
1363 |
3258
|
1364 DEFCONST (true, true, |
3443
|
1365 "-*- texinfo -*-\n\ |
|
1366 @defvr {Built-in Variable} true\n\ |
|
1367 Logical true value.\n\ |
|
1368 @end defvr"); |
3354
|
1369 |
2184
|
1370 } |
|
1371 |
523
|
1372 /* |
|
1373 ;;; Local Variables: *** |
|
1374 ;;; mode: C++ *** |
|
1375 ;;; End: *** |
|
1376 */ |