.TH FC 1.SH NAMEfc \- command-line floating point calculator.SH SYNOPSIS.B fc[.I base].I expression.br.SH DESCRIPTION.B Fccalculates the result of its argument.I expressionand prints the result in the format indicated bythe optional base argument..I Basecan be one of:.TP.B -dDecimal, as produced by the.B %gformat of.IR sys-print (2)..br.TP.B -xHexadecimal, prefixed with.BR 0x ..TP.B -oOctal, prefixed with.BR 0 ..TP.B -bBinary, prefixed with.BR 0b ..TP.B -BAs.BR -b ,but with extra lines to help bit-counting..TP.BI -r\ radixIn base.IR radix ,prefixed with.IB \fR``\fPradix r\fR'',\fPas understood by Limbo (e.g..BR 16r3fff )..TP.B -cAs a unicode character, prefixed with.BR @ ..RE.PP.I Expressionis 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 fromthe stack (the number of items depends on the operator)and push their result. All operands are converted to double precisionfloating point numbers before being pushed.Integer operations convert their operands to big (64-bit) integers.When all arguments are exhausted, all the values currentlyon the stack are printed, first-pushed first, in the specifiedoutput format..PPOperands can be given in any of the formats that.I fccan print, as detailed above..PPWhen an operation is not commutative, the argument valueswill be taken from the stack first-pushed first.Most functions from from.IR math-elem (2),.IR math-fp(2)are provided.In addition, other provided operators include:.TP.B + - / xRepresenting the four rules. Note the use of.B xrather than.BR * ,to avoid clashes with shell metacharacters..br.TP.B xxTo the power. (equivelant to 'pow').br.TP.B rad degConvert value to or from radians..br.TP!Factorial..br.TP.B _Unary minus..br.TP.B and or xor notBitwise operations..br.TP.B shl shrBitwise shift left/right..TP.B pPrint the current top value on the stack..br.TP.B sumSum all the values currently pushed on the stack..br.TP.B swapSwap the top two stack items..br.TP.B dupDuplicate the top item on the stack..br.TP.B repRepeatedly execute the last operator untilthere is only only one item left on the stack.This is only valid for operators that take exactly twoarguments..RE.PPA few symbolic names for operands are recognised, including.B pi(or.BR π ),.BR e ,and.BR macheps ..SH EXAMPLES.PPfc 22 7 /.PP.nf gives 3.1428571429.fi.PPfc -b 1 2 3 4 sum.PP.nf gives 0b00001010.fi.PPfc 10 0b10 010 0x10 x rep 0xa00 swap -.PP.nf gives 0.fi.PPfc -help.PP.nf gives a usage summary, including a list of the names of all the operators..fi.ne 5.SH SEE ALSO.IR calc (1),.IR math-fp (2),.IR math-elem (2),.IR sh-expr (1).SH DIAGNOSTICSAn error message is displayed ifan operator is called on a stack withtoo few elements. This also causes.I fcto yield a non-null exit status..SH BUGSThe.B -Boption will only work for fixed-width fonts.
.TH FC 1
.SH NAME
fc \- command-line floating point calculator
.SH SYNOPSIS
.B fc
[
.I base
]
.I expression
.br
.SH DESCRIPTION
.B Fc
calculates the result of its argument
.I expression
and prints the result in the format indicated by
the optional base argument.
.I Base
can be one of:
.TP
.B -d
Decimal, as produced by the
.B %g
format of
.IR sys-print (2).
.br
.TP
.B -x
Hexadecimal, prefixed with
.BR 0x .
.TP
.B -o
Octal, prefixed with
.BR 0 .
.TP
.B -b
Binary, prefixed with
.BR 0b .
.TP
.B -B
As
.BR -b ,
but with extra lines to help bit-counting.
.TP
.BI -r\ radix
In base
.IR radix ,
prefixed with
.IB \fR``\fPradix r\fR'',\fP
as understood by Limbo (e.g.
.BR 16r3fff ).
.TP
.B -c
As a unicode character, prefixed with
.BR @ .
.RE
.PP
.I 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.
.PP
Operands can be given in any of the formats that
.I fc
can print, as detailed above.
.PP
When an operation is not commutative, the argument values
will be taken from the stack first-pushed first.
Most functions from from
.IR math-elem (2),
.IR math-fp(2)
are provided.
In addition, other provided operators include:
.TP
.B + - / x
Representing the four rules. Note the use of
.B x
rather than
.BR * ,
to avoid clashes with shell metacharacters.
.br
.TP
.B xx
To the power. (equivelant to 'pow')
.br
.TP
.B rad deg
Convert value to or from radians.
.br
.TP
!
Factorial.
.br
.TP
.B _
Unary minus.
.br
.TP
.B and or xor not
Bitwise operations.
.br
.TP
.B shl shr
Bitwise shift left/right.
.TP
.B p
Print the current top value on the stack.
.br
.TP
.B sum
Sum all the values currently pushed on the stack.
.br
.TP
.B swap
Swap the top two stack items.
.br
.TP
.B dup
Duplicate the top item on the stack.
.br
.TP
.B 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.
.RE
.PP
A few symbolic names for operands are recognised, including
.B pi
(or
.BR π ),
.BR e ,
and
.BR macheps .
.SH EXAMPLES
.PP
fc 22 7 /
.PP
.nf
gives 3.1428571429
.fi
.PP
fc -b 1 2 3 4 sum
.PP
.nf
gives 0b00001010
.fi
.PP
fc 10 0b10 010 0x10 x rep 0xa00 swap -
.PP
.nf
gives 0
.fi
.PP
fc -help
.PP
.nf
gives a usage summary, including a list of
the names of all the operators.
.fi
.ne 5
.SH SEE ALSO
.IR calc (1),
.IR math-fp (2),
.IR math-elem (2),
.IR sh-expr (1)
.SH DIAGNOSTICS
An error message is displayed if
an operator is called on a stack with
too few elements. This also causes
.I fc
to yield a non-null exit status.
.SH BUGS
The
.B -B
option will only work for fixed-width fonts.