📄 bc.html
字号:
<li><p>It shall be interpreted as the character sequence <tt>"\<newline>"</tt> in <b>STRING</b> tokens.</p></li><li><p>It shall be ignored as part of a multi-line <b>NUMBER</b> token.</p></li></ul></li><li><p>The token <b>NUMBER</b> shall represent a numeric constant. It shall be recognized by the following grammar:</p><pre><tt>NUMBER : integer | '.' integer | integer '.' | integer '.' integer ;<br>integer : digit | integer digit ;<br>digit : 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F ;</tt></pre></li><li><p>The value of a <b>NUMBER</b> token shall be interpreted as a numeral in the base specified by the value of the internal register<b>ibase</b> (described below). Each of the <b>digit</b> characters shall have the value from 0 to 15 in the order listed here, andthe period character shall represent the radix point. The behavior 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 <a href="#tag_04_09_13_03">Operations in bc</a> .</p></li><li><p>The following keywords shall be recognized as tokens:</p><blockquote><table cellpadding="3"><tr valign="top"><td align="left"><p class="tent"><b><br>auto<br> break<br> define<br></b></p></td><td align="left"><p class="tent"><b><br>ibase<br> if<br> for<br></b></p></td><td align="left"><p class="tent"><b><br>length<br> obase<br> quit<br></b></p></td><td align="left"><p class="tent"><b><br>return<br> scale<br> sqrt<br></b></p></td><td align="left"><p class="tent"><b><br>while<br></b></p></td></tr></table></blockquote></li><li><p>Any of the following characters occurring anywhere except within a keyword shall be recognized as the token <b>LETTER</b>:</p><pre><tt>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</tt></pre></li><li><p>The following single-character and two-character sequences shall be recognized as the token <b>ASSIGN_OP</b>:</p><pre><tt>= += -= *= /= %= ^=</tt></pre></li><li><p>If an <tt>'='</tt> character, as the beginning of a token, is followed by a <tt>'-'</tt> character with no interveningdelimiter, the behavior is undefined.</p></li><li><p>The following single-characters shall be recognized as the token <b>MUL_OP</b>:</p><pre><tt>* / %</tt></pre></li><li><p>The following single-character and two-character sequences shall be recognized as the token <b>REL_OP</b>:</p><pre><tt>== <= >= != < ></tt></pre></li><li><p>The following two-character sequences shall be recognized as the token <b>INCR_DECR</b>:</p><pre><tt>++ --</tt></pre></li><li><p>The following single characters shall be recognized as tokens whose names are the character:</p><pre><tt><newline> ( ) , + - ; [ ] ^ { }</tt></pre></li><li><p>The token <b>EOF</b> is returned when the end of input is reached.</p></li></ol><h5><a name="tag_04_09_13_03"></a>Operations in bc</h5><p>There are three kinds of identifiers: ordinary identifiers, array identifiers, and function identifiers. All three types consistof single lowercase letters. Array identifiers shall be followed by square brackets ( <tt>"[]"</tt> ). An array subscript isrequired except in an argument or auto list. Arrays are singly dimensioned and can contain up to {BC_DIM_MAX} elements. Indexingshall begin at zero so an array is indexed from 0 to {BC_DIM_MAX}-1. Subscripts shall be truncated to integers. The applicationshall ensure that function identifiers are followed by parentheses, possibly enclosing arguments. The three types of identifiers donot conflict.</p><p>The following table summarizes the rules for precedence and associativity of all operators. Operators on the same line shallhave the same precedence; rows are in order of decreasing precedence.</p><center><b>Table: Operators in <i>bc</i></b></center><center><table border="1" cellpadding="3" align="center"><tr valign="top"><th align="center"><p class="tent"><b>Operator</b></p></th><th align="center"><p class="tent"><b>Associativity</b></p></th></tr><tr valign="top"><td align="left"><p class="tent">++, --</p></td><td align="left"><p class="tent">N/A</p></td></tr><tr valign="top"><td align="left"><p class="tent">unary -</p></td><td align="left"><p class="tent">N/A</p></td></tr><tr valign="top"><td align="left"><p class="tent">^</p></td><td align="left"><p class="tent">Right to left</p></td></tr><tr valign="top"><td align="left"><p class="tent">*, /, %</p></td><td align="left"><p class="tent">Left to right</p></td></tr><tr valign="top"><td align="left"><p class="tent">+, binary -</p></td><td align="left"><p class="tent">Left to right</p></td></tr><tr valign="top"><td align="left"><p class="tent">=, +=, -=, *=, /=, %=, ^=</p></td><td align="left"><p class="tent">Right to left</p></td></tr><tr valign="top"><td align="left"><p class="tent">==, <=, >=, !=, <, ></p></td><td align="left"><p class="tent">None</p></td></tr></table></center><p>Each expression or named expression has a <i>scale</i>, which is the number of decimal digits that shall be maintained as thefractional portion of the expression.</p><p><i>Named expressions</i> are places where values are stored. Named expressions shall be valid on the left side of an assignment.The value of a named expression shall be the value stored in the place named. Simple identifiers and array elements are namedexpressions; they have an initial value of zero and an initial scale of zero.</p><p>The internal registers <b>scale</b>, <b>ibase</b>, and <b>obase</b> are all named expressions. The scale of an expressionconsisting of the name of one of these registers shall be zero; values assigned to any of these registers are truncated tointegers. The <b>scale</b> register shall contain a global value used in computing the scale of expressions (as described below).The value of the register <b>scale</b> is limited to 0 <= <b>scale</b> <= {BC_SCALE_MAX} and shall have a default value ofzero. The <b>ibase</b> and <b>obase</b> registers are the input and output number radix, respectively. The value of <b>ibase</b>shall be limited to:</p><pre><tt>2 <= ibase <= 16</tt></pre><p>The value of <b>obase</b> shall be limited to:</p><pre><tt>2 <= obase <= {BC_BASE_MAX}</tt></pre><p>When either <b>ibase</b> or <b>obase</b> is assigned a single <b>digit</b> value from the list in <a href="#tag_04_09_13_02">Lexical Conventions in bc</a> , the value shall be assumed in hexadecimal. (For example, <b>ibase</b>=A sets tobase ten, regardless of the current <b>ibase</b> value.) Otherwise, the behavior 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> shall have initial values of 10.</p><p>Internal computations shall be conducted as if in decimal, regardless of the input and output bases, to the specified number ofdecimal digits. When an exact result is not achieved (for example, <b>scale</b>=0; 3.2/1)<b>,</b> the result shall betruncated.</p><p>For all values of <b>obase</b> specified by this volume of IEEE Std 1003.1-2001, <i>bc</i> shall output numeric valuesby performing each of the following steps in order:</p><ol><li><p>If the value is less than zero, a hyphen ( <tt>'-'</tt> ) character shall be output.</p></li><li><p>One of the following is output, depending on the numerical value:</p><ul><li><p>If the absolute value of the numerical value is greater than or equal to one, the integer portion of the value shall be outputas a series of digits appropriate to <b>obase</b> (as described below), most significant digit first. The most significant non-zerodigit shall be output next, followed by each successively less significant digit.</p></li><li><p>If the absolute value of the numerical value is less than one but greater than zero and the scale of the numerical value isgreater than zero, it is unspecified whether the character 0 is output.</p></li><li><p>If the numerical value is zero, the character 0 shall be output.</p></li></ul></li><li><p>If the scale of the value is greater than zero and the numeric value is not zero, a period character shall be output, followedby a series of digits appropriate to <b>obase</b> (as described below) representing the most significant portion of the fractionalpart of the value. If <i>s</i> represents the scale of the value being output, the number of digits output shall 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 represent aprecision of 10<sup><small><i>s</i></small></sup>.</p></li></ol><p>For <b>obase</b> values from 2 to 16, valid digits are the first <b>obase</b> of the single characters:</p><pre><tt>0 1 2 3 4 5 6 7 8 9 A B C D E F</tt></pre>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -