⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bc.1

📁 Unix操作系统minix 2.0源码
💻 1
📖 第 1 页 / 共 3 页
字号:
.\".\" bc.1 - the *roff document processor source for the bc manual.\".\" This file is part of bc written for MINIX..\" Copyright (C) 1991, 1992 Free Software Foundation, Inc..\".\" This program is free software; you can redistribute it and/or modify.\" it under the terms of the GNU General Public License as published by.\" the Free Software Foundation; either version 2 of the License , or.\" (at your option) any later version..\".\" This program is distributed in the hope that it will be useful,.\" but WITHOUT ANY WARRANTY; without even the implied warranty of.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the.\" GNU General Public License for more details..\".\" You should have received a copy of the GNU General Public License.\" along with this program; see the file COPYING.  If not, write to.\" the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA..\".\" You may contact the author by:.\" e-mail: phil@cs.wwu.edu.\" us-mail: Philip A. Nelson.\" Computer Science Department, 9062.\" Western Washington University.\" Bellingham, WA 98226-9062.\".\".TH bc 1 .\" "Command Manual" v1.02 "Feb 3, 1992".SH NAMEbc - An arbitrary precision calculator language.SH SYNTAX\fBbc\fR [ \fB-lws\fR ] [ \fI file ...\fR ].SH VERSIONThis man page documents GNU bc version 1.02..SH DESCRIPTION\fBbc\fR is a language that supports arbitrary precision numberswith interactive execution of statements.  There are some similaritiesin the syntax to the C programming language. A standard math library is available by command line option.If requested, the math library is defined before processing any files.\fBbc\fR starts by processing code from all the files listedon the command line in the order listed.  After all files have beenprocessed, \fBbc\fR reads from the standard input.  All code isexecuted as it is read.  (If a file contains a command to halt theprocessor, \fBbc\fR will never read from the standard input.).PPThis version of \fBbc\fR contains several extensions beyondtraditional \fBbc\fR implementations and the POSIX draft standard.Command line options can cause these extensions to print a warning or to be rejected.  This document describes the language accepted by this processor.Extensions will be identified as such..SS OPTIONS.IP -lDefine the standard math library..IP -wGive warnings for extensions to POSIX \fBbc\fR..IP -sProcess exactly the POSIX \fBbc\fR language..SS NUMBERSThe most basic element in \fBbc\fR is the number.  Numbers arearbitrary precision numbers.  This precision is both in the integerpart and the fractional part.  All numbers are represented internallyin decimal and all computation is done in decimal.  (This versiontruncates results from divide and multiply operations.)  There are twoattributes of numbers, the length and the scale.  The length is thetotal number of significant decimal digits in a number and the scaleis the total number of decimal digits after the decimal point.  Forexample:.nf.RS .000001 has a length of 6 and scale of 6. 1935.000 has a length of 7 and a scale of 3..RE.fi.SS VARIABLESNumbers are stored in two types of variables, simple variables andarrays.  Both simple variables and array variables are named.  Namesbegin with a letter followed by any number of letters, digits andunderscores.  All letters must be lower case.  (Full alpha-numericnames are an extension. In POSIX \fBbc\fR all names are a singlelower case letter.)  The type of variable is clear by the contextbecause all array variable names will be followed by brackets ([])..PPThere are four special variables, \fBscale, ibase, obase,\fR and\fBlast\fR.  \fBscale\fR defines how some operations use digits after thedecimal point.  The default value of \fBscale\fR is 0. \fBibase\fRand \fBobase\fR define the conversion base for input and outputnumbers.  The default for both input and output is base 10.\fBlast\fR (an extension) is a variable that has the value of the lastprinted number.  These will be discussed in further detail whereappropriate.  All of these variables may have values assigned to themas well as used in expressions..SS COMMENTSComments in \fBbc\fR start with the characters \fB/*\fR and end withthe characters \fB*/\fR.  Comments may start anywhere and appear as asingle space in the input.  (This causes comments to delimit otherinput items.  For example, a comment can not be found in the middle ofa variable name.)  Comments include any newlines (end of line) betweenthe start and the end of the comment..SS EXPRESSIONSThe numbers are manipulated by expressions and statements.  Sincethe language was designed to be interactive, statements and expressionsare executed as soon as possible.  There is no "main" program.  Instead,code is executed as it is encountered.  (Functions, discussed indetail later, are defined when encountered.).PPA simple expression is just a constant. \fBbc\fR converts constantsinto internal decimal numbers using the current input base, specifiedby the variable \fBibase\fR. (There is an exception in functions.)The legal values of \fBibase\fR are 2 through 16 (F).  Assigning avalue outside this range to \fBibase\fR will result in a value of 2or 16.  Input numbers may contain the characters 0-9 and A-F. (Note:They must be capitals.  Lower case letters are variable names.)Single digit numbers always have the value of the digit regardless ofthe value of \fBibase\fR. (i.e. A = 10.)  For multi-digit numbers,\fBbc\fR changes all input digits greater or equal to ibase to thevalue of \fBibase\fR-1.  This makes the number \fBFFF\fR always bethe largest 3 digit number of the input base..PPFull expressions are similar to many other high level languages.Since there is only one kind of number, there are no rules for mixingtypes.  Instead, there are rules on the scale of expressions.  Everyexpression has a scale.  This is derived from the scale of originalnumbers, the operation performed and in many cases, the value of thevariable \fBscale\fR. Legal values of the variable \fBscale\fR are0 to the maximum number representable by a C integer..PPIn the following descriptions of legal expressions, "expr" refers to acomplete expression and "var" refers to a simple or an array variable.A simple variable is just a.RS\fIname\fR.REand an array variable is specified as.RS\fIname\fR[\fIexpr\fR].REUnless specificallymentioned the scale of the result is the maximum scale of theexpressions involved..IP "- expr"The result is the negation of the expression..IP "++ var"The variable is incremented by one and the new value is the result ofthe expression..IP "-- var"The variableis decremented by one and the new value is the result of theexpression..IP "var ++" The result of the expression is the value ofthe variable and then the variable is incremented by one..IP "var --"The result of the expression is the value of the variable and thenthe variable is decremented by one..IP "expr + expr"The result of the expression is the sum of the two expressions..IP "expr - expr"The result of the expression is the difference of the two expressions..IP "expr * expr"The result of the expression is the product of the two expressions..IP "expr / expr"The result of the expression is the quotient of the two expressions.The scale of the result is the value of the variable \fBscale\fR..IP "expr % expr"The result of the expression is the "remainder" and it is computed in thefollowing way.  To compute a%b, first a/b is computed to \fBscale\fRdigits.  That result is used to compute a-(a/b)*b to the scale of themaximum of \fBscale\fR+scale(b) and scale(a).  If \fBscale\fR is setto zero and both expressions are integers this expression is theinteger remainder function..IP "expr ^ expr"The result of the expression is the value of the first raised to thesecond. The second expression must be an integer.  (If the secondexpression is not an integer, a warning is generated and theexpression is truncated to get an integer value.)  The scale of theresult is \fBscale\fR if the exponent is negative.  If the exponentis positive the scale of the result is the minimum of the scale of thefirst expression times the value of the exponent and the maximum of\fBscale\fR and the scale of the first expression.  (e.g. scale(a^b)= min(scale(a)*b, max( \fBscale,\fR scale(a))).)  It should be notedthat expr^0 will always return the value of 1..IP "( expr )"This alters the standard precedence to force the evaluation of theexpression..IP "var = expr"The variable is assigned the value of the expression..IP "var <op>= expr"This is equivalent to "var = var <op> expr" with the exception thatthe "var" part is evaluated only once.  This can make a difference if"var" is an array..PP Relational expressions are a special kind of expressionthat always evaluate to 0 or 1, 0 if the relation is false and 1 ifthe relation is true.  These may appear in any legal expression.(POSIX bc requires that relational expressions are used only in if,while, and for statements and that only one relational test may bedone in them.)  The relational operators are.IP "expr1 < expr2"The result is 1 if expr1 is strictly less than expr2..IP "expr1 <= expr2"The result is 1 if expr1 is less than or equal to expr2..IP "expr1 > expr2"The result is 1 if expr1 is strictly greater than expr2..IP "expr1 >= expr2"The result is 1 if expr1 is greater than or equal to expr2..IP "expr1 == expr2"The result is 1 if expr1 is equal to expr2..IP "expr1 != expr2"The result is 1 if expr1 is not equal to expr2..PPBoolean operations are also legal.  (POSIX \fBbc\fR does NOT haveboolean operations). The result of all boolean operations are 0 and 1(for false and true) as in relational expressions.  The booleanoperators are:.IP "!expr"The result is 1 if expr is 0..IP "expr && expr"The result is 1 if both expressions are non-zero..IP "expr || expr"The result is 1 if either expression is non-zero..PPThe expression precedence is as follows: (lowest to highest).nf.RS|| operator, left associative&& operator, left associative! operator, nonassociativeRelational operators, left associativeAssignment operator, right associative+ and - operators, left associative*, / and % operators, left associative^ operator, right associativeunary - operator, nonassociative++ and -- operators, nonassociative.RE.fi.PPThis precedence was chosen so that POSIX compliant \fBbc\fR programswill run correctly. This will cause the use of the relational andlogical operators to have some unusual behavior when used withassignment expressions.  Consider the expression:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -