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
|
<html lang="en">
<head>
<title>Integer Data Types - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Numeric-Data-Types.html#Numeric-Data-Types" title="Numeric Data Types">
<link rel="prev" href="Single-Precision-Data-Types.html#Single-Precision-Data-Types" title="Single Precision Data Types">
<link rel="next" href="Bit-Manipulations.html#Bit-Manipulations" title="Bit Manipulations">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Integer-Data-Types"></a>
Next: <a rel="next" accesskey="n" href="Bit-Manipulations.html#Bit-Manipulations">Bit Manipulations</a>,
Previous: <a rel="previous" accesskey="p" href="Single-Precision-Data-Types.html#Single-Precision-Data-Types">Single Precision Data Types</a>,
Up: <a rel="up" accesskey="u" href="Numeric-Data-Types.html#Numeric-Data-Types">Numeric Data Types</a>
<hr>
</div>
<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>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.
<pre class="example"> float = rand (2, 2)
float = 0.37569 0.92982
0.11962 0.50876
integer = int32 (float)
integer = 0 1
0 1
</pre>
<p class="noindent">As can be seen, floating point values are rounded to the nearest integer
when converted.
<!-- data.cc -->
<p><a name="doc_002disinteger"></a>
<div class="defun">
— Built-in Function: <b>isinteger</b> (<var>x</var>)<var><a name="index-isinteger-235"></a></var><br>
<blockquote><p>Return true if <var>x</var> is an integer object (int8, uint8, int16, etc.).
Note that <code>isinteger (14)</code> is false because numeric constants in
Octave are double precision floating point values.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002disreal.html#doc_002disreal">isreal</a>, <a href="doc_002disnumeric.html#doc_002disnumeric">isnumeric</a>, <a href="doc_002dclass.html#doc_002dclass">class</a>, <a href="doc_002disa.html#doc_002disa">isa</a>.
</p></blockquote></div>
<!-- ov-int8.cc -->
<p><a name="doc_002dint8"></a>
<div class="defun">
— Built-in Function: <b>int8</b> (<var>x</var>)<var><a name="index-int8-236"></a></var><br>
<blockquote><p>Convert <var>x</var> to 8-bit integer type.
</p></blockquote></div>
<!-- ov-uint8.cc -->
<p><a name="doc_002duint8"></a>
<div class="defun">
— Built-in Function: <b>uint8</b> (<var>x</var>)<var><a name="index-uint8-237"></a></var><br>
<blockquote><p>Convert <var>x</var> to unsigned 8-bit integer type.
</p></blockquote></div>
<!-- ov-int16.cc -->
<p><a name="doc_002dint16"></a>
<div class="defun">
— Built-in Function: <b>int16</b> (<var>x</var>)<var><a name="index-int16-238"></a></var><br>
<blockquote><p>Convert <var>x</var> to 16-bit integer type.
</p></blockquote></div>
<!-- ov-uint16.cc -->
<p><a name="doc_002duint16"></a>
<div class="defun">
— Built-in Function: <b>uint16</b> (<var>x</var>)<var><a name="index-uint16-239"></a></var><br>
<blockquote><p>Convert <var>x</var> to unsigned 16-bit integer type.
</p></blockquote></div>
<!-- ov-int32.cc -->
<p><a name="doc_002dint32"></a>
<div class="defun">
— Built-in Function: <b>int32</b> (<var>x</var>)<var><a name="index-int32-240"></a></var><br>
<blockquote><p>Convert <var>x</var> to 32-bit integer type.
</p></blockquote></div>
<!-- ov-uint32.cc -->
<p><a name="doc_002duint32"></a>
<div class="defun">
— Built-in Function: <b>uint32</b> (<var>x</var>)<var><a name="index-uint32-241"></a></var><br>
<blockquote><p>Convert <var>x</var> to unsigned 32-bit integer type.
</p></blockquote></div>
<!-- ov-int64.cc -->
<p><a name="doc_002dint64"></a>
<div class="defun">
— Built-in Function: <b>int64</b> (<var>x</var>)<var><a name="index-int64-242"></a></var><br>
<blockquote><p>Convert <var>x</var> to 64-bit integer type.
</p></blockquote></div>
<!-- ov-uint64.cc -->
<p><a name="doc_002duint64"></a>
<div class="defun">
— Built-in Function: <b>uint64</b> (<var>x</var>)<var><a name="index-uint64-243"></a></var><br>
<blockquote><p>Convert <var>x</var> to unsigned 64-bit integer type.
</p></blockquote></div>
<!-- bitfcns.cc -->
<p><a name="doc_002dintmax"></a>
<div class="defun">
— Built-in Function: <b>intmax</b> (<var>type</var>)<var><a name="index-intmax-244"></a></var><br>
<blockquote><p>Return the largest integer that can be represented in an integer type.
The variable <var>type</var> can be
<dl>
<dt><code>int8</code><dd>signed 8-bit integer.
<br><dt><code>int16</code><dd>signed 16-bit integer.
<br><dt><code>int32</code><dd>signed 32-bit integer.
<br><dt><code>int64</code><dd>signed 64-bit integer.
<br><dt><code>uint8</code><dd>unsigned 8-bit integer.
<br><dt><code>uint16</code><dd>unsigned 16-bit integer.
<br><dt><code>uint32</code><dd>unsigned 32-bit integer.
<br><dt><code>uint64</code><dd>unsigned 64-bit integer.
</dl>
<p>The default for <var>type</var> is <code>uint32</code>.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dintmin.html#doc_002dintmin">intmin</a>, <a href="doc_002dbitmax.html#doc_002dbitmax">bitmax</a>.
</p></blockquote></div>
<!-- bitfcns.cc -->
<p><a name="doc_002dintmin"></a>
<div class="defun">
— Built-in Function: <b>intmin</b> (<var>type</var>)<var><a name="index-intmin-245"></a></var><br>
<blockquote><p>Return the smallest integer that can be represented in an integer type.
The variable <var>type</var> can be
<dl>
<dt><code>int8</code><dd>signed 8-bit integer.
<br><dt><code>int16</code><dd>signed 16-bit integer.
<br><dt><code>int32</code><dd>signed 32-bit integer.
<br><dt><code>int64</code><dd>signed 64-bit integer.
<br><dt><code>uint8</code><dd>unsigned 8-bit integer.
<br><dt><code>uint16</code><dd>unsigned 16-bit integer.
<br><dt><code>uint32</code><dd>unsigned 32-bit integer.
<br><dt><code>uint64</code><dd>unsigned 64-bit integer.
</dl>
<p>The default for <var>type</var> is <code>uint32</code>.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dintmax.html#doc_002dintmax">intmax</a>, <a href="doc_002dbitmax.html#doc_002dbitmax">bitmax</a>.
</p></blockquote></div>
<!-- ./miscellaneous/intwarning.m -->
<p><a name="doc_002dintwarning"></a>
<div class="defun">
— Function File: <b>intwarning</b> (<var>action</var>)<var><a name="index-intwarning-246"></a></var><br>
— Function File: <b>intwarning</b> (<var>s</var>)<var><a name="index-intwarning-247"></a></var><br>
— Function File: <var>s</var> = <b>intwarning</b> (<var><small class="dots">...</small></var>)<var><a name="index-intwarning-248"></a></var><br>
<blockquote><p>Control the state of the warning for integer conversions and math
operations.
<dl>
<dt>"query"<dd>The state of the Octave integer conversion and math warnings is
queried. If there is no output argument, then the state is printed.
Otherwise it is returned in a structure with the fields "identifier"
and "state".
<!-- Set example in small font to prevent overfull line -->
<pre class="smallexample"> intwarning ("query")
The state of warning "Octave:int-convert-nan" is "off"
The state of warning "Octave:int-convert-non-int-val" is "off"
The state of warning "Octave:int-convert-overflow" is "off"
The state of warning "Octave:int-math-overflow" is "off"
</pre>
<br><dt>"on"<dd>Turn integer conversion and math warnings "on". If there is no output
argument, then nothing is printed. Otherwise the original state of
the state of the integer conversion and math warnings is returned in
a structure array.
<br><dt>"off"<dd>Turn integer conversion and math warnings "on". If there is no output
argument, then nothing is printed. Otherwise the original state of
the state of the integer conversion and math warnings is returned in
a structure array.
</dl>
<p>The original state of the integer warnings can be restored by passing
the structure array returned by <code>intwarning</code> to a later call to
<code>intwarning</code>. For example
<pre class="example"> s = intwarning ("off");
...
intwarning (s);
</pre>
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dwarning.html#doc_002dwarning">warning</a>.
</p></blockquote></div>
<ul class="menu">
<li><a accesskey="1" href="Integer-Arithmetic.html#Integer-Arithmetic">Integer Arithmetic</a>
</ul>
</body></html>
|