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

📄 bc.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<p>which represent the values zero to 15, inclusive, respectively.</p><p>For bases greater than 16, each digit shall be written as a separate multi-digit decimal number. Each digit except the mostsignificant fractional digit shall be preceded by a single &lt;space&gt;. For bases from 17 to 100, <i>bc</i> shall write two-digitdecimal numbers; for bases from 101 to 1000, three-digit decimal strings, and so on. For example, the decimal number 1024 in base25 would be written as:</p><pre><tt><img src="../images/delta.gif" border="0">01<img src="../images/delta.gif" border="0">15<img src="../images/delta.gif" border="0">24</tt></pre><p>and in base 125, as:</p><pre><tt><img src="../images/delta.gif" border="0">008<img src="../images/delta.gif" border="0">024</tt></pre><p>Very large numbers shall be split across lines with 70 characters per line in the POSIX locale; other locales may split atdifferent character boundaries. Lines that are continued shall end with a backslash ( <tt>'\'</tt> ).</p><p>A function call shall consist of a function name followed by parentheses containing a comma-separated list of expressions, whichare the function arguments. A whole array passed as an argument shall be specified by the array name followed by empty squarebrackets. All function arguments shall be passed by value. As a result, changes made to the formal parameters shall have no effecton the actual arguments. If the function terminates by executing a <b>return</b> statement, the value of the function shall be thevalue of the expression in the parentheses of the <b>return</b> statement or shall be zero if no expression is provided or if thereis no <b>return</b> statement.</p><p>The result of <b>sqrt</b>( <i>expression</i>) shall be the square root of the expression. The result shall be truncated in theleast significant decimal place. The scale of the result shall be the scale of the expression or the value of <b>scale</b>,whichever is larger.</p><p>The result of <b>length</b>( <i>expression</i>) shall be the total number of significant decimal digits in the expression. Thescale of the result shall be zero.</p><p>The result of <b>scale</b>( <i>expression</i>) shall be the scale of the expression. The scale of the result shall be zero.</p><p>A numeric constant shall be an expression. The scale shall be the number of digits that follow the radix point in the inputrepresenting the constant, or zero if no radix point appears.</p><p>The sequence (&nbsp;<i>expression</i>&nbsp;) shall be an expression with the same value and scale as <i>expression</i>. Theparentheses can be used to alter the normal precedence.</p><p>The semantics of the unary and binary operators are as follows:</p><dl compact><dt>-<i>expression</i></dt><dd><br>The result shall be the negative of the <i>expression</i>. The scale of the result shall be the scale of <i>expression</i>.</dd></dl><p>The unary increment and decrement operators shall not modify the scale of the named expression upon which they operate. Thescale of the result shall be the scale of that named expression.</p><dl compact><dt>++<i>named-expression</i></dt><dd><br>The named expression shall be incremented by one. The result shall be the value of the named expression after incrementing.</dd><dt>--<i>named-expression</i></dt><dd><br>The named expression shall be decremented by one. The result shall be the value of the named expression after decrementing.</dd><dt><i>named-expression</i>++</dt><dd><br>The named expression shall be incremented by one. The result shall be the value of the named expression before incrementing.</dd><dt><i>named-expression</i>--</dt><dd><br>The named expression shall be decremented by one. The result shall be the value of the named expression before decrementing.</dd></dl><p>The exponentiation operator, circumflex ( <tt>'^'</tt> ), shall bind right to left.</p><dl compact><dt><i>expression</i>^<i>expression</i></dt><dd><br>The result shall be the first <i>expression</i> raised to the power of the second <i>expression</i>. If the second expression isnot an integer, the behavior is undefined. If <i>a</i> is the scale of the left expression and <i>b</i> is the absolute value ofthe right expression, the scale of the result shall be: <pre><tt>if b &gt;= 0 min(a * b, max(scale, a)) if b &lt; 0 scale</tt></pre></dd></dl>The multiplicative operators ( <tt>'*'</tt> , <tt>'/'</tt> , <tt>'%'</tt> ) shall bind left to right. <dl compact><dt><i>expression</i>*<i>expression</i></dt><dd><br>The result shall be the product of the two expressions. If <i>a</i> and <i>b</i> are the scales of the two expressions, then thescale of the result shall be: <pre><tt>min(a+b,max(scale,a,b))</tt></pre></dd><dt><i>expression</i>/<i>expression</i></dt><dd><br>The result shall be the quotient of the two expressions. The scale of the result shall be the value of <b>scale</b>.</dd><dt><i>expression</i>%<i>expression</i></dt><dd><br>For expressions <i>a</i> and <i>b</i>, <i>a</i>% <i>b</i> shall be evaluated equivalent to the steps: <ol><li><p>Compute <i>a</i>/ <i>b</i> to current scale.</p></li><li><p>Use the result to compute:</p><pre><tt>a - (a / b) * b</tt></pre><p>to scale:</p><pre><tt>max(scale + scale(b), scale(a))</tt></pre></li></ol>The scale of the result shall be: <pre><tt>max(scale + scale(b), scale(a))</tt></pre><p>When <b>scale</b> is zero, the <tt>'%'</tt> operator is the mathematical remainder operator.</p></dd></dl><p>The additive operators ( <tt>'+'</tt> , <tt>'-'</tt> ) shall bind left to right.</p><dl compact><dt><i>expression</i>+<i>expression</i></dt><dd><br>The result shall be the sum of the two expressions. The scale of the result shall be the maximum of the scales of theexpressions.</dd><dt><i>expression</i>-<i>expression</i></dt><dd><br>The result shall be the difference of the two expressions. The scale of the result shall be the maximum of the scales of theexpressions.</dd></dl><p>The assignment operators ( <tt>'='</tt> , <tt>"+="</tt> , <tt>"-="</tt> , <tt>"*="</tt> , <tt>"/="</tt> , <tt>"%="</tt> ,<tt>"^="</tt> ) shall bind right to left.</p><dl compact><dt><i>named-expression</i>=<i>expression</i></dt><dd><br>This expression shall result in assigning the value of the expression on the right to the named expression on the left. The scaleof both the named expression and the result shall be the scale of <i>expression</i>.</dd></dl><p>The compound assignment forms:</p><pre><i>named-expression</i> <tt>&lt;</tt><i>operator</i><tt>&gt;=</tt> <i>expression</i></pre><p>shall be equivalent to:</p><pre><i>named-expression</i><tt>=</tt><i>named-expression</i> <tt>&lt;</tt><i>operator</i><tt>&gt;</tt> <i>expression</i></pre><p>except that the <i>named-expression</i> shall be evaluated only once.</p><p>Unlike all other operators, the relational operators ( <tt>'&lt;'</tt> , <tt>'&gt;'</tt> , <tt>"&lt;="</tt> , <tt>"&gt;="</tt> ,<tt>"=="</tt> , <tt>"!="</tt> ) shall be only valid as the object of an <b>if</b>, <b>while</b>, or inside a <b>for</b>statement.</p><dl compact><dt><i>expression1</i>&lt;<i>expression2</i></dt><dd><br>The relation shall be true if the value of <i>expression1</i> is strictly less than the value of <i>expression2</i>.</dd><dt><i>expression1</i>&gt;<i>expression2</i></dt><dd><br>The relation shall be true if the value of <i>expression1</i> is strictly greater than the value of <i>expression2</i>.</dd><dt><i>expression1</i>&lt;=<i>expression2</i></dt><dd><br>The relation shall be true if the value of <i>expression1</i> is less than or equal to the value of <i>expression2</i>.</dd><dt><i>expression1</i>&gt;=<i>expression2</i></dt><dd><br>The relation shall be true if the value of <i>expression1</i> is greater than or equal to the value of <i>expression2</i>.</dd><dt><i>expression1</i>==<i>expression2</i></dt><dd><br>The relation shall be true if the values of <i>expression1</i> and <i>expression2</i> are equal.</dd><dt><i>expression1</i>!=<i>expression2</i></dt><dd><br>The relation shall be true if the values of <i>expression1</i> and <i>expression2</i> are unequal.</dd></dl><p>There are only two storage classes in <i>bc</i>: global and automatic (local). Only identifiers that are local to a functionneed be declared with the <b>auto</b> command. The arguments to a function shall be local to the function. All other identifiersare assumed to be global and available to all functions. All identifiers, global and local, have initial values of zero.Identifiers declared as auto shall be allocated on entry to the function and released on returning from the function. Theytherefore do not retain values between function calls. Auto arrays shall be specified by the array name followed by empty squarebrackets. On entry to a function, the old values of the names that appear as parameters and as automatic variables shall be pushedonto a stack. Until the function returns, reference to these names shall refer only to the new values.</p><p>References to any of these names from other functions that are called from this function also refer to the new value until oneof those functions uses the same name for a local variable.</p><p>When a statement is an expression, unless the main operator is an assignment, execution of the statement shall write the valueof the expression followed by a &lt;newline&gt;.</p><p>When a statement is a string, execution of the statement shall write the value of the string.</p><p>Statements separated by semicolons or &lt;newline&gt;s shall be executed sequentially. In an interactive invocation of<i>bc</i>, each time a &lt;newline&gt; is read that satisfies the grammatical production:</p><pre><tt>input_item : semicolon_list NEWLINE</tt></pre><p>the sequential list of statements making up the <b>semicolon_list</b> shall be executed immediately and any output produced bythat execution shall be written without any delay due to buffering.</p><p>In an <b>if</b> statement ( <b>if</b>( <i>relation</i>) <i>statement</i>), the <i>statement</i> shall be executed if therelation is true.</p><p>The <b>while</b> statement ( <b>while</b>( <i>relation</i>) <i>statement</i>) implements a loop in which the <i>relation</i> istested; each time the <i>relation</i> is true, the <i>statement</i> shall be executed and the <i>relation</i> retested. When the<i>relation</i> is false, execution shall resume after <i>statement</i>.</p><p>A <b>for</b> statement( <b>for</b>( <i>expression</i>; <i>relation</i>; <i>expression</i>) <i>statement</i>) shall be the sameas:</p><pre><i>first-expression</i><tt>while (</tt><i>relation</i><tt>) {   </tt> <i>statement</i> <tt>  </tt> <i>last-expression</i><tt>}</tt></pre>The application shall ensure that all three expressions are present. <p>The <b>break</b> statement shall cause termination of a <b>for</b> or <b>while</b> statement.</p><p>The <b>auto</b> statement ( <b>auto</b> <i>identifier</i> <b>[</b>, <i>identifier</i> <b>]</b> ...) shall cause the values ofthe identifiers to be pushed down. The identifiers can be ordinary identifiers or array identifiers. Array identifiers shall bespecified by following the array name by empty square brackets. The application shall ensure that the <b>auto</b> statement is thefirst statement in a function definition.</p><p>A <b>define</b> statement:</p><pre><tt>define</tt> <i>LETTER</i> <tt>(</tt> <i>opt_parameter_list</i> <tt>) {   </tt> <i>opt_auto_define_list</i> <tt>  </tt> <i>statement_list</i><tt>}</tt></pre><p>defines a function named <b>LETTER</b>. If a function named <b>LETTER</b> was previously defined, the <b>define</b> statementshall replace the previous definition. The expression:</p><pre><tt>LETTER (</tt> <i>opt_argument_list</i> <tt>)</tt></pre><p>shall invoke the function named <b>LETTER</b>. The behavior is undefined if the number of arguments in the invocation does notmatch the number of parameters in the definition. Functions shall be defined before they are invoked. A function shall beconsidered to be defined within its own body, so recursive calls are valid. The values of numeric constants within a function shallbe interpreted in the base specified by the value of the <b>ibase</b> register when the function is invoked.</p><p>The <b>return</b> statements ( <b>return</b> and <b>return</b>( <i>expression</i>)) shall cause termination of a function,popping of its auto variables, and specification of the result of the function. The first form shall be equivalent to<b>return</b>(0). The value and scale of the result returned by the function shall be the value and scale of the expressionreturned.</p><p>The <b>quit</b> statement ( <b>quit</b>) shall stop execution of a <i>bc</i> program at the point where the statement occurs inthe input, even if it occurs in a function definition, or in an <b>if</b>, <b>for</b>, or <b>while</b> statement.</p><p>The following functions shall be defined when the <b>-l</b> option is specified:</p><dl compact><dt><b>s</b>(&nbsp;<i>expression</i>&nbsp;)</dt><dd><br>

⌨️ 快捷键说明

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