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
|
<html lang="en">
<head>
<title>Numeric 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="prev" href="Data-Types.html#Data-Types" title="Data Types">
<link rel="next" href="Strings.html#Strings" title="Strings">
<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="Numeric-Data-Types"></a>
Next: <a rel="next" accesskey="n" href="Strings.html#Strings">Strings</a>,
Previous: <a rel="previous" accesskey="p" href="Data-Types.html#Data-Types">Data Types</a>,
Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>
<h2 class="chapter">4 Numeric Data Types</h2>
<p><a name="index-numeric-constant-211"></a><a name="index-numeric-value-212"></a>
A <dfn>numeric constant</dfn> may be a scalar, a vector, or a matrix, and it
may contain complex values.
<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:
<pre class="example"> 105
1.05e+2
1050e-1
</pre>
<p>To specify complex constants, you can write an expression of the form
<pre class="example"> 3 + 4i
3.0 + 4.0i
0.3e1 + 40e-1i
</pre>
<p class="noindent">all of which are equivalent. The letter ‘<samp><span class="samp">i</span></samp>’ in the previous example
stands for the pure imaginary constant, defined as
<code>sqrt (-1)</code>.
<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><span class="samp">i</span></samp>’.
If it does, Octave will print an error message, like this:
<pre class="example"> octave:13> 3 + 4 i
parse error:
syntax error
>>> 3 + 4 i
^
</pre>
<p class="noindent">You may also use ‘<samp><span class="samp">j</span></samp>’, ‘<samp><span class="samp">I</span></samp>’, or ‘<samp><span class="samp">J</span></samp>’ in place of the
‘<samp><span class="samp">i</span></samp>’ above. All four forms are equivalent.
<!-- ov-re-mat.cc -->
<p><a name="doc_002ddouble"></a>
<div class="defun">
— Built-in Function: <b>double</b> (<var>x</var>)<var><a name="index-double-213"></a></var><br>
<blockquote><p>Convert <var>x</var> to double precision type.
<!-- 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_002dsingle.html#doc_002dsingle">single</a>.
</p></blockquote></div>
<!-- data.cc -->
<p><a name="doc_002dcomplex"></a>
<div class="defun">
— Built-in Function: <b>complex</b> (<var>x</var>)<var><a name="index-complex-214"></a></var><br>
— Built-in Function: <b>complex</b> (<var>re, im</var>)<var><a name="index-complex-215"></a></var><br>
<blockquote><p>Return a complex result from real arguments. With 1 real argument <var>x</var>,
return the complex result <var>x</var><code> + 0i</code>. With 2 real arguments,
return the complex result <var>re</var><code> + </code><var>im</var>. <code>complex</code> can
often be more convenient than expressions such as <code>a + i*b</code>.
For example:
<pre class="example"> complex ([1, 2], [3, 4])
1 + 3i 2 + 4i
</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_002dreal.html#doc_002dreal">real</a>, <a href="doc_002dimag.html#doc_002dimag">imag</a>, <a href="doc_002discomplex.html#doc_002discomplex">iscomplex</a>.
</p></blockquote></div>
<ul class="menu">
<li><a accesskey="1" href="Matrices.html#Matrices">Matrices</a>
<li><a accesskey="2" href="Ranges.html#Ranges">Ranges</a>
<li><a accesskey="3" href="Single-Precision-Data-Types.html#Single-Precision-Data-Types">Single Precision Data Types</a>
<li><a accesskey="4" href="Integer-Data-Types.html#Integer-Data-Types">Integer Data Types</a>
<li><a accesskey="5" href="Bit-Manipulations.html#Bit-Manipulations">Bit Manipulations</a>
<li><a accesskey="6" href="Logical-Values.html#Logical-Values">Logical Values</a>
<li><a accesskey="7" href="Promotion-and-Demotion-of-Data-Types.html#Promotion-and-Demotion-of-Data-Types">Promotion and Demotion of Data Types</a>
<li><a accesskey="8" href="Predicates-for-Numeric-Objects.html#Predicates-for-Numeric-Objects">Predicates for Numeric Objects</a>
</ul>
</body></html>
|