Charles.Forsyth20070601-14568bd193319 years agoHistory
183 lines · 3.0 KB · Text
RawDownload
.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.