File: Integer-Data-Types.html

package info (click to toggle)
octave 6.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 124,192 kB
  • sloc: cpp: 322,665; ansic: 68,088; fortran: 20,980; objc: 8,121; sh: 7,719; yacc: 4,266; lex: 4,123; perl: 1,530; java: 1,366; awk: 1,257; makefile: 424; xml: 147
file content (311 lines) | stat: -rw-r--r-- 13,014 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Integer Data Types (GNU Octave (version 6.2.0))</title>

<meta name="description" content="Integer Data Types (GNU Octave (version 6.2.0))">
<meta name="keywords" content="Integer Data Types (GNU Octave (version 6.2.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Numeric-Data-Types.html" rel="up" title="Numeric Data Types">
<link href="Integer-Arithmetic.html" rel="next" title="Integer Arithmetic">
<link href="Single-Precision-Data-Types.html" rel="prev" title="Single Precision Data Types">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">


</head>

<body lang="en">
<span id="Integer-Data-Types"></span><div class="header">
<p>
Next: <a href="Bit-Manipulations.html" accesskey="n" rel="next">Bit Manipulations</a>, Previous: <a href="Single-Precision-Data-Types.html" accesskey="p" rel="prev">Single Precision Data Types</a>, Up: <a href="Numeric-Data-Types.html" accesskey="u" rel="up">Numeric Data Types</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Integer-Data-Types-1"></span><h3 class="section">4.4 Integer Data Types</h3>

<p>Octave supports integer matrices as an alternative to using double
precision.  It is possible to use both signed and unsigned integers
represented by 8, 16, 32, or 64 bits.  It should be noted that most
computations require floating point data, meaning that integers will
often change type when involved in numeric computations.  For this
reason integers are most often used to store data, and not for
calculations.
</p>
<p>In general most integer matrices are created by casting
existing matrices to integers.  The following example shows how to cast
a matrix into 32 bit integers.
</p>
<div class="example">
<pre class="example">float = rand (2, 2)
     &rArr; float = 0.37569   0.92982
                0.11962   0.50876
integer = int32 (float)
     &rArr; integer = 0  1
                  0  1
</pre></div>

<p>As can be seen, floating point values are rounded to the nearest integer
when converted.
</p>
<span id="XREFisinteger"></span><dl>
<dt id="index-isinteger">: <em></em> <strong>isinteger</strong> <em>(<var>x</var>)</em></dt>
<dd><p>Return true if <var>x</var> is an integer object (int8, uint8, int16, etc.).
</p>
<p>Note that <code>isinteger&nbsp;(14)</code><!-- /@w --> is false because numeric constants in
Octave are double precision floating point values.
</p>
<p><strong>See also:</strong> <a href="Predicates-for-Numeric-Objects.html#XREFisfloat">isfloat</a>, <a href="Character-Arrays.html#XREFischar">ischar</a>, <a href="Predicates-for-Numeric-Objects.html#XREFislogical">islogical</a>, <a href="Character-Arrays.html#XREFisstring">isstring</a>, <a href="Predicates-for-Numeric-Objects.html#XREFisnumeric">isnumeric</a>, <a href="Built_002din-Data-Types.html#XREFisa">isa</a>.
</p></dd></dl>


<span id="XREFint8"></span><dl>
<dt id="index-int8">: <em></em> <strong>int8</strong> <em>(<var>x</var>)</em></dt>
<dd><p>Convert <var>x</var> to 8-bit integer type.
</p>
<p><strong>See also:</strong> <a href="#XREFuint8">uint8</a>, <a href="#XREFint16">int16</a>, <a href="#XREFuint16">uint16</a>, <a href="#XREFint32">int32</a>, <a href="#XREFuint32">uint32</a>, <a href="#XREFint64">int64</a>, <a href="#XREFuint64">uint64</a>.
</p></dd></dl>


<span id="XREFuint8"></span><dl>
<dt id="index-uint8">: <em></em> <strong>uint8</strong> <em>(<var>x</var>)</em></dt>
<dd><p>Convert <var>x</var> to unsigned 8-bit integer type.
</p>
<p><strong>See also:</strong> <a href="#XREFint8">int8</a>, <a href="#XREFint16">int16</a>, <a href="#XREFuint16">uint16</a>, <a href="#XREFint32">int32</a>, <a href="#XREFuint32">uint32</a>, <a href="#XREFint64">int64</a>, <a href="#XREFuint64">uint64</a>.
</p></dd></dl>


<span id="XREFint16"></span><dl>
<dt id="index-int16">: <em></em> <strong>int16</strong> <em>(<var>x</var>)</em></dt>
<dd><p>Convert <var>x</var> to 16-bit integer type.
</p>
<p><strong>See also:</strong> <a href="#XREFint8">int8</a>, <a href="#XREFuint8">uint8</a>, <a href="#XREFuint16">uint16</a>, <a href="#XREFint32">int32</a>, <a href="#XREFuint32">uint32</a>, <a href="#XREFint64">int64</a>, <a href="#XREFuint64">uint64</a>.
</p></dd></dl>


