@c Copyright (C) 1992 John W. Eaton
@c This is part of the Octave manual.
@c For copying conditions, see the file gpl.texi.

@node Built-in Variables, Built-in Functions, Statements, Top
@chapter Built-in Variables
@cindex Variables
@cindex built-in variables
@cindex variables, built-in

Octave provides a number of predefined variables.  Some, like
@code{do_fortran_indexing} and @code{page_screen_output} change Octave's
behavior.  Others, like the constants @code{pi} and @code{Inf} are
available to make programming easier.

@vtable @code
@item I
A pure imaginary number, defined as
@iftex
@tex
  $\sqrt{-1}$.
@end tex
@end iftex
@ifinfo
  @code{sqrt (-1)}.
@end ifinfo

@item Inf
Infinity.  This is the result of an operation like 1/0, or an operation
that results in a floating point overflow.

@item J
Another name for @code{I}.

@item NaN
Not a number.  This is the result of an operation like @samp{0/0}, or
@samp{Inf - Inf}, or any operation with a NaN.

@item LOADPATH
A colon separated list of directories in which to search for macro
files.  The value of @code{LOADPATH} overrides the environment variable
@code{OCTAVE_PATH}.  @xref{Installation}.

@item PAGER
The default value is @samp{less}, or, if @code{less} is not available
on your system, @samp{more}.  @xref{Installation}.

@c XXX FIXME XXX -- cross reference to a node on output.

@item PS1
The primary prompt string.  When executing interactively, Octave
displays the primary prompt @code{PS1} when it is ready to read a
command.  Octave allows the prompt to be customized by inserting a
number of backslash-escaped special characters that are decoded as
follows:

