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