<span id="XREFuint16"></span><dl>
<dt id="index-uint16">: <em></em> <strong>uint16</strong> <em>(<var>x</var>)</em></dt>
<dd><p>Convert <var>x</var> to unsigned 16-bit integer type.
</p>
<p><strong>See also:</strong> <a href="#XREFint8">int8</a>, <a href="#XREFuint8">uint8</a>, <a href="#XREFint16">int16</a>, <a href="#XREFint32">int32</a>, <a href="#XREFuint32">uint32</a>, <a href="#XREFint64">int64</a>, <a href="#XREFuint64">uint64</a>.
</p></dd></dl>


<span id="XREFint32"></span><dl>
<dt id="index-int32">: <em></em> <strong>int32</strong> <em>(<var>x</var>)</em></dt>
<dd><p>Convert <var>x</var> to 32-bit integer type.
</p>
<p><strong>See also:</strong> <a href="#XREFint8">int8</a>, <a href="#XREFuint8">uint8</a>, <a href="#XREFint16">int16</a>, <a href="#XREFuint16">uint16</a>, <a href="#XREFuint32">uint32</a>, <a href="#XREFint64">int64</a>, <a href="#XREFuint64">uint64</a>.
</p></dd></dl>


<span id="XREFuint32"></span><dl>
<dt id="index-uint32">: <em></em> <strong>uint32</strong> <em>(<var>x</var>)</em></dt>
<dd><p>Convert <var>x</var> to unsigned 32-bit integer type.
</p>
<p><strong>See also:</strong> <a href="#XREFint8">int8</a>, <a href="#XREFuint8">uint8</a>, <a href="#XREFint16">int16</a>, <a href="#XREFuint16">uint16</a>, <a href="#XREFint32">int32</a>, <a href="#XREFint64">int64</a>, <a href="#XREFuint64">uint64</a>.
</p></dd></dl>


<span id="XREFint64"></span><dl>
<dt id="index-int64">: <em></em> <strong>int64</strong> <em>(<var>x</var>)</em></dt>
<dd><p>Convert <var>x</var> to 64-bit integer type.
</p>
<p><strong>See also:</strong> <a href="#XREFint8">int8</a>, <a href="#XREFuint8">uint8</a>, <a href="#XREFint16">int16</a>, <a href="#XREFuint16">uint16</a>, <a href="#XREFint32">int32</a>, <a href="#XREFuint32">uint32</a>, <a href="#XREFuint64">uint64</a>.
</p></dd></dl>


<span id="XREFuint64"></span><dl>
<dt id="index-uint64">: <em></em> <strong>uint64</strong> <em>(<var>x</var>)</em></dt>
<dd><p>Convert <var>x</var> to unsigned 64-bit integer type.
</p>
<p><strong>See also:</strong> <a href="#XREFint8">int8</a>, <a href="#XREFuint8">uint8</a>, <a href="#XREFint16">int16</a>, <a href="#XREFuint16">uint16</a>, <a href="#XREFint32">int32</a>, <a href="#XREFuint32">uint32</a>, <a href="#XREFint64">int64</a>.
</p></dd></dl>


<span id="XREFintmax"></span><dl>
<dt id="index-intmax">: <em></em> <strong>intmax</strong> <em>()</em></dt>
<dt id="index-intmax-1">: <em></em> <strong>intmax</strong> <em>(&quot;<var>type</var>&quot;)</em></dt>
<dt id="index-intmax-2">: <em></em> <strong>intmax</strong> <em>(<var>var</var>)</em></dt>
<dd><p>Return the largest integer that can be represented by a specific integer type.
</p>
<p>The input is either a string <code>&quot;<var>type</var>&quot;</code> specifying an integer type,
or it is an existing integer variable <var>var</var>.
</p>
<p>Possible values for <var>type</var> are
</p>
<dl compact="compact">
<dt><code>&quot;int8&quot;</code></dt>
<dd><p>signed 8-bit integer.
</p>
</dd>
<dt><code>&quot;int16&quot;</code></dt>
<dd><p>signed 16-bit integer.
</p>
</dd>
<dt><code>&quot;int32&quot;</code></dt>
<dd><p>signed 32-bit integer.
</p>
</dd>
<dt><code>&quot;int64&quot;</code></dt>
<dd><p>signed 64-bit integer.
</p>
</dd>
<dt><code>&quot;uint8&quot;</code></dt>
<dd><p>unsigned 8-bit integer.
</p>
</dd>
<dt><code>&quot;uint16&quot;</code></dt>
<dd><p>unsigned 16-bit integer.
</p>
</dd>
<dt><code>&quot;uint32&quot;</code></dt>
<dd><p>unsigned 32-bit integer.
</p>
</dd>
<dt><code>&quot;uint64&quot;</code></dt>
<dd><p>unsigned 64-bit integer.
</p></dd>
</dl>

<p>The default for <var>type</var> is <code>&quot;int32&quot;</code>.
</p>
<p>Example Code - query an existing variable
</p>
<div class="example">
<pre class="example">x = int8 (1);
intmax (x)
  &rArr; 127
</pre></div>


<p><strong>See also:</strong> <a href="#XREFintmin">intmin</a>, <a href="#XREFflintmax">flintmax</a>.
</p></dd></dl>


<span id="XREFintmin"></span><dl>
<dt id="index-intmin">: <em></em> <strong>intmin</strong> <em>()</em></dt>
<dt id="index-intmin-1">: <em></em> <strong>intmin</strong> <em>(&quot;<var>type</var>&quot;)</em></dt>
<dt id="index-intmin-2">: <em></em> <strong>intmin</strong> <em>(<var>var</var>)</em></dt>
<dd><p>Return the smallest integer that can be represented by a specific integer type.
</p>
<p>The input is either a string <code>&quot;<var>type</var>&quot;</code> specifying an integer type,
or it is an existing integer variable <var>var</var>.
</p>
<p>Possible values for <var>type</var> are
</p>
<dl compact="compact">
<dt><code>&quot;int8&quot;</code></dt>
<dd><p>signed 8-bit integer.
</p>
</dd>
<dt><code>&quot;int16&quot;</code></dt>
<dd><p>signed 16-bit integer.
</p>
</dd>
<dt><code>&quot;int32&quot;</code></dt>
<dd><p>signed 32-bit integer.
</p>
</dd>
<dt><code>&quot;int64&quot;</code></dt>
<dd><p>signed 64-bit integer.
</p>
</dd>
<dt><code>&quot;uint8&quot;</code></dt>
<dd><p>unsigned 8-bit integer.
</p>
</dd>
<dt><code>&quot;uint16&quot;</code></dt>
<dd><p>unsigned 16-bit integer.
</p>
</dd>
<dt><code>&quot;uint32&quot;</code></dt>
<dd><p>unsigned 32-bit integer.
</p>
</dd>
<dt><code>&quot;uint64&quot;</code></dt>
<dd><p>unsigned 64-bit integer.
</p></dd>
</dl>

<p>The default for <var>type</var> is <code>&quot;int32&quot;</code>.
</p>
<p>Example Code - query an existing variable
</p>
<div class="example">
<pre class="example">x = int8 (1);
intmin (x)
  &rArr; -128
</pre></div>


<p><strong>See also:</strong> <a href="#XREFintmax">intmax</a>, <a href="#XREFflintmax">flintmax</a>.
</p></dd></dl>


<span id="XREFflintmax"></span><dl>
<dt id="index-flintmax">: <em></em> <strong>flintmax</strong> <em>()</em></dt>
<dt id="index-flintmax-1">: <em></em> <strong>flintmax</strong> <em>(&quot;double&quot;)</em></dt>
<dt id="index-flintmax-2">: <em></em> <strong>flintmax</strong> <em>(&quot;single&quot;)</em></dt>
<dt id="index-flintmax-3">: <em></em> <strong>flintmax</strong> <em>(<var>var</var>)</em></dt>
<dd><p>Return the largest integer that can be represented consecutively in a
floating point value.
</p>
<p>The input is either a string specifying a floating point type, or it is an
existing floating point variable <var>var</var>.
</p>
<p>The default type is <code>&quot;double&quot;</code>, but <code>&quot;single&quot;</code> is a valid option.
On IEEE 754 compatible systems, <code>flintmax</code> is <em>2^{53}</em><!-- /@w --> for
<code>&quot;double&quot;</code> and <em>2^{24}</em><!-- /@w --> for <code>&quot;single&quot;</code>.
</p>
<p>Example Code - query an existing variable
</p>
<div class="example">
<pre class="example">x = single (1);
flintmax (x)
  &rArr; 16777216
</pre></div>


<p><strong>See also:</strong> <a href="#XREFintmax">intmax</a>, <a href="Mathematical-Constants.html#XREFrealmax">realmax</a>, <a href="Mathematical-Constants.html#XREFrealmin">realmin</a>.
</p></dd></dl>


<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="Integer-Arithmetic.html" accesskey="1">Integer Arithmetic</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>

<hr>
<div class="header">
<p>
Next: <a href="Bit-Manipulations.html" accesskey="n" rel="next">Bit Manipulations</a>, Previous: <a href="Single-Precision-Data-Types.html" accesskey="p" rel="prev">Single Precision Data Types</a>, Up: <a href="Numeric-Data-Types.html" accesskey="u" rel="up">Numeric Data Types</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>