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
|
<!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>Numeric Data Types (GNU Octave (version 6.2.0))</title>
<meta name="description" content="Numeric Data Types (GNU Octave (version 6.2.0))">
<meta name="keywords" content="Numeric 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="index.html" rel="up" title="Top">
<link href="Matrices.html" rel="next" title="Matrices">
<link href="Object-Sizes.html" rel="prev" title="Object Sizes">
<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="Numeric-Data-Types"></span><div class="header">
<p>
Next: <a href="Strings.html" accesskey="n" rel="next">Strings</a>, Previous: <a href="Data-Types.html" accesskey="p" rel="prev">Data Types</a>, Up: <a href="index.html" accesskey="u" rel="up">Top</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>
<span id="Numeric-Data-Types-1"></span><h2 class="chapter">4 Numeric Data Types</h2>
<span id="index-numeric-constant-1"></span>
<span id="index-numeric-value-1"></span>
<p>A <em>numeric constant</em> may be a scalar, a vector, or a matrix, and it may
contain complex values.
</p>
<p>The simplest form of a numeric constant, a scalar, is a single number. Note
that by default numeric constants are represented within Octave by IEEE 754
double precision (binary64) floating-point format (complex constants are
stored as pairs of binary64 values). It is, however, possible to represent
real integers as described in <a href="Integer-Data-Types.html">Integer Data Types</a>.
</p>
<p>If the numeric constant is a real integer, it can be defined in decimal,
hexadecimal, or binary notation. Hexadecimal notation starts with ‘<samp>0x</samp>’ or
‘<samp>0X</samp>’, binary notation starts with ‘<samp>0b</samp>’ or ‘<samp>0B</samp>’, otherwise
decimal notation is assumed. As a consequence, ‘<samp>0b</samp>’ is not a hexadecimal
number, in fact, it is not a valid number at all.
</p>
<p>For better readability, digits may be partitioned by the underscore separator
‘<samp>_</samp>’, which is ignored by the Octave interpreter. Here are some examples
of real-valued integer constants, which all represent the same value and are
internally stored as binary64:
</p>
<div class="example">
<pre class="example">42 # decimal notation
0x2A # hexadecimal notation
0b101010 # binary notation
0b10_1010 # underscore notation
round (42.1) # also binary64
</pre></div>
<p>In decimal notation, the numeric constant may be denoted as decimal fraction
or even in scientific (exponential) notation. Note that this is not possible
for hexadecimal or binary notation. Again, in the following example all
numeric constants represent the same value:
</p>
<div class="example">
<pre class="example">.105
1.05e-1
.00105e+2
</pre></div>
<p>Unlike most programming languages, complex numeric constants are denoted as
the sum of real and imaginary parts. The imaginary part is denoted by a
real-valued numeric constant followed immediately by a complex value indicator
(‘<samp>i</samp>’, ‘<samp>j</samp>’, ‘<samp>I</samp>’, or ‘<samp>J</samp>’ which represents
<code>sqrt (-1)</code>).
No spaces are allowed between the numeric constant and the complex value
indicator. Some examples of complex numeric constants that all represent the
same value:
</p>
<div class="example">
<pre class="example">3 + 42i
3 + 42j
3 + 42I
3 + 42J
3.0 + 42.0i
3.0 + 0x2Ai
3.0 + 0b10_1010i
0.3e1 + 420e-1i
</pre></div>
<span id="XREFdouble"></span><dl>
<dt id="index-double">: <em></em> <strong>double</strong> <em>(<var>x</var>)</em></dt>
<dd><p>Convert <var>x</var> to double precision type.
</p>
<p><strong>See also:</strong> <a href="Single-Precision-Data-Types.html#XREFsingle">single</a>.
</p></dd></dl>
<span id="XREFcomplex"></span><dl>
<dt id="index-complex">: <em></em> <strong>complex</strong> <em>(<var>x</var>)</em></dt>
<dt id="index-complex-1">: <em></em> <strong>complex</strong> <em>(<var>re</var>, <var>im</var>)</em></dt>
<dd><p>Return a complex value from real arguments.
</p>
<p>With 1 real argument <var>x</var>, return the complex result
<code><var>x</var> + 0i</code><!-- /@w -->.
</p>
<p>With 2 real arguments, return the complex result
<code><var>re</var> + <var>im</var>i</code><!-- /@w -->.
<code>complex</code> can often be more convenient than expressions such as
<code>a + b*i</code><!-- /@w -->.
For example:
</p>
<div class="example">
<pre class="example">complex ([1, 2], [3, 4])
⇒ [ 1 + 3i 2 + 4i ]
</pre></div>
<p><strong>See also:</strong> <a href="Complex-Arithmetic.html#XREFreal">real</a>, <a href="Complex-Arithmetic.html#XREFimag">imag</a>, <a href="Predicates-for-Numeric-Objects.html#XREFiscomplex">iscomplex</a>, <a href="Complex-Arithmetic.html#XREFabs">abs</a>, <a href="Complex-Arithmetic.html#XREFarg">arg</a>.
</p></dd></dl>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="Matrices.html" accesskey="1">Matrices</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="Ranges.html" accesskey="2">Ranges</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="Single-Precision-Data-Types.html" accesskey="3">Single Precision Data Types</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="Integer-Data-Types.html" accesskey="4">Integer Data Types</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="Bit-Manipulations.html" accesskey="5">Bit Manipulations</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="Logical-Values.html" accesskey="6">Logical Values</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="Promotion-and-Demotion-of-Data-Types.html" accesskey="7">Promotion and Demotion of Data Types</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="Predicates-for-Numeric-Objects.html" accesskey="8">Predicates for Numeric Objects</a></td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<div class="header">
<p>
Next: <a href="Strings.html" accesskey="n" rel="next">Strings</a>, Previous: <a href="Data-Types.html" accesskey="p" rel="prev">Data Types</a>, Up: <a href="index.html" accesskey="u" rel="up">Top</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>
|