[manual index][section index]


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:

Decimal, as produced by the %g format of sys-print(2).
Hexadecimal, prefixed with 0x.
Octal, prefixed with 0.
Binary, prefixed with 0b.
As -b, but with extra lines to help bit-counting.
-r radix
In base radix, prefixed with ``radixr'', as understood by Limbo (e.g. 16r3fff).
As a unicode character, prefixed with @.

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:

+ - / x
Representing the four rules. Note the use of x rather than *, to avoid clashes with shell metacharacters.
To the power. (equivelant to 'pow')
rad deg
Convert value to or from radians.
Unary minus.
and or xor not
Bitwise operations.
shl shr
Bitwise shift left/right.
Print the current top value on the stack.
Sum all the values currently pushed on the stack.
Swap the top two stack items.
Duplicate the top item on the stack.
Repeatedly execute the last operator until there is only only one item left on the stack. This is only valid for operators that take exactly two arguments.

A few symbolic names for operands are recognised, including pi (or PI), 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.


calc(1), math-fp(2), math-elem(2), sh-expr(1)


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.

FC(1 ) Rev:  Fri Jun 01 15:51:58 GMT 2007