navigation map

Chapters:
  1: Introduction
  2: Simple example
  3: Invocation
  4: Finer Control
  5: X-Y Plots
  6: Contour Plots
  7: Image Plots
  8: Examples
  9: Gri Commands
  10: Programming
  11: Environment
  12: Emacs Mode
  13: History
  14: Installation
  15: Gri Bugs
  16: Test Suite
  17: Gri in Press
  18: Acknowledgments
  19: License

Indices:
  Concepts
  Commands
  Variables
index.html#Top ReversePolishMath.html#rpnMathematics Gri: RPN binary operators Gri: RPN solitary operators index.html#Top Gri: RPN solitary operators

10.9.5: Unary Operators

Unary operators replace the last item on the stack with another item. For example, the `sin' operator takes the sine of the number on the top of the stack; e.g., `{rpn 45 sin}' yields the sine of 45 degrees.

The unary operators are illustrated below, in rough alphabetical order.

{rpn 0 !}
Replace 0 (false) with its logical negation 1 (true).

{rpn 0 not}
Replace 0 (false) with its logical negation 1 (true).

{rpn -3 abs}
Calculate the absolute value of `-3'.

{rpn 0.5 acos}
Calculate the inverse cosine of 0.5, yielding 60 (degrees).

{rpn 2 acosh}
Calculate the inverse hyperbolic cosine of 2, yielding 1.317. (Note: argument must equal or exceed 1, or an error results.)

{rpn y x area}
Calculate the area under the curve y=y(x). For details (see Manipulation of Columns etc).

{rpn 0.5 asin}
Calculate the inverse sine of 0.5, yielding 30 (degrees).

{rpn 1 atan}
Calculate the inverse tangent of 1, yielding 45 (degrees).

{rpn 0.5 atanh}
Calculate the inverse hyperbolic tangent of 0.5, yielding 0.549306 (radians).

{rpn 0 argv}
Returns the name of the Gri command-file, which is considered as the first "optional" argument. (It may seem odd that the name of the command-file is considered an option, but Gri does this for consistency with C and other languages. It is useful.) Other arguments provided when Gri was invoked are provided as `rpn 1 argv', etc.

A string consisting of a single blank character results if one tries to access beyond the list of arguments that were actually supplied. See also the `argc' solitary operator (see Solitary Operators), which returns the number of optional arguments.

For example, if Gri is invoked as


gri myscript.gri file1.dat file2.dat

and if `myscript.gri' contained


.n. = {rpn argc}
.i. = 0
while {rpn .n. .i. <}
    show "argument " .i. " is " {rpn .i. argv}
    .i. += 1
end while

then the output would be


argument 0 is myscript.gri
argument 1 is file1.dat
argument 2 is file2.dat

For usage within the Emacs gri-mode, see see Filename arguments when running gri.

{rpn "hi" ascent}
Determine ascent of this string (in cm), in the present font and fontsize. (See also `descent' and `width'.)

{rpn "3.1" atof}
Calculate the numerical value contained in indicated string.

{rpn 1.5 ceil}
Calculate the next higher integer, yielding 2. (Opposite of `floor'.)

{rpn 45 cos}
Calculate the cosine of 45 degrees, yielding 0.707.

{rpn 1 cosh}
Calculate the hyperbolic cosine of 1 (radian), yielding 1.543.

{rpn 1 cmtopt}
Convert from 1 centimeter to so-called ``point'' units, yielding 28.45. (Opposite of `pttocm'.)

{rpn 170 dec2hex}
Convert a number into a string which is its hexadecimal representation. Before the conversion, the number is rounded to the nearest integer, and if the result is negative, an error results. The string is double-quoted, with letters (if there are any) being in upper case.

For example `\hex = {rpn 63 dec2hex'} is equivalent to `\hex = "3F"'.

Compare with `hex2dec', the inverse.

{rpn "\\syn" defined}
Test whether the synonym is defined at the moment, returning 1 if so and 0 if not. (Note the double-backslash in the synonym name, which is required.)

{rpn ".var." defined}
Test whether the variable is defined at the moment, returning 1 if so and 0 if not.

{rpn "\\@alias" defined}
Test whether the variable/synonym item that is named by the alias (see Alias Synonyms) is defined at the moment, returning 1 if so and 0 if not.

{rpn "hi" descent}
Calculate the descent (below the baseline in cm) for the given string, in the present font and fontsize. (See also `ascent' and `width'.)

{rpn "/home/me/data/timeseries" directory_exists}
Determine whether indicate directory exists, yielding `1' if it does and `0' otherwise. (See also `file_exists'.)

