<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <!-- Created by GNU Texinfo 6.5, 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 5.1.0))</title> <meta name="description" content="Numeric Data Types (GNU Octave (version 5.1.0))"> <meta name="keywords" content="Numeric Data Types (GNU Octave (version 5.1.0))"> <meta name="resource-type" content="document"> <meta name="distribution" content="global"> <meta name="Generator" content="makeinfo"> <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.indentedblock {margin-right: 0em} blockquote.smallindentedblock {margin-right: 0em; font-size: smaller} blockquote.smallquotation {font-size: smaller} div.display {margin-left: 3.2em} div.example {margin-left: 3.2em} div.lisp {margin-left: 3.2em} div.smalldisplay {margin-left: 3.2em} div.smallexample {margin-left: 3.2em} 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.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"> <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. 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">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> <a name="XREFdouble"></a><dl> <dt><a name="index-double"></a><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><em></em> <strong>complex</strong> <em>(<var>x</var>)</em></dt> <dt><a name="index-complex-1"></a><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#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>