Mercurial > octave
annotate doc/interpreter/numbers.txi @ 10791:3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
interpreter/doccheck: New directory for spelling/grammar scripts.
interpreter/doccheck/README: Instructions for using scripts.
interpreter/doccheck/spellcheck: Script to spellcheck a Texinfo file.
interpreter/doccheck/aspell.conf: GNU Aspell configuration file for
Octave documentation.
interpreter/doccheck/aspell-octave.en.pws: Private Aspell dictionary.
interpreter/doccheck/add_to_aspell_dict: Script to add new
Octave-specific words to
private Aspell dictionary.
interpreter/octave.texi: New @nospell macro which forces Aspell
to ignore the word marked by the macro.
interpreter/mk_doc_cache.m: Skip new @nospell macro when building
doc_cache.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 17 Jul 2010 19:53:01 -0700 |
parents | 923c7cb7f13f |
children | 322f43e0e170 |
rev | line source |
---|---|
8920 | 1 @c Copyright (C) 1996, 1997, 2007, 2008, 2009 John W. Eaton |
7018 | 2 @c |
3 @c This file is part of Octave. | |
4 @c | |
5 @c Octave is free software; you can redistribute it and/or modify it | |
6 @c under the terms of the GNU General Public License as published by the | |
7 @c Free Software Foundation; either version 3 of the License, or (at | |
8 @c your option) any later version. | |
9 @c | |
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 @c for more details. | |
14 @c | |
15 @c You should have received a copy of the GNU General Public License | |
16 @c along with Octave; see the file COPYING. If not, see | |
17 @c <http://www.gnu.org/licenses/>. | |
3294 | 18 |
4167 | 19 @node Numeric Data Types |
3294 | 20 @chapter Numeric Data Types |
21 @cindex numeric constant | |
22 @cindex numeric value | |
23 | |
24 A @dfn{numeric constant} may be a scalar, a vector, or a matrix, and it | |
25 may contain complex values. | |
26 | |
27 The simplest form of a numeric constant, a scalar, is a single number | |
28 that can be an integer, a decimal fraction, a number in scientific | |
6620 | 29 (exponential) notation, or a complex number. Note that by default numeric |
3294 | 30 constants are represented within Octave in double-precision floating |
31 point format (complex constants are stored as pairs of double-precision | |
6620 | 32 floating point values). It is however possible to represent real |
8534
0eb83938c8bc
Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
33 integers as described in @ref{Integer Data Types}. Here are some |
0eb83938c8bc
Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
34 examples of real-valued numeric constants, which all have the same |
0eb83938c8bc
Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
35 value: |
3294 | 36 |
37 @example | |
38 @group | |
39 105 | |
40 1.05e+2 | |
41 1050e-1 | |
42 @end group | |
43 @end example | |
44 | |
45 To specify complex constants, you can write an expression of the form | |
46 | |
47 @example | |
48 @group | |
49 3 + 4i | |
50 3.0 + 4.0i | |
51 0.3e1 + 40e-1i | |
52 @end group | |
53 @end example | |
54 | |
6620 | 55 @noindent |
3294 | 56 all of which are equivalent. The letter @samp{i} in the previous example |
57 stands for the pure imaginary constant, defined as | |
58 @tex | |
59 $\sqrt{-1}$. | |
60 @end tex | |
6620 | 61 @ifnottex |
3294 | 62 @code{sqrt (-1)}. |
6620 | 63 @end ifnottex |
3294 | 64 |
65 For Octave to recognize a value as the imaginary part of a complex | |
66 constant, a space must not appear between the number and the @samp{i}. | |
67 If it does, Octave will print an error message, like this: | |
68 | |
69 @example | |
70 @group | |
71 octave:13> 3 + 4 i | |
72 | |
73 parse error: | |
74 | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
75 syntax error |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
76 |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
77 >>> 3 + 4 i |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
78 ^ |
3294 | 79 @end group |
80 @end example | |
81 | |
6620 | 82 @noindent |
3294 | 83 You may also use @samp{j}, @samp{I}, or @samp{J} in place of the |
84 @samp{i} above. All four forms are equivalent. | |
85 | |
6549 | 86 @DOCSTRING(double) |
87 | |
88 @DOCSTRING(complex) | |
89 | |
3294 | 90 @menu |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
91 * Matrices:: |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
92 * Ranges:: |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
93 * Single Precision Data Types:: |
6549 | 94 * Integer Data Types:: |
6781 | 95 * Bit Manipulations:: |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
96 * Logical Values:: |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
97 * Promotion and Demotion of Data Types:: |
3294 | 98 * Predicates for Numeric Objects:: |
99 @end menu | |
100 | |
4167 | 101 @node Matrices |
3294 | 102 @section Matrices |
103 @cindex matrices | |
104 | |
105 @opindex [ | |
106 @opindex ] | |
107 @opindex ; | |
108 @opindex , | |
109 | |
110 It is easy to define a matrix of values in Octave. The size of the | |
111 matrix is determined automatically, so it is not necessary to explicitly | |
112 state the dimensions. The expression | |
113 | |
114 @example | |
115 a = [1, 2; 3, 4] | |
116 @end example | |
117 | |
118 @noindent | |
119 results in the matrix | |
120 @tex | |
121 $$ a = \left[ \matrix{ 1 & 2 \cr 3 & 4 } \right] $$ | |
122 @end tex | |
6620 | 123 @ifnottex |
3294 | 124 |
125 @example | |
126 @group | |
127 | |
128 / \ | |
129 | 1 2 | | |
130 a = | | | |
131 | 3 4 | | |
132 \ / | |
133 | |
134 @end group | |
135 @end example | |
6620 | 136 @end ifnottex |
3294 | 137 |
138 Elements of a matrix may be arbitrary expressions, provided that the | |
139 dimensions all make sense when combining the various pieces. For | |
140 example, given the above matrix, the expression | |
141 | |
142 @example | |
143 [ a, a ] | |
144 @end example | |
145 | |
146 @noindent | |
147 produces the matrix | |
148 | |
149 @example | |
150 @group | |
151 ans = | |
152 | |
153 1 2 1 2 | |
154 3 4 3 4 | |
155 @end group | |
156 @end example | |
157 | |
158 @noindent | |
159 but the expression | |
160 | |
161 @example | |
162 [ a, 1 ] | |
163 @end example | |
164 | |
165 @noindent | |
166 produces the error | |
167 | |
168 @example | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
169 error: number of rows must match (1 != 2) near line 13, column 6 |
3294 | 170 @end example |
171 | |
172 @noindent | |
173 (assuming that this expression was entered as the first thing on line | |
174 13, of course). | |
175 | |
176 Inside the square brackets that delimit a matrix expression, Octave | |
177 looks at the surrounding context to determine whether spaces and newline | |
178 characters should be converted into element and row separators, or | |
4476 | 179 simply ignored, so an expression like |
3294 | 180 |
181 @example | |
182 @group | |
183 a = [ 1 2 | |
184 3 4 ] | |
185 @end group | |
186 @end example | |
187 | |
188 @noindent | |
189 will work. However, some possible sources of confusion remain. For | |
190 example, in the expression | |
191 | |
192 @example | |
193 [ 1 - 1 ] | |
194 @end example | |
195 | |
196 @noindent | |
197 the @samp{-} is treated as a binary operator and the result is the | |
198 scalar 0, but in the expression | |
199 | |
200 @example | |
201 [ 1 -1 ] | |
202 @end example | |
203 | |
204 @noindent | |
205 the @samp{-} is treated as a unary operator and the result is the | |
4476 | 206 vector @code{[ 1, -1 ]}. Similarly, the expression |
207 | |
208 @example | |
209 [ sin (pi) ] | |
210 @end example | |
211 | |
212 @noindent | |
213 will be parsed as | |
214 | |
215 @example | |
216 [ sin, (pi) ] | |
217 @end example | |
3294 | 218 |
4476 | 219 @noindent |
220 and will result in an error since the @code{sin} function will be | |
221 called with no arguments. To get around this, you must omit the space | |
222 between @code{sin} and the opening parenthesis, or enclose the | |
223 expression in a set of parentheses: | |
224 | |
225 @example | |
226 [ (sin (pi)) ] | |
227 @end example | |
228 | |
229 Whitespace surrounding the single quote character (@samp{'}, used as a | |
230 transpose operator and for delimiting character strings) can also cause | |
231 confusion. Given @code{a = 1}, the expression | |
3294 | 232 |
233 @example | |
234 [ 1 a' ] | |
235 @end example | |
236 | |
237 @noindent | |
4476 | 238 results in the single quote character being treated as a |
3294 | 239 transpose operator and the result is the vector @code{[ 1, 1 ]}, but the |
240 expression | |
241 | |
242 @example | |
243 [ 1 a ' ] | |
244 @end example | |
245 | |
246 @noindent | |
247 produces the error message | |
248 | |
249 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
250 @group |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
251 parse error: |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
252 |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
253 syntax error |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
254 |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
255 >>> [ 1 a ' ] |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7989
diff
changeset
|
256 ^ |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
257 @end group |
3294 | 258 @end example |
259 | |
260 @noindent | |
6620 | 261 because not doing so would cause trouble when parsing the valid expression |
3294 | 262 |
263 @example | |
264 [ a 'foo' ] | |
265 @end example | |
266 | |
267 For clarity, it is probably best to always use commas and semicolons to | |
4476 | 268 separate matrix elements and rows. |
3294 | 269 |
270 When you type a matrix or the name of a variable whose value is a | |
271 matrix, Octave responds by printing the matrix in with neatly aligned | |
272 rows and columns. If the rows of the matrix are too large to fit on the | |
273 screen, Octave splits the matrix and displays a header before each | |
274 section to indicate which columns are being displayed. You can use the | |
275 following variables to control the format of the output. | |
276 | |
3321 | 277 @DOCSTRING(output_max_field_width) |
3294 | 278 |
3321 | 279 @DOCSTRING(output_precision) |
3294 | 280 |
281 It is possible to achieve a wide range of output styles by using | |
282 different values of @code{output_precision} and | |
283 @code{output_max_field_width}. Reasonable combinations can be set using | |
284 the @code{format} function. @xref{Basic Input and Output}. | |
285 | |
3321 | 286 @DOCSTRING(split_long_rows) |
3294 | 287 |
288 Octave automatically switches to scientific notation when values become | |
289 very large or very small. This guarantees that you will see several | |
290 significant figures for every value in a matrix. If you would prefer to | |
291 see all values in a matrix printed in a fixed point format, you can set | |
292 the built-in variable @code{fixed_point_format} to a nonzero value. But | |
293 doing so is not recommended, because it can produce output that can | |
294 easily be misinterpreted. | |
295 | |
3321 | 296 @DOCSTRING(fixed_point_format) |
3294 | 297 |
298 @menu | |
299 * Empty Matrices:: | |
300 @end menu | |
301 | |
4167 | 302 @node Empty Matrices |
3294 | 303 @subsection Empty Matrices |
304 | |
305 A matrix may have one or both dimensions zero, and operations on empty | |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9209
diff
changeset
|
306 matrices are handled as described by Carl @nospell{de} Boor in @cite{An Empty |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
307 Exercise}, SIGNUM, Volume 25, pages 2-6, 1990 and C. N. Nett and W. M. |
3294 | 308 Haddad, in @cite{A System-Theoretic Appropriate Realization of the Empty |
309 Matrix Concept}, IEEE Transactions on Automatic Control, Volume 38, | |
310 Number 5, May 1993. | |
311 @tex | |
312 Briefly, given a scalar $s$, an $m\times n$ matrix $M_{m\times n}$, | |
313 and an $m\times n$ empty matrix $[\,]_{m\times n}$ (with either one or | |
314 both dimensions equal to zero), the following are true: | |
315 $$ | |
316 \eqalign{% | |
317 s \cdot [\,]_{m\times n} = [\,]_{m\times n} \cdot s &= [\,]_{m\times n}\cr | |
318 [\,]_{m\times n} + [\,]_{m\times n} &= [\,]_{m\times n}\cr | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
319 [\,]_{0\times m} \cdot M_{m\times n} &= [\,]_{0\times n}\cr |
3294 | 320 M_{m\times n} \cdot [\,]_{n\times 0} &= [\,]_{m\times 0}\cr |
321 [\,]_{m\times 0} \cdot [\,]_{0\times n} &= 0_{m\times n}} | |
322 $$ | |
323 @end tex | |
6620 | 324 @ifnottex |
3294 | 325 Briefly, given a scalar @var{s}, an @var{m} by |
326 @var{n} matrix @code{M(mxn)}, and an @var{m} by @var{n} empty matrix | |
327 @code{[](mxn)} (with either one or both dimensions equal to zero), the | |
328 following are true: | |
329 | |
330 @example | |
331 @group | |
332 s * [](mxn) = [](mxn) * s = [](mxn) | |
333 | |
334 [](mxn) + [](mxn) = [](mxn) | |
335 | |
336 [](0xm) * M(mxn) = [](0xn) | |
337 | |
338 M(mxn) * [](nx0) = [](mx0) | |
339 | |
340 [](mx0) * [](0xn) = 0(mxn) | |
341 @end group | |
342 @end example | |
6620 | 343 @end ifnottex |
3294 | 344 |
345 By default, dimensions of the empty matrix are printed along with the | |
346 empty matrix symbol, @samp{[]}. The built-in variable | |
347 @code{print_empty_dimensions} controls this behavior. | |
348 | |
3321 | 349 @DOCSTRING(print_empty_dimensions) |
3294 | 350 |
351 Empty matrices may also be used in assignment statements as a convenient | |
352 way to delete rows or columns of matrices. | |
353 @xref{Assignment Ops, ,Assignment Expressions}. | |
354 | |
355 When Octave parses a matrix expression, it examines the elements of the | |
356 list to determine whether they are all constants. If they are, it | |
357 replaces the list with a single matrix constant. | |
358 | |
4167 | 359 @node Ranges |
3294 | 360 @section Ranges |
361 @cindex range expressions | |
362 @cindex expression, range | |
363 | |
3920 | 364 @opindex colon |
3294 | 365 |
366 A @dfn{range} is a convenient way to write a row vector with evenly | |
367 spaced elements. A range expression is defined by the value of the first | |
368 element in the range, an optional value for the increment between | |
369 elements, and a maximum value which the elements of the range will not | |
370 exceed. The base, increment, and limit are separated by colons (the | |
371 @samp{:} character) and may contain any arithmetic expressions and | |
372 function calls. If the increment is omitted, it is assumed to be 1. | |
373 For example, the range | |
374 | |
375 @example | |
376 1 : 5 | |
377 @end example | |
378 | |
379 @noindent | |
380 defines the set of values @samp{[ 1, 2, 3, 4, 5 ]}, and the range | |
381 | |
382 @example | |
383 1 : 3 : 5 | |
384 @end example | |
385 | |
386 @noindent | |
387 defines the set of values @samp{[ 1, 4 ]}. | |
388 | |
389 Although a range constant specifies a row vector, Octave does @emph{not} | |
390 convert range constants to vectors unless it is necessary to do so. | |
391 This allows you to write a constant like @samp{1 : 10000} without using | |
392 80,000 bytes of storage on a typical 32-bit workstation. | |
393 | |
394 Note that the upper (or lower, if the increment is negative) bound on | |
395 the range is not always included in the set of values, and that ranges | |
396 defined by floating point values can produce surprising results because | |
397 Octave uses floating point arithmetic to compute the values in the | |
398 range. If it is important to include the endpoints of a range and the | |
399 number of elements is known, you should use the @code{linspace} function | |
400 instead (@pxref{Special Utility Matrices}). | |
401 | |
9158 | 402 When adding a scalar to a range, subtracting a scalar from it (or subtracting a |
403 range from a scalar) and multiplying by scalar, Octave will attempt to avoid | |
404 unpacking the range and keep the result as a range, too, if it can determine | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
405 that it is safe to do so. For instance, doing |
9158 | 406 |
407 @example | |
408 a = 2*(1:1e7) - 1; | |
409 @end example | |
410 | |
411 will produce the same result as @samp{1:2:2e7-1}, but without ever forming a | |
412 vector with ten million elements. | |
413 | |
414 Using zero as an increment in the colon notation, as @samp{1:0:1} is not | |
415 allowed, because a division by zero would occur in determining the number of | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
416 range elements. However, ranges with zero increment (i.e., all elements equal) |
9158 | 417 are useful, especially in indexing, and Octave allows them to be constructed |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
418 using the built-in function @dfn{ones}. Note that because a range must be a row |
9158 | 419 vector, @samp{ones (1, 10)} produces a range, while @samp{ones (10, 1)} does not. |
420 | |
3294 | 421 When Octave parses a range expression, it examines the elements of the |
422 expression to determine whether they are all constants. If they are, it | |
423 replaces the range expression with a single range constant. | |
424 | |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
425 @node Single Precision Data Types |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
426 @section Single Precision Data Types |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
427 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
428 Octave includes support for single precision data types, and most of the |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
429 functions in Octave accept single precision values and return single |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
430 precision answers. A single precision variable is created with the |
8534
0eb83938c8bc
Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
431 @code{single} function. |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
432 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
433 @DOCSTRING(single) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
434 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
435 for example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
436 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
437 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
438 @group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
439 sngl = single (rand (2, 2)) |
8534
0eb83938c8bc
Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
440 @result{} sngl = |
0eb83938c8bc
Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
441 0.37569 0.92982 |
0eb83938c8bc
Trivial fixes in numbers.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8347
diff
changeset
|
442 0.11962 0.50876 |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
443 class (sngl) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
444 @result{} single |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
445 @end group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
446 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
447 |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
448 Many functions can also return single precision values directly. For |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
449 example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
450 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
451 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
452 @group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
453 ones (2, 2, "single") |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
454 zeros (2, 2, "single") |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
455 eye (2, 2, "single") |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
456 rand (2, 2, "single") |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
457 NaN (2, 2, "single") |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
458 NA (2, 2, "single") |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
459 Inf (2, 2, "single") |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
460 @end group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
461 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
462 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
463 @noindent |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
464 will all return single precision matrices. |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
465 |
6549 | 466 @node Integer Data Types |
467 @section Integer Data Types | |
468 | |
6620 | 469 Octave supports integer matrices as an alternative to using double |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
470 precision. It is possible to use both signed and unsigned integers |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
471 represented by 8, 16, 32, or 64 bits. It should be noted that most |
6620 | 472 computations require floating point data, meaning that integers will |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
473 often change type when involved in numeric computations. For this |
6620 | 474 reason integers are most often used to store data, and not for |
475 calculations. | |
476 | |
477 In general most integer matrices are created by casting | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
478 existing matrices to integers. The following example shows how to cast |
6620 | 479 a matrix into 32 bit integers. |
480 | |
481 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
482 @group |
6620 | 483 float = rand (2, 2) |
484 @result{} float = 0.37569 0.92982 | |
485 0.11962 0.50876 | |
486 integer = int32 (float) | |
487 @result{} integer = 0 1 | |
488 0 1 | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
489 @end group |
6620 | 490 @end example |
491 | |
492 @noindent | |
493 As can be seen, floating point values are rounded to the nearest integer | |
494 when converted. | |
495 | |
6549 | 496 @DOCSTRING(isinteger) |
497 | |
498 @DOCSTRING(int8) | |
499 | |
500 @DOCSTRING(uint8) | |
501 | |
502 @DOCSTRING(int16) | |
503 | |
504 @DOCSTRING(uint16) | |
505 | |
506 @DOCSTRING(int32) | |
507 | |
508 @DOCSTRING(uint32) | |
509 | |
510 @DOCSTRING(int64) | |
511 | |
512 @DOCSTRING(uint64) | |
513 | |
514 @DOCSTRING(intmax) | |
515 | |
516 @DOCSTRING(intmin) | |
517 | |
8039
cd90e2842080
Add additional integer math and conversion warnings, set their default state to be off and add the intwarning function
David Bateman <dbateman@free.fr>
parents:
8015
diff
changeset
|
518 @DOCSTRING(intwarning) |
cd90e2842080
Add additional integer math and conversion warnings, set their default state to be off and add the intwarning function
David Bateman <dbateman@free.fr>
parents:
8015
diff
changeset
|
519 |
6624 | 520 @menu |
521 * Integer Arithmetic:: | |
522 @end menu | |
523 | |
6620 | 524 @node Integer Arithmetic |
525 @subsection Integer Arithmetic | |
526 | |
527 While many numerical computations can't be carried out in integers, | |
528 Octave does support basic operations like addition and multiplication | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
529 on integers. The operators @code{+}, @code{-}, @code{.*}, and @code{./} |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
530 work on integers of the same type. So, it is possible to add two 32 bit |
6620 | 531 integers, but not to add a 32 bit integer and a 16 bit integer. |
532 | |
6715 | 533 The arithmetic operations on integers are performed by casting the |
534 integer values to double precision values, performing the operation, and | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
535 then re-casting the values back to the original integer type. As the |
6715 | 536 double precision type of Octave is only capable of representing integers |
537 with up to 53 bits of precision, it is not possible to perform | |
8828 | 538 arithmetic with 64 bit integer types. |
6715 | 539 |
6620 | 540 When doing integer arithmetic one should consider the possibility of |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
541 underflow and overflow. This happens when the result of the computation |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
542 can't be represented using the chosen integer type. As an example it is |
6620 | 543 not possible to represent the result of @math{10 - 20} when using |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
544 unsigned integers. Octave makes sure that the result of integer |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
545 computations is the integer that is closest to the true result. So, the |
6620 | 546 result of @math{10 - 20} when using unsigned integers is zero. |
547 | |
548 When doing integer division Octave will round the result to the nearest | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
549 integer. This is different from most programming languages, where the |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
550 result is often floored to the nearest integer. So, the result of |
6620 | 551 @code{int32(5)./int32(8)} is @code{1}. |
552 | |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
553 @DOCSTRING(idivide) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
554 |
6781 | 555 @node Bit Manipulations |
556 @section Bit Manipulations | |
557 | |
558 Octave provides a number of functions for the manipulation of numeric | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
559 values on a bit by bit basis. The basic functions to set and obtain the |
6781 | 560 values of individual bits are @code{bitset} and @code{bitget}. |
561 | |
562 @DOCSTRING(bitset) | |
563 | |
564 @DOCSTRING(bitget) | |
565 | |
566 The arguments to all of Octave's bitwise operations can be scalar or | |
567 arrays, except for @code{bitcmp}, whose @var{k} argument must a | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
568 scalar. In the case where more than one argument is an array, then all |
6781 | 569 arguments must have the same shape, and the bitwise operator is applied |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
570 to each of the elements of the argument individually. If at least one |
6781 | 571 argument is a scalar and one an array, then the scalar argument is |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
572 duplicated. Therefore |
6781 | 573 |
574 @example | |
575 bitget (100, 8:-1:1) | |
576 @end example | |
577 | |
578 is the same as | |
579 | |
580 @example | |
581 bitget (100 * ones (1, 8), 8:-1:1) | |
582 @end example | |
583 | |
584 It should be noted that all values passed to the bit manipulation | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
585 functions of Octave are treated as integers. Therefore, even though the |
6781 | 586 example for @code{bitset} above passes the floating point value |
587 @code{10}, it is treated as the bits @code{[1, 0, 1, 0]} rather than the | |
588 bits of the native floating point format representation of @code{10}. | |
589 | |
8828 | 590 As the maximum value that can be represented by a number is important |
6781 | 591 for bit manipulation, particularly when forming masks, Octave supplies |
592 the function @code{bitmax}. | |
593 | |
594 @DOCSTRING(bitmax) | |
595 | |
596 This is the double precision version of the functions @code{intmax}, | |
597 previously discussed. | |
598 | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
599 Octave also includes the basic bitwise 'and', 'or' and 'exclusive or' |
6781 | 600 operators. |
601 | |
602 @DOCSTRING(bitand) | |
603 | |
604 @DOCSTRING(bitor) | |
605 | |
606 @DOCSTRING(bitxor) | |
607 | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8325
diff
changeset
|
608 The bitwise 'not' operator is a unary operator that performs a logical |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
609 negation of each of the bits of the value. For this to make sense, the |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
610 mask against which the value is negated must be defined. Octave's |
6781 | 611 bitwise 'not' operator is @code{bitcmp}. |
612 | |
613 @DOCSTRING(bitcmp) | |
614 | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8325
diff
changeset
|
615 Octave also includes the ability to left-shift and right-shift values bitwise. |
6781 | 616 |
617 @DOCSTRING(bitshift) | |
618 | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
619 Bits that are shifted out of either end of the value are lost. Octave |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8325
diff
changeset
|
620 also uses arithmetic shifts, where the sign bit of the value is kept |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
621 during a right shift. For example |
6781 | 622 |
623 @example | |
624 @group | |
625 bitshift (-10, -1) | |
626 @result{} -5 | |
627 bitshift (int8 (-1), -1) | |
628 @result{} -1 | |
629 @end group | |
630 @end example | |
631 | |
632 Note that @code{bitshift (int8 (-1), -1)} is @code{-1} since the bit | |
633 representation of @code{-1} in the @code{int8} data type is @code{[1, 1, | |
634 1, 1, 1, 1, 1, 1]}. | |
635 | |
4167 | 636 @node Logical Values |
3428 | 637 @section Logical Values |
638 | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
639 Octave has built-in support for logical values, i.e., variables that |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
640 are either @code{true} or @code{false}. When comparing two variables, |
6620 | 641 the result will be a logical value whose value depends on whether or |
642 not the comparison is true. | |
643 | |
644 The basic logical operations are @code{&}, @code{|}, and @code{!}, | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8325
diff
changeset
|
645 which correspond to ``Logical And'', ``Logical Or'', and ``Logical |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
646 Negation''. These operations all follow the usual rules of logic. |
6620 | 647 |
648 It is also possible to use logical values as part of standard numerical | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
649 calculations. In this case @code{true} is converted to @code{1}, and |
6620 | 650 @code{false} to 0, both represented using double precision floating |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
651 point numbers. So, the result of @code{true*22 - false/6} is @code{22}. |
6620 | 652 |
653 Logical values can also be used to index matrices and cell arrays. | |
654 When indexing with a logical array the result will be a vector containing | |
655 the values corresponding to @code{true} parts of the logical array. | |
656 The following example illustrates this. | |
657 | |
658 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
659 @group |
6620 | 660 data = [ 1, 2; 3, 4 ]; |
661 idx = (data <= 2); | |
662 data(idx) | |
9136
537a73861cb7
Fix small mistake in example.
Ansgar Burchard <ansgar@43-1.org>
parents:
9036
diff
changeset
|
663 @result{} ans = [ 1; 2 ] |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
664 @end group |
6620 | 665 @end example |
666 | |
667 @noindent | |
668 Instead of creating the @code{idx} array it is possible to replace | |
669 @code{data(idx)} with @code{data( data <= 2 )} in the above code. | |
670 | |
8828 | 671 Logical values can also be constructed by |
6620 | 672 casting numeric objects to logical values, or by using the @code{true} |
673 or @code{false} functions. | |
674 | |
6549 | 675 @DOCSTRING(logical) |
676 | |
3428 | 677 @DOCSTRING(true) |
678 | |
679 @DOCSTRING(false) | |
680 | |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
681 @node Promotion and Demotion of Data Types |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
682 @section Promotion and Demotion of Data Types |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
683 |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
684 Many operators and functions can work with mixed data types. For example |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
685 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
686 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
687 @group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
688 uint8 (1) + 1 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
689 @result{} 2 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
690 @end group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
691 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
692 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
693 @noindent |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
694 where the above operator works with an 8-bit integer and a double precision |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
695 value and returns an 8-bit integer value. Note that the type is demoted |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
696 to an 8-bit integer, rather than promoted to a double precision value as |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
697 might be expected. The reason is that if Octave promoted values in |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
698 expressions like the above with all numerical constants would need to be |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
699 explicitly cast to the appropriate data type like |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
700 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
701 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
702 @group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
703 uint8 (1) + uint8 (1) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
704 @result{} 2 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
705 @end group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
706 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
707 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
708 @noindent |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
709 which becomes difficult for the user to apply uniformly and might allow |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
710 hard to find bugs to be introduced. The same applies to single precision |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
711 values where a mixed operation such as |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
712 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
713 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
714 @group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
715 single (1) + 1 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
716 @result{} 2 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
717 @end group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
718 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
719 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
720 @noindent |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
721 returns a single precision value. The mixed operations that are valid |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
722 and their returned data types are |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
723 |
7989
23c248d415b5
Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents:
7984
diff
changeset
|
724 @multitable @columnfractions .2 .3 .3 .2 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
725 @item @tab Mixed Operation @tab Result @tab |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
726 @item @tab double OP single @tab single @tab |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
727 @item @tab double OP integer @tab integer @tab |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
728 @item @tab double OP char @tab double @tab |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
729 @item @tab double OP logical @tab double @tab |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
730 @item @tab single OP integer @tab integer @tab |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
731 @item @tab single OP char @tab single @tab |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
732 @item @tab single OP logical @tab single @tab |
7989
23c248d415b5
Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents:
7984
diff
changeset
|
733 @end multitable |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
734 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
735 The same logic applies to functions with mixed arguments such as |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
736 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
737 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
738 @group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
739 min (single (1), 0) |
7989
23c248d415b5
Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents:
7984
diff
changeset
|
740 @result{} 0 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
741 @end group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
742 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
743 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
744 @noindent |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
745 where the returned value is single precision. |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
746 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
747 In the case of mixed type indexed assignments, the type is not |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
748 changed. For example |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
749 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
750 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
751 @group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
752 x = ones (2, 2); |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
753 x (1, 1) = single (2) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
754 @result{} x = 2 1 |
7989
23c248d415b5
Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents:
7984
diff
changeset
|
755 1 1 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
756 @end group |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
757 @end example |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
758 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
759 @noindent |
7989
23c248d415b5
Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents:
7984
diff
changeset
|
760 where @code{x} remains of the double precision type. |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
761 |
4167 | 762 @node Predicates for Numeric Objects |
3294 | 763 @section Predicates for Numeric Objects |
764 | |
6620 | 765 Since the type of a variable may change during the execution of a |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
766 program, it can be necessary to do type checking at run-time. Doing this |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
767 also allows you to change the behavior of a function depending on the |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
768 type of the input. As an example, this naive implementation of @code{abs} |
7001 | 769 returns the absolute value of the input if it is a real number, and the |
6620 | 770 length of the input if it is a complex number. |
771 | |
772 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
773 @group |
6620 | 774 function a = abs (x) |
775 if (isreal (x)) | |
776 a = sign (x) .* x; | |
777 elseif (iscomplex (x)) | |
778 a = sqrt (real(x).^2 + imag(x).^2); | |
779 endif | |
780 endfunction | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9158
diff
changeset
|
781 @end group |
6620 | 782 @end example |
783 | |
784 The following functions are available for determining the type of a | |
785 variable. | |
786 | |
3428 | 787 @DOCSTRING(isnumeric) |
788 | |
789 @DOCSTRING(isreal) | |
790 | |
7638
2df457529cfa
implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7018
diff
changeset
|
791 @DOCSTRING(isfloat) |
2df457529cfa
implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7018
diff
changeset
|
792 |
4029 | 793 @DOCSTRING(iscomplex) |
3428 | 794 |
4029 | 795 @DOCSTRING(ismatrix) |
3294 | 796 |
4029 | 797 @DOCSTRING(isvector) |
3294 | 798 |
4029 | 799 @DOCSTRING(isscalar) |
3294 | 800 |
4029 | 801 @DOCSTRING(issquare) |
3294 | 802 |
4029 | 803 @DOCSTRING(issymmetric) |
3428 | 804 |
6550 | 805 @DOCSTRING(isdefinite) |
806 | |
6688 | 807 @DOCSTRING(islogical) |
6550 | 808 |
809 @DOCSTRING(isprime) |