{rpn 2 dup}
Duplicate the top item on stack, yielding `2 2' on the stack. (See also `exch' and `pop'.)

{rpn 1 exp}
Calculate the value of `e' raised to the indicated power, yielding 2.71828.

{rpn 2 exp10}
Calculate the value of `10' raised to the indicated power, yielding 100.

{rpn "foo.dat" file_exists}
Determine whether the indicate file exists, yielding `1' if it does and `0' otherwise. (See also `directory_exists'.)

{rpn 1.5 floor}
Calculate the nearest smaller integer, yielding 1. (Opposite of `ceil'.)

{rpn "AA" hex2dec}
Convert a string, representing a hexadecimal value, into an integer. The string must be double-quoted, and it may contain either lower- or upper-case letters; this is in contrast to the inverse function, `dec2hex', which returns upper-case.

This operator is most often used in working with colours, since Gri handles colour components in decimal terms, whereas many other applications refer to the components in hexadecimal notation.

Compare with `dec2hex', the inverse.

{rpn 3 ismissing}
Yields 1 if the indicated value is a ``missing value'' or 0 otherwise.

{rpn 100 log}
Calculate the base-10 logarithm of 100, yielding 2.

{rpn 10 ln}
Calculate the natural logarithm of 10, yielding 2.30259.

{rpn x mean}
Yields the mean value of the (non-missing) numbers in the x column. A similar form also works for `y', etc. (see Manipulation of Columns etc).

{rpn x max}
Yields the largest value of the (non-missing) numbers in the x column. A similar form also works for `y', etc. (see Manipulation of Columns etc).

{rpn x min}
Yields the smallest value of the (non-missing) numbers in the x column. A similar form also works for `y', etc. (see Manipulation of Columns etc).

{rpn 28.45 pttocm}
Calculate the number of centimeters in 28.45 printers points, yielding 1. (Opposite of `cmtopt'.)

{rpn 1 2 pop}
Remove the top item from the stack, yielding `1' on the stack. Generates an error if the stack is empty. (See also `exch' and `dup'.)

{rpn 4 sqrt}
Calculate the square root of 4, yielding 2. (Negative arguments yield errors.)

{rpn 45 sin}
Calculate the sine of 45 (degrees), yielding 0.707107.

{rpn 2 sinh}
Calculate the hyperbolic sine of 2, yielding 3.62686.

{rpn "hello" strlen}
Determine the number of characters in string, e.g. 6 here.

{rpn "date" system}
Call the indicated system function and insert its ouput on the stack, yielding the date as a character string.

{rpn 45 tan}
Calculate the tangent of 45 (degrees), yielding 1.

{rpn tanh}
Calculate the hyperbolic tangent of 2, yielding 0.964028.

{rpn "hi" width}
Determine width of this string (in cm), in the present font and fontsize. (See also `ascent' and `descent'.)

{rpn 0 wordv}
Returns the first word used in invoking the present command. Similar to the `\.word0.' synonym (see Local Synonyms). Example:


`let us test .it.'
{
  .w. = 0
  while {rpn .w. wordc >}
    show "The " .w. "-th word is `" {rpn .w. wordv} "'."
    .w. += 1
  end while
}
let us test "this thing"
let us test "this" "thing"
let us test "Pi is" {rpn 3.14}

If you are using this to parse options given to the command, it is up to you to skip the non-optional words in the command. In this case, for example, we skipped the first three words (`let', `us', and `test').

{rpn 1 xusertocm}
Calculate the x coordinate, in centimeters measured from left-hand side of page, corresponding to a user-value of x=1. (Opposite of `xcmtouser'.)

{rpn 1 xcmtouser}
Calculate the x value, in user units, for a point that is 1 centimeter from the left-hand edge of the paper. (Opposite of `xusertocm'.)

{rpn 1 yusertocm}
Calculate the y coordinate, in centimeters measured from bottom side of page, corresponding to a user-value of x=1. (Opposite of `ycmtouser'.)

{rpn 1 ycmtouser}
Calculate the y value, in user units, for a point that is 1 centimeter from the bottom edge of the paper. (Opposite of `yusertocm'.)

navigation map