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 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
|
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Built-in Data Types (GNU Octave (version 10.3.0))</title>
<meta name="description" content="Built-in Data Types (GNU Octave (version 10.3.0))">
<meta name="keywords" content="Built-in Data Types (GNU Octave (version 10.3.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<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="Data-Types.html" rel="up" title="Data Types">
<link href="User_002ddefined-Data-Types.html" rel="next" title="User-defined Data Types">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<div class="section-level-extent" id="Built_002din-Data-Types">
<div class="nav-panel">
<p>
Next: <a href="User_002ddefined-Data-Types.html" accesskey="n" rel="next">User-defined Data Types</a>, Up: <a href="Data-Types.html" accesskey="u" rel="up">Data Types</a> [<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>
<h3 class="section" id="Built_002din-Data-Types-1"><span>3.1 Built-in Data Types<a class="copiable-link" href="#Built_002din-Data-Types-1"> ¶</a></span></h3>
<a class="index-entry-id" id="index-data-types_002c-built_002din"></a>
<a class="index-entry-id" id="index-built_002din-data-types"></a>
<p>The standard built-in data types are real and complex scalars and
matrices, ranges, character strings, a data structure type, and cell
arrays. Additional built-in data types may be added in future versions.
If you need a specialized data type that is not currently provided as a
built-in type, you are encouraged to write your own user-defined data
type and contribute it for distribution in a future release of Octave.
</p>
<p>The data type of a variable can be determined and changed through the
use of the following functions.
</p>
<a class="anchor" id="XREFclass"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-class"><span><code class="def-type"><var class="var">classname</var> =</code> <strong class="def-name">class</strong> <code class="def-code-arguments">(<var class="var">obj</var>)</code><a class="copiable-link" href="#index-class"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-class-1"><span><code class="def-type"><var class="var">cls</var> =</code> <strong class="def-name">class</strong> <code class="def-code-arguments">(<var class="var">s</var>, <var class="var">classname</var>)</code><a class="copiable-link" href="#index-class-1"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-class-2"><span><code class="def-type"><var class="var">cls</var> =</code> <strong class="def-name">class</strong> <code class="def-code-arguments">(<var class="var">s</var>, <var class="var">classname</var>, <var class="var">parent1</var>, …)</code><a class="copiable-link" href="#index-class-2"> ¶</a></span></dt>
<dd><p>Return the class of the object <var class="var">obj</var>, or create a class with fields from
structure <var class="var">s</var> and name (string) <var class="var">classname</var>.
</p>
<p>Additional arguments name a list of parent classes from which the new class is
derived.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Data-Types.html#XREFtypeinfo">typeinfo</a>, <a class="ref" href="#XREFisa">isa</a>.
</p></dd></dl>
<a class="anchor" id="XREFisa"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-isa"><span><code class="def-type"><var class="var">tf</var> =</code> <strong class="def-name">isa</strong> <code class="def-code-arguments">(<var class="var">obj</var>, <var class="var">classname</var>)</code><a class="copiable-link" href="#index-isa"> ¶</a></span></dt>
<dd><p>Return true if <var class="var">obj</var> is an object from the class <var class="var">classname</var>.
</p>
<p><var class="var">classname</var> may also be one of the following class categories:
</p>
<dl class="table">
<dt><code class="code">"float"</code></dt>
<dd><p>Floating point value comprising classes <code class="code">"double"</code> and
<code class="code">"single"</code>.
</p>
</dd>
<dt><code class="code">"integer"</code></dt>
<dd><p>Integer value comprising classes (u)int8, (u)int16, (u)int32, (u)int64.
</p>
</dd>
<dt><code class="code">"numeric"</code></dt>
<dd><p>Numeric value comprising either a floating point or integer value.
</p></dd>
</dl>
<p>If <var class="var">classname</var> is a cell array of string, a logical array of the same
size is returned, containing true for each class to which <var class="var">obj</var>
belongs to.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFclass">class</a>, <a class="ref" href="Data-Types.html#XREFtypeinfo">typeinfo</a>.
</p></dd></dl>
<a class="anchor" id="XREFcast"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-cast"><span><code class="def-type"><var class="var">y</var> =</code> <strong class="def-name">cast</strong> <code class="def-code-arguments">(<var class="var">x</var>, "<var class="var">type</var>")</code><a class="copiable-link" href="#index-cast"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-cast-1"><span><code class="def-type"><var class="var">y</var> =</code> <strong class="def-name">cast</strong> <code class="def-code-arguments">(<var class="var">x</var>, "<var class="var">like</var>", <var class="var">var</var>)</code><a class="copiable-link" href="#index-cast-1"> ¶</a></span></dt>
<dd><p>Convert <var class="var">x</var> to data type <var class="var">type</var>.
</p>
<p>The input <var class="var">x</var> may be a scalar, vector, or matrix of a class that is
convertible to the target class (see below).
</p>
<p>If a variable <var class="var">var</var> is specified after <code class="code">"like"</code>, <var class="var">x</var> is
converted to the same data type and sparsity attribute. If <var class="var">var</var> is
complex, <var class="var">x</var> will be complex, too.
</p>
<p><var class="var">var</var> may be and <var class="var">type</var> may name any of the following built-in
numeric classes:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">"double"
"single"
"logical"
"char"
"int8"
"int16"
"int32"
"int64"
"uint8"
"uint16"
"uint32"
"uint64"
</pre></div></div>
<p>The value <var class="var">x</var> may be modified to fit within the range of the new type.
</p>
<p>Examples:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">cast (-5, "uint8")
⇒ 0
cast (300, "int8")
⇒ 127
</pre></div></div>
<p>Programming Note: This function relies on the object <var class="var">x</var> having a
conversion method named <var class="var">type</var>. User-defined classes may implement only
a subset of the full list of types shown above. In that case, it may be
necessary to call cast twice in order to reach the desired type.
For example, the conversion to double is nearly always implemented, but
the conversion to uint8 might not be. In that case, the following code will
work:
</p>
<div class="example">
<pre class="example-preformatted">cast (cast (<var class="var">user_defined_val</var>, "double"), "uint8")
</pre></div>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFtypecast">typecast</a>, <a class="ref" href="Integer-Data-Types.html#XREFint8">int8</a>, <a class="ref" href="Integer-Data-Types.html#XREFuint8">uint8</a>, <a class="ref" href="Integer-Data-Types.html#XREFint16">int16</a>, <a class="ref" href="Integer-Data-Types.html#XREFuint16">uint16</a>, <a class="ref" href="Integer-Data-Types.html#XREFint32">int32</a>, <a class="ref" href="Integer-Data-Types.html#XREFuint32">uint32</a>, <a class="ref" href="Integer-Data-Types.html#XREFint64">int64</a>, <a class="ref" href="Integer-Data-Types.html#XREFuint64">uint64</a>, <a class="ref" href="Numeric-Data-Types.html#XREFdouble">double</a>, <a class="ref" href="Single-Precision-Data-Types.html#XREFsingle">single</a>, <a class="ref" href="Logical-Values.html#XREFlogical">logical</a>, <a class="ref" href="Concatenating-Strings.html#XREFchar">char</a>, <a class="ref" href="#XREFclass">class</a>, <a class="ref" href="Data-Types.html#XREFtypeinfo">typeinfo</a>.
</p></dd></dl>
<a class="anchor" id="XREFtypecast"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-typecast"><span><code class="def-type"><var class="var">y</var> =</code> <strong class="def-name">typecast</strong> <code class="def-code-arguments">(<var class="var">x</var>, "<var class="var">class</var>")</code><a class="copiable-link" href="#index-typecast"> ¶</a></span></dt>
<dd><p>Return a new array <var class="var">y</var> resulting from interpreting the data of <var class="var">x</var>
in memory as data of the numeric class <var class="var">class</var>.
</p>
<p>Both the class of <var class="var">x</var> and <var class="var">class</var> must be one of the built-in
numeric classes:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">"logical"
"char"
"int8"
"int16"
"int32"
"int64"
"uint8"
"uint16"
"uint32"
"uint64"
"double"
"single"
"double complex"
"single complex"
</pre></div></div>
<p>the last two are only used with <var class="var">class</var>; they indicate that a
complex-valued result is requested. Complex arrays are stored in memory as
consecutive pairs of real numbers. The sizes of integer types are given by
their bit counts. Both logical and char are typically one byte wide;
however, this is not guaranteed by C++. If your system is IEEE 754
conformant, single and double will be 4 bytes and 8 bytes wide, respectively.
<code class="code">"logical"</code> is not allowed for <var class="var">class</var>.
</p>
<p>If the input is a row vector, the return value is a row vector, otherwise it
is a column vector.
</p>
<p>If the bit length of <var class="var">x</var> is not divisible by that of <var class="var">class</var>, an
error occurs.
</p>
<p>An example of the use of typecast on a little-endian machine is
</p>
<div class="example">
<div class="group"><pre class="example-preformatted"><var class="var">x</var> = uint16 ([1, 65535]);
typecast (<var class="var">x</var>, "uint8")
⇒ [ 1, 0, 255, 255]
</pre></div></div>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFcast">cast</a>, <a class="ref" href="#XREFbitpack">bitpack</a>, <a class="ref" href="#XREFbitunpack">bitunpack</a>, <a class="ref" href="#XREFswapbytes">swapbytes</a>.
</p></dd></dl>
<a class="anchor" id="XREFswapbytes"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-swapbytes"><span><code class="def-type"><var class="var">y</var> =</code> <strong class="def-name">swapbytes</strong> <code class="def-code-arguments">(<var class="var">x</var>)</code><a class="copiable-link" href="#index-swapbytes"> ¶</a></span></dt>
<dd><p>Swap the byte order on values, converting from little endian to big endian
and vice versa.
</p>
<p>For example:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">swapbytes (uint16 (1:4))
⇒ 256 512 768 1024
</pre></div></div>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFtypecast">typecast</a>, <a class="ref" href="#XREFcast">cast</a>.
</p></dd></dl>
<a class="anchor" id="XREFbitpack"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-bitpack"><span><code class="def-type"><var class="var">y</var> =</code> <strong class="def-name">bitpack</strong> <code class="def-code-arguments">(<var class="var">x</var>, <var class="var">class</var>)</code><a class="copiable-link" href="#index-bitpack"> ¶</a></span></dt>
<dd><p>Return a new array <var class="var">y</var> resulting from interpreting the logical array
<var class="var">x</var> as raw bit patterns for data of the numeric class <var class="var">class</var>.
</p>
<p><var class="var">class</var> must be one of the built-in numeric classes:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">"double"
"single"
"double complex"
"single complex"
"char"
"int8"
"int16"
"int32"
"int64"
"uint8"
"uint16"
"uint32"
"uint64"
</pre></div></div>
<p>The number of elements of <var class="var">x</var> should be divisible by the bit length of
<var class="var">class</var>. If it is not, excess bits are discarded. Bits come in
increasing order of significance, i.e., <code class="code">x(1)</code> is bit 0, <code class="code">x(2)</code> is
bit 1, etc.
</p>
<p>The result is a row vector if <var class="var">x</var> is a row vector, otherwise it is a
column vector.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFbitunpack">bitunpack</a>, <a class="ref" href="#XREFtypecast">typecast</a>.
</p></dd></dl>
<a class="anchor" id="XREFbitunpack"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-bitunpack"><span><code class="def-type"><var class="var">y</var> =</code> <strong class="def-name">bitunpack</strong> <code class="def-code-arguments">(<var class="var">x</var>)</code><a class="copiable-link" href="#index-bitunpack"> ¶</a></span></dt>
<dd><p>Return a logical array <var class="var">y</var> corresponding to the raw bit patterns of
<var class="var">x</var>.
</p>
<p><var class="var">x</var> must belong to one of the built-in numeric classes:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">"double"
"single"
"char"
"int8"
"int16"
"int32"
"int64"
"uint8"
"uint16"
"uint32"
"uint64"
</pre></div></div>
<p>The result is a row vector if <var class="var">x</var> is a row vector; otherwise, it is a
column vector.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFbitpack">bitpack</a>, <a class="ref" href="#XREFtypecast">typecast</a>.
</p></dd></dl>
<ul class="mini-toc">
<li><a href="Numeric-Objects.html" accesskey="1">Numeric Objects</a></li>
<li><a href="Missing-Data.html" accesskey="2">Missing Data</a></li>
<li><a href="String-Objects.html" accesskey="3">String Objects</a></li>
<li><a href="Data-Structure-Objects.html" accesskey="4">Data Structure Objects</a></li>
<li><a href="Cell-Array-Objects.html" accesskey="5">Cell Array Objects</a></li>
</ul>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="User_002ddefined-Data-Types.html">User-defined Data Types</a>, Up: <a href="Data-Types.html">Data Types</a> [<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>
|