@table @code
@item \t
The time.
@item \d
The date.
@item \n
Begins a new line by printing the equivalent of a carriage return
followed by a line feed.
@item \s
The name of the program (usually just @code{octave}).
@item \w
The current working directory.
@item \W
The basename of the current working directory.
@item \u
The username of the current user.
@item \h
The hostname.
@item \#
The command number of this command, counting from when Octave starts.
@item \!
The history number of this command.  This differs from @samp{\#} by the
number of commands in the history list when Octave starts.
@item \$
If the effective UID is 0, a #, otherwise a $.
@item \nnn
The character whose character code in octal is @samp{nnn}.
@item \\
A backslash.
@end table

The default value if @code{PS1} is @samp{\s:\#> }.  To change it, use a
command like

@example
octave:13> PS1 = '\u@@\h> '
@end example

@noindent
which will result in the prompt @samp{boris@@kremvax> }.

@noindent
for the user @samp{boris} logged in on the host @samp{kremvax}.

@item PS2
The secondary prompt string, which is printed when Octave is
expecting additional input to complete a command.  For example, when
defining a function over several lines, Octave will print the value of
@code{PS1} at the beginning of each line after the first.  Octave allows
@code{PS2} to be customized in the same way as @code{PS1}.  The default
value of @code{PS2} is @samp{> }.

@item PWD
The current working directory.  The value of @code{PWD} is updated each
time the current working directory is changed with the @samp{cd} command
@xref{Built-in Functions}.

@item SEEK_SET
@itemx SEEK_CUR
@itemx SEEK_END

These variables may be used as the optional third argument for the
function @code{fseek}.

@item ans
If an assignment is not explicitly specified, the result of an
expression is assigned to @code{ans}.

@item do_fortran_indexing
If the value of @code{do_fortran_indexing} is @samp{true}, Octave allows 
you to select elements of a two-dimensional matrix using a single index
by treating the matrix as a single vector created from the columns of
the matrix.  The default value is @samp{false}. 

@item empty_list_elements_ok
This variable controls whether Octave ignores empty matrices in a matrix
list.

For example, if the value of @code{empty_list_elements_ok} is
@samp{true}, Octave will ignore the empty matrices in the expression

@example
a = [1, [], 3, [], 5]
@end example

@noindent
and the variable @samp{a} will be assigned the value @samp{[ 1 3 5 ]}.

The default value is @samp{warn}.

@item eps
The machine precision.  More precisely, @code{eps} is the smallest value
such that @samp{1+eps} is not equal to 1.

@item gnuplot_binary
The name of the program invoked by the plot command.  The default value
is @samp{gnuplot}.  @xref{Installation}.

@item i
Another name for @code{I}.

@item implicit_str_to_num_ok
If the value of @code{implicit_str_to_num_ok} is @samp{true}, implicit
conversions of strings to their numeric ASCII equivalents are allowed.
Otherwise, an error message is printed and control is returned to the
top level.  The default value is @samp{true}.

@item inf
Another name for @code{Inf}.

@item j
Another name for @code{I}.

@item nan
Another name for @code{NaN}.

@item ok_to_lose_imaginary_part
If the value of @code{ok_to_lose_imaginary_part} is @samp{true},
implicit conversions of complex numbers to real numbers are allowed (for
example, by fsolve).  If the value is @samp{warn}, the conversion is allowed,
but a warning is printed.  Otherwise, an error message is printed and
control is returned to the top level.  The default value is @samp{warn}.

@item output_max_field_width
This variable specifies the maximum width of a numeric output field.
The default value is 10.

@c XXX FIXME XXX -- cross reference to a node on output.

It is possible to achieve a wide range of output styles by using
different values of @code{output_precision} and
@code{output_max_field_width}.  Reasonable combinations can be set using
the @code{format} function.  @xref{Built-in Functions}.

@item output_precision
This variable specifies the minimum number of significant figures to
display for numeric output.  The default value is 5.

@c XXX FIXME XXX -- cross reference to a node on output.

It is possible to achieve a wide range of output styles by using
different values of @code{output_precision} and
@code{output_max_field_width}.  Reasonable combinations can be set using
the @code{format} function.  @xref{Built-in Functions}.

@item page_screen_output
If the value of @code{page_screen_output} is @samp{true}, all output
intended for the screen that is longer than one page is sent through a
pager.  This allows you to view one screenful at a time.  Some pagers
(such as @code{less}---see @ref{Installation}) are also capable of moving
backward on the output.  The default value is @samp{true}.

@c XXX FIXME XXX -- cross reference to a node on output.

You can choose the program to use as the pager by setting the variable
@code{PAGER}.

@item pi
The ratio of the circumference of a circle to its diameter.
Internally, @code{pi} is computed as @samp{4.0 * atan (1.0)}.

@item prefer_column_vectors
If @code{prefer_column_vectors} is @samp{true}, operations like

@example
octave:13> for i = 1:10 a (i) = i; endfor
@end example

@noindent
(for @samp{a} previously  undefined) produce column vectors.  Otherwise, row
vectors are preferred.  The default value is @samp{false}.

If a variable is already defined to be a vector (a matrix with a single
row or column), the original orientation is respected, regardless of the
value of @code{prefer_column_vectors}.

@item prefer_zero_one_indexing
If the value of @code{prefer_zero_one_indexing} is @samp{true}, Octave
will perform zero-one style indexing when there is a conflict with the
normal indexing rules.  @xref{Index Expressions}.  For example, given a
matrix

@example
a = [1, 2, 3, 4]
@end example

@noindent
with @code{prefer_zero_one_indexing} is set to @samp{true}, the
statement

@example
a ([1, 1, 1, 1])
@end example

@noindent
results in the matrix @samp{[ 1  2  3  4 ]}.  If the value of
@code{prefer_zero_one_indexing} set to @samp{false}, the result would be
the matrix @samp{[ 1 1 1 1 ]}.

In the first case, Octave is selecting each element corresponding to a
@samp{1} in the index vector.  In the second, Octave is selecting the
first element multiple times.

The default value for @code{prefer_zero_one_indexing} is @samp{false}.

@item print_answer_id_name
If the value of @code{print_answer_id_name} is @samp{true}, variable
names are printed along with the result.  Otherwise, only the result
values are printed.  The default value is @samp{true}.

@item print_empty_dimensions
If the value of @code{print_empty_dimensions} is @samp{true}, the
dimensions of empty matrices are printed along with the empty matrix
symbol, @samp{[]}.  For example, the expression

@example
octave:13> zeros (3, 0)
@end example

@noindent
will print

@example
ans =

[](3x0)
@end example

@item propagate_empty_matrices
If the value of @code{propagate_empty_matrices} is @samp{true},
functions like @code{inverse} and @code{svd} will return an empty matrix
if they are given one as an argument.  The default value is @samp{true}.
Not entirely correct now.  XXX FIXME XXX

@item resize_on_range_error
If the value of @code{resize_on_range_error} is @samp{true}, expressions
like

@example
octave:13> for i = 1:10 a (i) = i; endfor
@end example

@noindent
(for @samp{a} previously undefined) result in the variable @samp{a}
being resized to be just large enough to hold the new value.  Otherwise
uninitialized elements are set to zero.  If the value of
@code{resize_on_range_error} is @samp{false}, an error message is
printed and control is returned to the top level.  The default value is
@samp{true}.

@item return_last_computed_value
If the value of @code{return_last_computed_value} is true, and a
function is defined without explicitly specifying a return value, the
function will return the value of the last expression.  Otherwise, no
value will be returned.  The default value is @samp{false}.

For example, the function

@example
function f ()
  2 + 2;
endfunction
@end example

@noindent
will either return nothing, if @code{return_last_computed_value} is
@samp{false}, or 4, if it is @samp{true}.

@item silent_functions
If the value of @code{silent_functions} is @samp{true}, internal output
from a function is suppressed.  Otherwise, the results of statements
within a function body that are not terminated with a semicolon will
have their values printed.  The default value is @samp{false}.

For example, if the function

@example
function f ()
  2 + 2
endfunction
@end example

@noindent
is executed, Octave will either print @samp{ans = 4} or nothing
depending on the value of @code{silent_functions}.

@item split_long_rows
For large matrices, Octave may not be able to display all the columns of
a given row on one line of your screen.  This can result in missing
information or output that is nearly impossible to decipher, depending
on whether your terminal truncates or wraps long lines.

If the value of @code{split_long_rows} is @samp{true}, Octave will
display the matrix in a series of smaller pieces, each of which can fit
within the limits of your terminal width.  Each set of rows is labeled
so that you can easily see which columns are currently being displayed.
For example:

@smallexample
octave:13> rand (2, 9)
ans =

 Columns 1 through 7:

   0.92205  0.72628  0.99841  0.62590  0.82422  0.77486  0.30258
   0.15999  0.79484  0.75443  0.86995  0.91430  0.23980  0.64591

 Columns 8 and 9:

  0.08894  0.13266
  0.28008  0.65575
@end smallexample

The default value of @code{split_long_rows} is @samp{true}.

@item stdin
@itemx stdout
@itemx stderr
These variables are the file numbers corresponding to the standard
input, standard output, and standard error streams.  These streams are
preconnected and available when Octave starts.

@item treat_neg_dim_as_zero
If the value of @code{treat_neg_dim_as_zero} is @samp{true}, expressions
like

@example
octave:13> eye (-1)
@end example

@noindent
produce an empty matrix (i.e., row and column dimensions are zero).
Otherwise, an error message is printed and control is returned to the
top level.  The default value is @samp{false}.

@item warn_comma_in_global_decl
If the value of @code{warn_comma_in_global_decl} is @samp{true}, a
warning is issued for statements like

@example
octave:13> global a = 1, b
@end example

@noindent
which makes the variables @samp{a} and @samp{b} global and assigns the
value 1 to the variable @samp{a}, because in this context, the comma is
not interpreted as a statement separator.

The default value of @code{warn_comma_in_global_decl} is @samp{true}.
@end vtable
