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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GNU Octave: Numeric Data Types</title>
<meta name="description" content="GNU Octave: Numeric Data Types">
<meta name="keywords" content="GNU Octave: Numeric Data Types">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="index.html#Top" rel="up" title="Top">
<link href="Matrices.html#Matrices" rel="next" title="Matrices">
<link href="Object-Sizes.html#Object-Sizes" rel="prev" title="Object Sizes">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {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}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Numeric-Data-Types"></a>
<div class="header">
<p>
Next: <a href="Strings.html#Strings" accesskey="n" rel="next">Strings</a>, Previous: <a href="Data-Types.html#Data-Types" accesskey="p" rel="prev">Data Types</a>, Up: <a href="index.html#Top" 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#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Numeric-Data-Types-1"></a>
<h2 class="chapter">4 Numeric Data Types</h2>
<a name="index-numeric-constant-1"></a>
<a name="index-numeric-value-1"></a>
<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
that can be an integer, a decimal fraction, a number in scientific
(exponential) notation, or a complex number. Note that by default numeric
constants are represented within Octave in double-precision floating
point format (complex constants are stored as pairs of double-precision
floating point values). It is, however, possible to represent real
integers as described in <a href="Integer-Data-Types.html#Integer-Data-Types">Integer Data Types</a>. Here are some
examples of real-valued numeric constants, which all have the same
value:
</p>
<div class="example">
<pre class="example">105
1.05e+2
1050e-1
</pre></div>
<p>To specify complex constants, you can write an expression of the form
</p>
<div class="example">
<pre class="example">3 + 4i
3.0 + 4.0i
0.3e1 + 40e-1i
</pre></div>
<p>all of which are equivalent. The letter ‘<samp>i</samp>’ in the previous example
stands for the pure imaginary constant, defined as
<code>sqrt (-1)</code>.
</p>
<p>For Octave to recognize a value as the imaginary part of a complex
constant, a space must not appear between the number and the ‘<samp>i</samp>’.
If it does, Octave will print an error message, like this:
</p>
<div class="example">
<pre class="example">octave:13> 3 + 4 i
parse error:
syntax error
>>> 3 + 4 i
^
</pre></div>
<p>You may also use ‘<samp>j</samp>’, ‘<samp>I</samp>’, or ‘<samp>J</samp>’ in place of the
‘<samp>i</samp>’ above. All four forms are equivalent.
</p>
<a name="XREFdouble"></a><dl>
<dt><a name="index-double"></a>Built-in Function: <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>
<a name="XREFcomplex"></a><dl>
<dt><a name="index-complex"></a>Built-in Function: <em></em> <strong>complex</strong> <em>(<var>x</var>)</em></dt>
<dt><a name="index-complex-1"></a>Built-in Function: <em></em> <strong>complex</strong> <em>(<var>re</var>, <var>im</var>)</em></dt>
<dd><p>Return a complex result from real arguments. With 1 real argument <var>x</var>,
return the complex result <code><var>x</var> + 0i</code>. With 2 real arguments,
return the complex result <code><var>re</var> + <var>im</var></code>. <code>complex</code> can
often be more convenient than expressions such as <code>a + i*b</code>.
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#Matrices" accesskey="1">Matrices</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="Ranges.html#Ranges" 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#Single-Precision-Data-Types" 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#Integer-Data-Types" 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#Bit-Manipulations" 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#Logical-Values" 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#Promotion-and-Demotion-of-Data-Types" 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#Predicates-for-Numeric-Objects" 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#Strings" accesskey="n" rel="next">Strings</a>, Previous: <a href="Data-Types.html#Data-Types" accesskey="p" rel="prev">Data Types</a>, Up: <a href="index.html#Top" 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#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|