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: Acknowledgments
  18: License

Indices:
  Concepts
  Commands
  Variables
index.html#Top ReversePolishMath.html#rpnMathematics Gri: tertiary operators Gri: RPN unary operators index.html#Top Gri: RPN unary operators

10.9.4: Binary Operators

Binary operators act on the top two items on the stack. Most binary operators replace two items on the stack with one item, e.g. `{rpn 1 2 /}' yields 0.5. However, a few binary operators replace one pair of items with a new pair of items, e.g. the `xyusertocm' operator replaces an (x,y) pair in user coordinates with an (xcm,ycm) pair in coordinates of centimeters on the page.

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

{rpn 3 2 +}
Add 2 to 3.
{rpn 3 2 -}
Subtract 2 from 3.
{rpn 3 2 *}
Multiply 3 by 2.
{rpn 3 2 /}
Divide 3 by 2.
{rpn 3 2 <}

Test whether 2 is less than 3, yielding 1. Note: this convention may be confusing to users who are familiar with HP calculators from decades past. Present-day calculators use this convention, but possibly older calculators used the reverse convention, using `>' where Gri uses `<'.

{rpn 3 2 <=}
Test whether 2 is less than or equal to 3.

{rpn 3 2 >}
Test whether 2 is greater than 3, yielding 0.

{rpn 3 2 >=}
Test whether 2 is greater than or equal to 3, yielding 0.

{rpn 3 2 ==}
Test whether 2 and 3 are equal, yielding 0. (Do not confuse this with the asignment operator `=', described next.)

{rpn 10 ".ten." =}
Assign the value `10' to the variable named `.ten.'. (Do not confuse this with the `==' equality operator described above.)

{rpn "hello" "\\greeting" =}
Assign the value `"hello"' to the synonym `\greeting'.

{rpn 0 1 &}
Test whether 0 and 1 are both true, yielding 0.

{rpn 0 1 |}
Test whether either 0 or 1 is true, yielding 1.

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

{rpn x 0 @}
Yields the value of the first number in the x column. A similar form also works for `y', etc. (see Manipulation of Columns etc).

{rpn 2 3 inf}
Pick the smaller of two values, yielding 3. (Opposite to `sup'.)

{rpn 2 3 power}
Take 2 to the 3rd power, yielding 8. Note: This convention may be confusing to users who are familiar with HP calculators from decades past. Present-day calculators use this convention, which they write as `y^x', but older calculators used the reverse convention, labelling the key `x^y'.

{rpn 2 3 remainder}
Calculate the remainder after dividing 2 by 3, yielding 2. The return value for `{rpn A B remainder'} is `B - n * A', where `n' is the quotient of `A/B', rounded towards zero to an integer. In this case, `2/3' rounds to an `n' value of zero, yielding 2 as the resulting remainder.

{rpn "file" ".dat" strcat}
Concatenate the two strings, yielding the string `"file.dat"'.

{rpn 2 3 sup}
Pick the larger of two values, yielding 3. (Opposite to `inf'.)