| FC(1) | General Commands Manual | FC(1) |
fc - command-line floating point calculator
fc [ base ] expression
Fc calculates the result of its argument expression and prints the result in the format indicated by the optional base argument. Base can be one of:
Expression is in reverse polish notation: each command line argument is either an operand (number) or an operator. Operands are pushed on a stack; operators pop items from the stack (the number of items depends on the operator) and push their result. All operands are converted to double precision floating point numbers before being pushed. Integer operations convert their operands to big (64-bit) integers. When all arguments are exhausted, all the values currently on the stack are printed, first-pushed first, in the specified output format.
Operands can be given in any of the formats that fc can print, as detailed above.
When an operation is not commutative, the argument values will be taken from the stack first-pushed first. Most functions from from math-elem (2), math-fp(2) are provided. In addition, other provided operators include:
A few symbolic names for operands are recognised, including pi (or π), e, and macheps.
fc 22 7 /
gives 3.1428571429
fc -b 1 2 3 4 sum
gives 0b00001010
fc 10 0b10 010 0x10 x rep 0xa00 swap -
gives 0
fc -help
gives a usage summary, including a list of the names of all the operators.
An error message is displayed if an operator is called on a stack with too few elements. This also causes fc to yield a non-null exit status.
The -B option will only work for fixed-width fonts.