Next: Strings, Previous: Data Types, Up: Top [Contents][Index]

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. 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 Integer Data Types.

If the numeric constant is a real integer, it can be defined in decimal,
hexadecimal, or binary notation. Hexadecimal notation starts with ‘`0x`’ or
‘`0X`’, binary notation starts with ‘`0b`’ or ‘`0B`’, otherwise
decimal notation is assumed. As a consequence, ‘`0b`’ is not a hexadecimal
number, in fact, it is not a valid number at all.

For better readability, digits may be partitioned by the underscore separator
‘`_`’, 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:

42 # decimal notation 0x2A # hexadecimal notation 0b101010 # binary notation 0b10_1010 # underscore notation round (42.1) # also binary64

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:

.105 1.05e-1 .00105e+2

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
(‘`i`’, ‘`j`’, ‘`I`’, or ‘`J`’ which represents
`sqrt (-1)`

).
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:

3 + 42i 3 + 42j 3 + 42I 3 + 42J 3.0 + 42.0i 3.0 + 0x2Ai 3.0 + 0b10_1010i 0.3e1 + 420e-1i

- :
**double***(*`x`) Convert

`x`to double precision type.**See also:**single.

- :
**complex***(*`x`) - :
**complex***(*`re`,`im`) Return a complex value from real arguments.

With 1 real argument

`x`, return the complex result

.`x`+ 0iWith 2 real arguments, return the complex result

.`re`+`im``complex`

can often be more convenient than expressions such as`a + i*b`

. For example:complex ([1, 2], [3, 4]) ⇒ [ 1 + 3i 2 + 4i ]

• Matrices: | ||

• Ranges: | ||

• Single Precision Data Types: | ||

• Integer Data Types: | ||

• Bit Manipulations: | ||

• Logical Values: | ||

• Promotion and Demotion of Data Types: | ||

• Predicates for Numeric Objects: |

Next: Strings, Previous: Data Types, Up: Top [Contents][Index]