# Expressions

In general, any mathematical expression accepted by C, FORTRAN, Pascal, or BASIC is valid. The precedence of these operators is determined by the specifications of the C programming language. White space (spaces and tabs) is ignored inside expressions.

Note that gnuplot uses both `"`real`"` and `"`integer`"` arithmetic, like FORTRAN and C. Integers are entered as `"`1`"`, `"`-10`"`, etc; reals as `"`1.0`"`, `"`-10.0`"`, `"`1e1`"`, 3.5e-1, etc. The most important difference between the two forms is in division: division of integers truncates: 5/2 = 2; division of reals does not: 5.0/2.0 = 2.5. In mixed expressions, integers are `"`promoted`"` to reals before evaluation: 5/2e0 = 2.5. The result of division of a negative integer by a positive one may vary among compilers. Try a test like `"`print -5/2`"` to determine if your system always rounds down (-5/2 yields -3) or always rounds toward zero (-5/2 yields -2).

The integer expression `"`1/0`"` may be used to generate an `"`undefined`"` flag, which causes a point to be ignored. Or you can use the pre-defined variable NaN to achieve the same result. See using (p. ) for an example.

Gnuplot can also perform simple operations on strings and string variables. For example, the expression (`"`A`"` . `"`B`"` eq `"`AB`"`) evaluates as true, illustrating the string concatenation operator and the string equality operator.

A string which contains a numerical value is promoted to the corresponding integer or real value if used in a numerical expression. Thus (`"`3`"` + `"`4`"` == 7) and (6.78 == `"`6.78`"`) both evaluate to true. An integer, but not a real or complex value, is promoted to a string if used in string concatenation. A typical case is the use of integers to construct file names or other strings; e.g. (`"`file`"` . 4 eq `"`file4`"`) is true.

Substrings can be specified using a postfixed range descriptor [beg:end]. For example, `"`ABCDEF`"`[3:4] == `"`CD`"` and `"`ABCDEF`"`[4:*] == `"`DEF`"` The syntax `"`string`"`[beg:end] is exactly equivalent to calling the built-in string-valued function substr(`"`string`"`,beg,end), except that you cannot omit either beg or end from the function call.

Subsections

- Constants
- Functions
  - Elliptic integrals
  - Random number generator
  - Value
  - Counting and extracting words
- Operators
  - Unary
  - Binary
  - Ternary
- Summation
- Gnuplot-defined variables
- User-defined variables and functions
- Arrays