dc: Arithmetic

1 
1 4 Arithmetic
1 ************
1 
1 '+'
1      Pops two values off the stack, adds them, and pushes the result.
1      The precision of the result is determined only by the values of the
1      arguments, and is enough to be exact.
1 
1 '-'
1      Pops two values, subtracts the first one popped from the second one
1      popped, and pushes the result.
1 
1 '*'
1      Pops two values, multiplies them, and pushes the result.  The
1      number of fraction digits in the result is the largest of the
1      precision value, the number of fraction digits in the multiplier,
1      or the number of fraction digits in the multiplicand; but in no
1      event exceeding the number of digits required for an exact result.
1 
1 '/'
1      Pops two values, divides the second one popped from the first one
1      popped, and pushes the result.  The number of fraction digits is
1      specified by the precision value.
1 
1 '%'
1      Pops two values, computes the remainder of the division that the
1      '/' command would do, and pushes that.  The value computed is the
1      same as that computed by the sequence 'Sd dld/ Ld*-' .
1 
1 '~'
1      Pops two values, divides the second one popped from the first one
1      popped.  The quotient is pushed first, and the remainder is pushed
1      next.  The number of fraction digits used in the division is
1      specified by the precision value.  (The sequence 'SdSn lnld/ LnLd%'
1      could also accomplish this function, with slightly different error
1      checking.)  (This command is a GNU extension.)
1 
1 '^'
1      Pops two values and exponentiates, using the first value popped as
1      the exponent and the second popped as the base.  The fraction part
1      of the exponent is ignored.  The precision value specifies the
1      number of fraction digits in the result.
1 
1 '|'
1      Pops three values and computes a modular exponentiation.  The first
1      value popped is used as the reduction modulus; this value must be a
1      non-zero number, and the result may not be accurate if the modulus
1      is not an integer.  The second popped is used as the exponent; this
1      value must be a non-negative number, and any fractional part of
1      this exponent will be ignored.  The third value popped is the base
1      which gets exponentiated, which should be an integer.  For small
1      integers this is like the sequence 'Sm^Lm%', but, unlike '^', this
1      command will work with arbitrarily large exponents.  (This command
1      is a GNU extension.)
1 
1 'v'
1      Pops one value, computes its square root, and pushes that.  The
1      maximum of the precision value and the precision of the argument is
1      used to determine the number of fraction digits in the result.
1 
1    Most arithmetic operations are affected by the _precision value_,
1 which you can set with the 'k' command.  The default precision value is
1 zero, which means that all arithmetic except for addition and
1 subtraction produces integer results.
1