📄 bc.html
字号:
<td align=left>;<tr valign=top><td align=left>integer<td align=left>:<td align=center>digit<tr valign=top><td align=left><td align=left>|<td align=center>integer digit<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>digit<td align=left>:<td align=center>0 | 1 | 2 | 3 | 4 | 5 | 6 | 7<tr valign=top><td align=left><td align=left>|<td align=center>8 | 9 | A | B | C | D | E | F<tr valign=top><td align=left><td align=left>;</table></code></pre><p><li>The value of a<b>NUMBER</b>token is interpreted as a numeral in thebase specified by the value of the internal register<b>ibase</b>(described below).Each of the<b>digit</b>characters has the value from 0 to 15 in the order listed here, and theperiod character represents the radix point.The behaviour is undefined if digits greater than or equal to the value of<b>ibase</b>appear in the token.However, note the exception for single-digit values being assigned to<b>ibase</b>and<b>obase</b>themselves, in<xref href=bcops><a href="#tag_000_000_165_003">Operations in bc</a></xref>.<p><li>The following keywords are recognised as tokens:<pre><dl compact><dt> <dd><table <tr valign=top><th align=left>auto<th align=left>for<th align=left>length<th align=left>return<th align=left>sqrt<tr valign=top><td align=left>break<td align=left>ibase<td align=left>obase<td align=left>scale<td align=left>while<tr valign=top><td align=left>define<td align=left>if<td align=left>quit</table></dl></pre><p><li>Any of the following characters occurring anywhere except withina keyword are recognised as the token<b>LETTER</b>:<pre><code>a b c d e f g h i j k l m n o p q r s t u v w x y z</code></pre><p><li>The following single-character and two-character sequences arerecognised as the token<b>ASSIGN_OP</b>:<pre><code>= += -= *= /= %= ^=</code></pre><p><li>If an = character, as the beginning of a token, is followed bya - character with no intervening delimiter, the behaviour is undefined.<p><li>The following single-characters are recognised as the token<b>MUL_OP</b>:<pre><code>* / %</code></pre><p><li>The following single-character and two-character sequences arerecognised as the token<b>REL_OP</b>:<pre><code>== <= >= != < ></code></pre><p><li>The following two-character sequences are recognised as the token<b>INCR_DECR</b>:<pre><code>++ --</code></pre><p><li>The following single characters are recognised as tokens whosenames are the character:<pre><code><newline> ( ) , + - ; [ ] ^ { }</code></pre><p><li>The token<b>EOF</b>will be returned when the end of input is reached.<p></ol><h5><a name = "tag_000_000_165_003"> </a>Operations in bc</h5><xref type="5" name="bcops"></xref>There are three kinds of identifiers:ordinary identifiers, array identifiers and function identifiers.All three types consist of single lower-case letters.Array identifiers are followed by square brackets([ ]).An array subscript is required except in an argument orauto list.Arrays are singly dimensioned and can contain up to{BC_DIM_MAX}elements.Indexing begins at zero so an array is indexed from 0 to{BC_DIM_MAX}-1.Subscripts will be truncated to integers.Function identifiers must be followed by parentheses, possiblyenclosing arguments.The three types of identifiers do not conflict.<p>The following tablesummarises the rules for precedence and associativityof all operators.Operators on the same line have the sameprecedence; rows are in order of decreasing precedence.<pre><table bordercolor=#000000 border=1 align=center><tr valign=top><th align=center><b>Operator</b><th align=center><b>Associativity</b><tr valign=top><td align=left>++, --<td align=left>not applicable<tr valign=top><td align=left>unary -<td align=left>not applicable<tr valign=top><td align=left>^<td align=left>right to left<tr valign=top><td align=left>*, /, %<td align=left>left to right<tr valign=top><td align=left>+, binary -<td align=left>left to right<tr valign=top><td align=left>=, +=, -=, *=, /=, %=, ^=<td align=left>right to left<tr valign=top><td align=left>==, <=, >=, !=, <, ><td align=left>none</table></pre><h6 align=center><xref table="Operators in <I>bc</i>"></xref>Table: Operators in <i>bc</i></h6><p>Each expression or named expression has a<i>scale</i>,which is the number ofdecimal digits that are maintained as the fractional portion ofthe expression.<p><i>Named expressions</i>are places where values are stored.Named expressions are valid on the left side of an assignment.The valueof a named expression is the value stored in the place named.Simple identifiers and array elements are named expressions;they have an initial value of zero and an initial scale of zero.<p>The internal registers <b>scale</b>, <b>ibase</b>and<b>obase</b>are all named expressions.The scale of an expression consisting of the name of one ofthese registers is zero; values assigned to any of theseregisters will be truncated to integers.The<b>scale</b>register contains a global value used in computing the scale ofexpressions (as described below).The value of the register<b>scale</b>is limited to0 <=<b>scale</b><={BC_SCALE_MAX}and has a default value of zero.The<b>ibase</b>and<b>obase</b>registers are the input and output number radix, respectively.The value of<b>ibase</b>is limited to:<pre><code>2 <= ibase <= 16</code></pre>The value of<b>obase</b>is limited to:<pre><code>2 <= obase <= {BC_BASE_MAX}</code></pre>When either<b>ibase</b>or<b>obase</b>is assigned a single<b>digit</b>value from the list in<xref href=bclex><a href="#tag_000_000_165_002">Lexical Conventions in bc</a></xref>,the value is assumed in hexadecimal.(For example,ibase=Asets to base ten, regardless of the current<b>ibase</b>value.)Otherwise, the behaviour is undefined when digits greater than or equal tothe value of<b>ibase</b>appear in the input.Both<b>ibase</b>and<b>obase</b>have initial values of 10.<p>Internal computations will be conducted as if in decimal, regardlessof the input and output bases, to the specified number of decimal digits.When an exact result is not achieved, (for example,scale=0; 3.2/1)the result will be truncated.<p>For all values of<b>obase</b>specified by this specification,numerical values will be output as follows:<ol><p><li>If the value is less than zero, a hyphen(-)character will be output.<p><li>One of the following will be output, dependingon the numerical value:<ul><p><li>If the absolute value of the numerical value isgreater than or equal to one, the integer portion ofthe value will be output as a series of digits appropriate to<b>obase</b>(as described below).The most significant non-zero digit will be output next, followedby each successively less significant digit.<p><li>If the absolute value of the numerical value is lessthan one but greater than zero and the scale of thenumerical value is greater than zero, it is unspecifiedwhether the character 0 is output.<p><li>If the numerical value is zero, the character 0 will be output.<p></ul><p><li>If the scale of the value is greater thanzero, a period character will be output, followed by aseries of digits appropriate to<b>obase</b>(as described below) representing the most significantportion of the fractional part of the value.If<i>s</i>represents the scale of the value being output, thenumber of digits output will be<i>s</i>if<b>obase</b>is 10, less than or equal to<i>s</i>if<b>obase</b>is greater than 10, or greater than or equal to<i>s</i>if<b>obase</b>is less than 10.For<b>obase</b>values other than 10, this should be the number of digits needed to representa precision of 10<sup><small><i>s</i></small></sup>.<p></ol><p>For<b>obase</b>values from 2 to 16, valid digits are the first<b>obase</b>of the single characters:<pre><code>0 1 2 3 4 5 6 7 8 9 A B C D E F</code></pre>which represent the values zero to 15, inclusive, respectively.<p>For bases greater than 16, each digit is written as a separatemulti-digit decimal number.Each digit except the mostsignificant fractional digit will be preceded a singlespacecharacter.For bases from 17 to 100,<i>bc</i>will write two-digit decimal numbers;for bases from 101 to1000, three-digit decimal strings and so on.For example, the decimal number 1024 in base 25 would be written as:<pre><code> <img src="../images/delta.gif" border=0>01<img src="../images/delta.gif" border=0>15<img src="../images/delta.gif" border=0>24</code></pre>in base 125, as:<pre><code> <img src="../images/delta.gif" border=0">008<img src="../images/delta.gif" border=0">024</code></pre><p>Very large numbers will be split across lines with 70characters per line in the POSIX locale;other locales may split at different character boundaries.Lines that are continued must end with a backslash(\).<p>A function call consists of a function name followed by parenthesescontaining a comma-separated list of expressions, which are thefunction arguments.A whole array passed as an argument is specifiedby the array name followed by empty square brackets.All functionarguments are passed by value.As a result, changes made to theformal parameters have no effect on the actual arguments.If thefunction terminates by executing a<b>return</b>statement, the value of thefunction will be the value of the expression in the parentheses of the<b>return</b>statement or will be zero if no expression is provided or if thereis no<b>return</b>statement.<p>The result of<b>sqrt</b>(<i>expression</i>) will be the square root of the expression.The result will be truncated in the least significant decimal place.The scale of the result will be the scale of the expression or the value of<b>scale</b>,whichever is larger.<p>The result of<b>length</b>(<i>expression</i>)will be the total number of significant decimaldigits in the expression.The scale of the result will be zero.<p>The result of<b>scale</b>(<i>expression</i>) will be the scale of the expression.The scale of the result will be zero.<p>A numeric constant will be an expression.The scale will be the number ofdigits that follow the radix point in the input representing theconstant, or zero if no radix point appears.<p>The sequence<b>(</b> <i>expression</i> <b>)</b>will be an expression with the same value and scale as<i>expression</i>.The parentheses can be used to alter the normal precedence.<p>The semantics of the unary and binary operators are as follows:<dl compact><dt>-<i>expression</i><dd>The result will be the negative of the <i>expression</i>.The scale of the result will be the scale of<i>expression</i>.</dl><p>The unary increment and decrement operators will not modify thescale of the named expression upon which they operate.The scale of the result will be the scale of that named expression.<dl compact><dt>++<i>named-expression</i><dd>The named expression will be incremented by one.The result will bethe value of the named expression after incrementing.<dt>--<i>named-expression</i><dd>The named expression will be decremented by one.The result will bethe value of the named expression after decrementing.<dt><i>named-expression</i>++<dd>The named expression will be incremented by one.The result will bethe value of the named expression before incrementing.<dt><i>named-expression</i>--<dd>The named expression will be decremented by one.The result will bethe value of the named expression before decrementing.</dl><p>The exponentiation operator, circumflex(^),binds right to left.<dl compact><dt><i>expression</i>^<i>expression</i><dd>The result will be the first<i>expression</i>raised to the powerof the second <i>expression</i>.If the second expression is not an integer, the behaviour is undefined.Ifais the scale of the left expression andbis the absolute value of the right expression,the scale of the result will be:<pre><code>if b >= 0 min(a * b, max(scale, a))if b < 0 scale</code></pre></dl>The multiplicative operators ("*", "/", "%")bind left to right.<dl compact><dt><i>expression</i> * <i>expression</i><dd>The result will be the product of the two expressions.Ifaandbare the scales of the two expressions, then the scale ofthe result will be:<pre><code>min(a+b,max(scale,a,b))</code></pre><dt><i>expression</i> / <i>expression</i><dd>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -