FC(1) FC(1)
NAME
fc - command-line floating point calculator
SYNOPSIS
fc [ base ] expression
DESCRIPTION
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:
-d Decimal, as produced by the %g format of sys-print(2).
-x Hexadecimal, prefixed with 0x.
-o Octal, prefixed with 0.
-b Binary, prefixed with 0b.
-B 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).
-c 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 opera-
tions 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 out-
put 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 func-
tions 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.
Page 1 Plan 9 (printed 10/26/25)
FC(1) FC(1)
xx To the power. (equivelant to 'pow')
rad deg
Convert value to or from radians.
! Factorial.
_ Unary minus.
and or xor not
Bitwise operations.
shl shr
Bitwise shift left/right.
p Print the current top value on the stack.
sum Sum all the values currently pushed on the stack.
swap Swap the top two stack items.
dup Duplicate the top item on the stack.
rep 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 π), e, and macheps.
EXAMPLES
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.
SEE ALSO
calc(1), math-fp(2), math-elem(2), sh-expr(1)
DIAGNOSTICS
Page 2 Plan 9 (printed 10/26/25)
FC(1) FC(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.
BUGS
The -B option will only work for fixed-width fonts.
Page 3 Plan 9 (printed 10/26/25)