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

📄 bc

📁 UNIX v6源代码 这几乎是最经典的unix版本 unix操作系统设计和莱昂氏unix源代码分析都是用的该版
💻
📖 第 1 页 / 共 2 页
字号:
.RP.TLBC \- An Arbitrary Precision Desk-Calculator Language.AULorinda Cherry.AURobert Morris.AI.MH.ABBC is a language and a compiler for doing arbitrary precision arithmeticon the PDP-11 under the UNIX time-sharingsystem.  The output of the compiler is interpreted and executed bya collection of routines which can input, output, and doarithmetic on indefinitely large integers and on scaled fixed-pointnumbers..PPThese routines are themselves based on a dynamic storage allocator.Overflow does not occur until all available core storageis exhausted..PPThe language has a complete control structure as well as immediate-modeoperation.  Functions can be defined and saved for later execution..PPTwo five hundred-digit numbers can be multiplied to give athousand digit result in about ten seconds..PPA small collection of library functions is also available,including sin, cos, arctan, log, exponential, and Bessel functions ofinteger order..PPSome of the uses of this compiler are.IP \-to do computation with large integers,.IP \-to do computation accurate to many decimal places,.IP \-conversion of numbers from one base to another base..AE.PP.SHIntroduction.PPBC is a language and a compiler for doing arbitrary precisionarithmetic on the UNIX time-sharing system [1].The compiler was written to make conveniently available acollection of routines (called DC [6]) which are capable of doingarithmetic on integers of arbitrary size.  The compileris by no means intended to provide a complete programminglanguage.It is a minimal language facility..PPThere is a scaling provision that permits theuse of decimal point notation.Provision is made for input and output in bases other thandecimal.  Numbers can be converted from decimal to octal bysimply setting the output base to equal 8..PPThe actual limit on the number of digits that canbe handled depends on the amount of storage available on the machine.Manipulation of numbers with many hundreds of digitsis possible even on the smallest versions of UNIX..PPThe syntax of BC has been deliberately selected to agreesubstantially with the C language [2,3].  Those whoare familiar with C will find few surprises in this language..SHSimple Computations with Integers.PPThe simplest kind of statement is an arithmetic expressionon a line by itself.For instance, if you type in the line:.DS142857 + 285714.DEthe program responds immediately with the line.DS428571.DEThe operators \-, *, /, %, and ^ can also be used; theyindicate subtraction, multiplication, division, remaindering, andexponentiation, respectively.  Division of integers produces aninteger result truncated toward zero.Division by zero produces an errorcomment..PPAny term in an expression may be prefixed by a minus sign toindicate that it is to be negated (the `unary' minus sign).The expression.DS7+\-3.DEis interpreted to mean that \-3 is to be added to 7..PPMore complex expressions with several operators and withparentheses are interpreted just as inFortran, with ^ having the greatest bindingpower, then * and % and /, and finally + and \-.Contents of parentheses are evaluated before materialoutside the parentheses.Exponentiations areperformed from right to left and the other operatorsfrom left to right.The two expressions.DSa^b^c  and  a^(b^c).DEare equivalent, as are the two expressions.DSa*b*c  and  (a*b)*c.DEBC shares with Fortran and C the undesirable convention that.DSa/b*c  is equivalent to  (a/b)*c.DE.PPInternal storage registers to hold numbers have single lower-caseletter names.  The value of an expression can be assigned toa register in the usual way.  The statement.DSx = x + 3.DEhas the effect of increasing by three the value of the contents of theregister named x.When, as in this case, the outermost operator is an =, theassignment is performed but the result is not printed.Only 26 of these named storage registers are available..PPThere is a built-in square root function whoseresult is truncated to an integer (but see scaling below).The lines.DSx = sqrt(191)x.DEproduce the printed result.DS13.DE.SHBases.PPThere are special internal quantities, called `ibase' and `obase'.The contents of `ibase', initially set to 10,determines the base used for interpreting numbers read in.For example, the lines.DSibase = 811.DEwill produce the output line.DS9.DEand you are all set up to do octal to decimal conversions.Beware, however of trying to change the input base backto decimal by typing.DSibase = 10.DEBecause the number 10 is interpreted as octal, this statement willhave no effect.For those who deal in hexadecimal notation,the characters A\-F are permitted in numbers(no matter what base is in effect)and areinterpreted as digits having values 10\-15 respectively.The statement.DSibase = A.DEwill change you back to decimal input base no matter what thecurrent input base is.Negative and large positive input bases arepermitted but useless.No mechanism has been provided for the input of arbitrarynumbers in bases less than 1 and greater than 16..PPThe contents of `obase', initially set to 10, are used as the base for outputnumbers.  The lines.DSobase = 161000.DEwill produce the output line.DS3E8.DEwhich is to be interpreted as a 3-digit hexadecimal number.Very large output bases are permitted, and they are sometimes useful.For example, large numbers can be output in groups of five digitsby setting `obase' to 100000.Strange (i.e. 1, 0, or negative) output bases arehandled appropriately..PPVery large numbers are split across lines with 70 characters per line.Lines which are continued end with \\.Decimal output conversion is practically instantaneous, but outputof very large numbers (i.e., more than 100 digits) with other basesis rather slow.Non-decimal output conversion ofa one hundred digit number takes aboutthree seconds..PPIt is best to remember that `ibase' and `obase' have no effectwhatever on the course of internal computation oron the evaluation of expressions, but only affect input andoutput conversion, respectively..SHScaling.PPA third special internal quantity called `scale' isused to determine the scale of calculatedquantities.Numbers may haveup to 99 decimal digits after the decimal point.This fractional part is retained in further computations.We refer to the number of digits after the decimal point ofa number as its scale..PPWhen two scaled numbers are combined bymeans of one of the arithmetic operations, the resulthas a scale determined by the following rules.  Foraddition and subtraction, the scale of the result is the largerof the scales of the two operands.  In this case,there is never any truncation of the result.For multiplications, the scale of the result is neverless than the maximum of the two scales of the operands,never more than the sum of the scales of the operandsand, subject to those two restrictions,the scale of the result is set equal to the contents of the internalquantity `scale'.The scale of a quotient is the contents of the internalquantity `scale'.  The scale of a remainder isthe sum of the scales of the quotient and the divisor.The result of an exponentiation is scaled as ifthe implied multiplications were performed.An exponent must be an integer.The scale of a square root is set to the maximum of the scaleof the argument and the contents of `scale'..PPAll of the internal operations are actually carried out in termsof integers, with digits being discarded when necessary.In every case where digits are discarded, truncation andnot rounding is performed..PPThe contents of`scale' must be no greater than99 and no less than 0.  It is initially set to 0.In case you need more than 99 fraction digits, you may arrangeyour own scaling..PPThe internal quantities `scale', `ibase', and `obase' can beused in expressions just like other variables.The line.DSscale = scale + 1.DEincreases the value of `scale' by one, and the line.DSscale.DEcauses the current value of `scale' to be printed..PPThe value of `scale' retains its meaning as anumber of decimal digits to be retained in internalcomputation even when `ibase' or `obase' are not equal to 10.The internal computations (which are still conducted in decimal,regardless of the bases) are performed to the specified numberof decimal digits, never hexadecimal or octal or anyother kind of digits..SHFunctions.PPThe name of a function is a single lower-case letter.Function names are permitted to collide with simplevariable names.Twenty-six different defined functions are permittedin addition to the twenty-six variable names.The line.DS	define a(x){.DEbegins the definition of a function with one argument.This line must be followed by one or more statements,which make up the body of the function, endingwith a right brace }.Return of control from a function occurs when a returnstatement is executed or when the end of the function is reached.The return statement can take eitherof the two forms.DSreturnreturn(x).DEIn the first case, the value of the function is 0, and inthe second, the value of the expression in parentheses..PPVariables used in the function can be declared as automaticby a statement of the form.DSauto x,y,z.DEThere can be only one `auto' statement in a function and it mustbe the first statement in the definition.These automatic variables are allocated space and initializedto zero on entry to the function and thrown away on return.  Thevalues of any variables with the same names outside the function

⌨️ 快捷键说明

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