[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4. Numeric Data Types

A numeric constant may be a scalar, a vector, or a matrix, and it may contain complex values.

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 Integer Data Types. Here are some examples of real-valued numeric constants, which all have the same value:

 
105
1.05e+2
1050e-1

To specify complex constants, you can write an expression of the form

 
3 + 4i
3.0 + 4.0i
0.3e1 + 40e-1i

all of which are equivalent. The letter `i' in the previous example stands for the pure imaginary constant, defined as sqrt (-1).

For Octave to recognize a value as the imaginary part of a complex constant, a space must not appear between the number and the `i'. If it does, Octave will print an error message, like this:

 
octave:13> 3 + 4 i

parse error:

  3 + 4 i
        ^

You may also use `j', `I', or `J' in place of the `i' above. All four forms are equivalent.

Built-in Function: double (x)

Convert x to double precision type.

Function File: single (val)

Convert the numeric value val to single precision.

Note: this function currently returns its argument converted to double precision because Octave does not yet have a single-precision numeric data type.

Built-in Function: complex (val)
Built-in Function: complex (re, im)

Convert x to a complex value.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated on December, 26 2007 using texi2html 1.76.