isposix

Un outil pour savoir si une commande est posix - retour accueil

git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |

bc.html (50768B)


      1 <!-- Copyright 2001-2024 IEEE and The Open Group, All Rights Reserved -->
      2 <!DOCTYPE HTML>
      3 <html lang="en">
      4 <head>
      5 <meta name="generator" content="HTML Tidy for HTML5 for Linux version 5.8.0">
      6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      7 <link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group rhtm tool v1.2.4 -->
      8 <!-- Copyright (c) 2001-2024 The Open Group, All Rights Reserved -->
      9 <title>bc</title>
     10 </head>
     11 <body bgcolor="white">
     12 <div class="NAVHEADER">
     13 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0">
     14 <tr class="nav">
     15 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/batch.html" accesskey="P">&lt;&lt;&lt;
     16 Previous</a></td>
     17 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td>
     18 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/bg.html" accesskey="N">Next &gt;&gt;&gt;</a></td>
     19 </tr>
     20 </table>
     21 <hr align="left" width="100%"></div>
     22 <script language="JavaScript" src="../jscript/codes.js"></script><basefont size="3">
     23 <center><font size="2">The Open Group Base Specifications Issue 8<br>
     24 IEEE Std 1003.1-2024<br>
     25 Copyright © 2001-2024 The IEEE and The Open Group</font></center>
     26 <hr size="2" noshade>
     27 <a name="top" id="top"></a> <a name="bc" id="bc"></a> <a name="tag_20_09" id="tag_20_09"></a><!-- bc -->
     28 <h4 class="mansect"><a name="tag_20_09_01" id="tag_20_09_01"></a>NAME</h4>
     29 <blockquote>bc — arbitrary-precision arithmetic language</blockquote>
     30 <h4 class="mansect"><a name="tag_20_09_02" id="tag_20_09_02"></a>SYNOPSIS</h4>
     31 <blockquote class="synopsis">
     32 <p><code><tt>bc</tt> <b>[</b><tt>-l</tt><b>] [</b><i>file</i><tt>...</tt><b>]</b></code></p>
     33 </blockquote>
     34 <h4 class="mansect"><a name="tag_20_09_03" id="tag_20_09_03"></a>DESCRIPTION</h4>
     35 <blockquote>
     36 <p>The <i>bc</i> utility shall implement an arbitrary precision calculator. It shall take input from any files given, then read
     37 from the standard input. If the standard input and standard output to <i>bc</i> are attached to a terminal, the invocation of
     38 <i>bc</i> shall be considered to be <i>interactive</i>, causing behavioral constraints described in the following sections.</p>
     39 </blockquote>
     40 <h4 class="mansect"><a name="tag_20_09_04" id="tag_20_09_04"></a>OPTIONS</h4>
     41 <blockquote>
     42 <p>The <i>bc</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax
     43 Guidelines</i></a> .</p>
     44 <p>The following option shall be supported:</p>
     45 <dl compact>
     46 <dd></dd>
     47 <dt><b>-l</b></dt>
     48 <dd>(The letter ell.) Define the math functions and initialize <i>scale</i> to 20, instead of the default zero; see the EXTENDED
     49 DESCRIPTION section.</dd>
     50 </dl>
     51 </blockquote>
     52 <h4 class="mansect"><a name="tag_20_09_05" id="tag_20_09_05"></a>OPERANDS</h4>
     53 <blockquote>
     54 <p>The following operand shall be supported:</p>
     55 <dl compact>
     56 <dd></dd>
     57 <dt><i>file</i></dt>
     58 <dd>A pathname of a text file containing <i>bc</i> program statements. After all <i>file</i>s have been read, <i>bc</i> shall read
     59 the standard input.</dd>
     60 </dl>
     61 </blockquote>
     62 <h4 class="mansect"><a name="tag_20_09_06" id="tag_20_09_06"></a>STDIN</h4>
     63 <blockquote>
     64 <p>See the INPUT FILES section.</p>
     65 </blockquote>
     66 <h4 class="mansect"><a name="tag_20_09_07" id="tag_20_09_07"></a>INPUT FILES</h4>
     67 <blockquote>
     68 <p>Input files shall be text files containing a sequence of comments, statements, and function definitions that shall be executed
     69 as they are read.</p>
     70 </blockquote>
     71 <h4 class="mansect"><a name="tag_20_09_08" id="tag_20_09_08"></a>ENVIRONMENT VARIABLES</h4>
     72 <blockquote>
     73 <p>The following environment variables shall affect the execution of <i>bc</i>:</p>
     74 <dl compact>
     75 <dd></dd>
     76 <dt><i>LANG</i></dt>
     77 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href=
     78 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization
     79 variables used to determine the values of locale categories.)</dd>
     80 <dt><i>LC_ALL</i></dt>
     81 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
     82 <dt><i>LC_CTYPE</i></dt>
     83 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
     84 opposed to multi-byte characters in arguments and input files).</dd>
     85 <dt><i>LC_MESSAGES</i></dt>
     86 <dd><br>
     87 Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.</dd>
     88 <dt><i>NLSPATH</i></dt>
     89 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
     90 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border=
     91 "0"></dd>
     92 </dl>
     93 </blockquote>
     94 <h4 class="mansect"><a name="tag_20_09_09" id="tag_20_09_09"></a>ASYNCHRONOUS EVENTS</h4>
     95 <blockquote>
     96 <p>Default.</p>
     97 </blockquote>
     98 <h4 class="mansect"><a name="tag_20_09_10" id="tag_20_09_10"></a>STDOUT</h4>
     99 <blockquote>
    100 <p>The output of the <i>bc</i> utility shall be controlled by the program read, and consist of zero or more lines containing the
    101 value of all executed expressions without assignments. The radix and precision of the output shall be controlled by the values of
    102 the <b>obase</b> and <b>scale</b> variables; see the EXTENDED DESCRIPTION section.</p>
    103 </blockquote>
    104 <h4 class="mansect"><a name="tag_20_09_11" id="tag_20_09_11"></a>STDERR</h4>
    105 <blockquote>
    106 <p>The standard error shall be used only for diagnostic messages.</p>
    107 </blockquote>
    108 <h4 class="mansect"><a name="tag_20_09_12" id="tag_20_09_12"></a>OUTPUT FILES</h4>
    109 <blockquote>
    110 <p>None.</p>
    111 </blockquote>
    112 <h4 class="mansect"><a name="tag_20_09_13" id="tag_20_09_13"></a>EXTENDED DESCRIPTION</h4>
    113 <blockquote>
    114 <h5><a name="tag_20_09_13_01" id="tag_20_09_13_01"></a>Grammar</h5>
    115 <p>The grammar in this section and the lexical conventions in the following section shall together describe the syntax for
    116 <i>bc</i> programs. The general conventions for this style of grammar are described in <a href=
    117 "../utilities/V3_chap01.html#tag_18_03"><i>1.3 Grammar Conventions</i></a> . A valid program can be represented as the non-terminal
    118 symbol <b>program</b> in the grammar. This formal syntax shall take precedence over the text syntax description.</p>
    119 <pre>
    120 <tt>%token    EOF NEWLINE STRING LETTER NUMBER
    121 <br>
    122 %token    MUL_OP
    123 /*        '*', '/', '%'                           */
    124 <br>
    125 %token    ASSIGN_OP
    126 /*        '=', '+=', '-=', '*=', '/=', '%=', '^=' */
    127 <br>
    128 %token    REL_OP
    129 /*        '==', '&lt;=', '&gt;=', '!=', '&lt;', '&gt;'        */
    130 <br>
    131 %token    INCR_DECR
    132 /*        '++', '--'                              */
    133 <br>
    134 %token    Define    Break    Quit    Length
    135 /*        'define', 'break', 'quit', 'length'     */
    136 <br>
    137 %token    Return    For    If    While    Sqrt
    138 /*        'return', 'for', 'if', 'while', 'sqrt'  */
    139 <br>
    140 %token    Scale    Ibase    Obase    Auto
    141 /*        'scale', 'ibase', 'obase', 'auto'       */
    142 <br>
    143 %start    program
    144 <br>
    145 %%
    146 <br>
    147 program              : EOF
    148                      | input_item program
    149                      ;
    150 <br>
    151 input_item           : semicolon_list NEWLINE
    152                      | function
    153                      ;
    154 <br>
    155 semicolon_list       : /* empty */
    156                      | statement
    157                      | semicolon_list ';' statement
    158                      | semicolon_list ';'
    159                      ;
    160 <br>
    161 statement_list       : /* empty */
    162                      | statement
    163                      | statement_list NEWLINE
    164                      | statement_list NEWLINE statement
    165                      | statement_list ';'
    166                      | statement_list ';' statement
    167                      ;
    168 <br>
    169 statement            : expression
    170                      | STRING
    171                      | Break
    172                      | Quit
    173                      | Return
    174                      | Return '(' return_expression ')'
    175                      | For '(' expression ';'
    176                            relational_expression ';'
    177                            expression ')' statement
    178                      | If '(' relational_expression ')' statement
    179                      | While '(' relational_expression ')' statement
    180                      | '{' statement_list '}'
    181                      ;
    182 <br>
    183 function             : Define LETTER '(' opt_define_list ')'
    184                            '{' NEWLINE opt_auto_define_list
    185                            statement_list '}'
    186                      ;
    187 <br>
    188 opt_define_list      : /* empty */
    189                      | define_list
    190                      ;
    191 <br>
    192 opt_auto_define_list : /* empty */
    193                      | Auto define_list NEWLINE
    194                      | Auto define_list ';'
    195                      ;
    196 <br>
    197 define_list          : LETTER
    198                      | LETTER '[' ']'
    199                      | define_list ',' LETTER
    200                      | define_list ',' LETTER '[' ']'
    201                      ;
    202 <br>
    203 opt_argument_list    : /* empty */
    204                      | argument_list
    205                      ;
    206 <br>
    207 argument_list        : expression
    208                      | expression ',' argument_list
    209                      | LETTER '[' ']'
    210                      | LETTER '[' ']' ',' argument_list
    211                      ;
    212 <br>
    213 relational_expression : expression
    214                      | expression REL_OP expression
    215                      ;
    216 <br>
    217 return_expression    : /* empty */
    218                      | expression
    219                      ;
    220 <br>
    221 expression           : named_expression
    222                      | NUMBER
    223                      | '(' expression ')'
    224                      | LETTER '(' opt_argument_list ')'
    225                      | '-' expression
    226                      | expression '+' expression
    227                      | expression '-' expression
    228                      | expression MUL_OP expression
    229                      | expression '^' expression
    230                      | INCR_DECR named_expression
    231                      | named_expression INCR_DECR
    232                      | named_expression ASSIGN_OP expression
    233                      | Length '(' expression ')'
    234                      | Sqrt '(' expression ')'
    235                      | Scale '(' expression ')'
    236                      ;
    237 <br>
    238 named_expression     : LETTER
    239                      | LETTER '[' expression ']'
    240                      | Scale
    241                      | Ibase
    242                      | Obase
    243                      ;
    244 </tt></pre>
    245 <h5><a name="tag_20_09_13_02" id="tag_20_09_13_02"></a>Lexical Conventions in bc</h5>
    246 <p>The lexical conventions for <i>bc</i> programs, with respect to the preceding grammar, shall be as follows:</p>
    247 <ol>
    248 <li>
    249 <p>Except as noted, <i>bc</i> shall recognize the longest possible token or delimiter beginning at a given point.</p>
    250 </li>
    251 <li>
    252 <p>A comment shall consist of any characters beginning with the two adjacent characters <tt>"/*"</tt> and terminated by the next
    253 occurrence of the two adjacent characters <tt>"*/"</tt>. Comments shall have no effect except to delimit lexical tokens.</p>
    254 </li>
    255 <li>
    256 <p>The &lt;newline&gt; shall be recognized as the token <b>NEWLINE</b>.</p>
    257 </li>
    258 <li>
    259 <p>The token <b>STRING</b> shall represent a string constant; it shall consist of any characters beginning with the double-quote
    260 character (<tt>'"'</tt> ) and terminated by another occurrence of the double-quote character. The value of the string is the
    261 sequence of all characters between, but not including, the two double-quote characters. All characters shall be taken literally
    262 from the input, and there is no way to specify a string containing a double-quote character. The length of the value of each string
    263 shall be limited to {BC_STRING_MAX} bytes.</p>
    264 </li>
    265 <li>
    266 <p>A &lt;blank&gt; shall have no effect except as an ordinary character if it appears within a <b>STRING</b> token, or to delimit a
    267 lexical token other than <b>STRING</b>.</p>
    268 </li>
    269 <li>
    270 <p>The combination of a &lt;backslash&gt; character immediately followed by a &lt;newline&gt; shall have no effect other than to
    271 delimit lexical tokens with the following exceptions:</p>
    272 <ul>
    273 <li>
    274 <p>It shall be interpreted as the character sequence <tt>"\&lt;newline&gt;"</tt> in <b>STRING</b> tokens.</p>
    275 </li>
    276 <li>
    277 <p>It shall be ignored as part of a multi-line <b>NUMBER</b> token.</p>
    278 </li>
    279 </ul>
    280 </li>
    281 <li>
    282 <p>The token <b>NUMBER</b> shall represent a numeric constant. It shall be recognized by the following grammar:</p>
    283 <pre>
    284 <tt>NUMBER  : integer
    285         | '.' integer
    286         | integer '.'
    287         | integer '.' integer
    288         ;
    289 <br>
    290 integer : digit
    291         | integer digit
    292         ;
    293 <br>
    294 digit   : 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
    295         | 8 | 9 | A | B | C | D | E | F
    296         ;
    297 </tt></pre></li>
    298 <li>
    299 <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
    300 <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, and
    301 the &lt;period&gt; character shall represent the radix point. The behavior is undefined if digits greater than or equal to the
    302 value of <b>ibase</b> appear in the token. However, note the exception for single-digit values being assigned to <b>ibase</b> and
    303 <b>obase</b> themselves, in <a href="#tag_20_09_13_03">Operations in bc</a> .</p>
    304 </li>
    305 <li>
    306 <p>The following keywords shall be recognized as tokens:</p>
    307 <table cellpadding="3">
    308 <tr valign="top">
    309 <td align="left">
    310 <p class="tent"><b><br>
    311 auto<br>
    312 break<br>
    313 define<br></b></p>
    314 </td>
    315 <td align="left">
    316 <p class="tent"><b><br>
    317 ibase<br>
    318 if<br>
    319 for<br></b></p>
    320 </td>
    321 <td align="left">
    322 <p class="tent"><b><br>
    323 length<br>
    324 obase<br>
    325 quit<br></b></p>
    326 </td>
    327 <td align="left">
    328 <p class="tent"><b><br>
    329 return<br>
    330 scale<br>
    331 sqrt<br></b></p>
    332 </td>
    333 <td align="left">
    334 <p class="tent"><b><br>
    335 while<br></b></p>
    336 </td>
    337 </tr>
    338 </table>
    339 </li>
    340 <li class="tent">Any of the following characters occurring anywhere except within a keyword shall be recognized as the token
    341 <b>LETTER</b>:
    342 <pre>
    343 <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
    344 </tt></pre></li>
    345 <li class="tent">The following single-character and two-character sequences shall be recognized as the token <b>ASSIGN_OP</b>:
    346 <pre>
    347 <tt>=   +=   -=   *=   /=   %=   ^=
    348 </tt></pre></li>
    349 <li class="tent">If an <tt>'='</tt> character, as the beginning of a token, is followed by a <tt>'-'</tt> character with no
    350 intervening delimiter, the behavior is undefined.</li>
    351 <li class="tent">The following single-characters shall be recognized as the token <b>MUL_OP</b>:
    352 <pre>
    353 <tt>*   /   %
    354 </tt></pre></li>
    355 <li class="tent">The following single-character and two-character sequences shall be recognized as the token <b>REL_OP</b>:
    356 <pre>
    357 <tt>==   &lt;=   &gt;=   !=   &lt;   &gt;
    358 </tt></pre></li>
    359 <li class="tent">The following two-character sequences shall be recognized as the token <b>INCR_DECR</b>:
    360 <pre>
    361 <tt>++   --
    362 </tt></pre></li>
    363 <li class="tent">The following single characters shall be recognized as tokens whose names are the character:
    364 <pre>
    365 <tt>&lt;newline&gt;  (  )  ,  +  -  ;  [  ]  ^  {  }
    366 </tt></pre></li>
    367 <li class="tent">The token <b>EOF</b> is returned when the end of input is reached.</li>
    368 </ol>
    369 <h5><a name="tag_20_09_13_03" id="tag_20_09_13_03"></a>Operations in bc</h5>
    370 <p class="tent">There are three kinds of identifiers: ordinary identifiers, array identifiers, and function identifiers. All three
    371 types consist of single lowercase letters. Array identifiers shall be followed by square brackets (<tt>"[]"</tt>). An array
    372 subscript is required except in an argument or auto list. Arrays are singly dimensioned and can contain up to {BC_DIM_MAX}
    373 elements. Indexing shall begin at zero so an array is indexed from 0 to {BC_DIM_MAX}-1. Subscripts shall be truncated to integers.
    374 The application shall ensure that function identifiers are followed by parentheses, possibly enclosing arguments. The three types
    375 of identifiers do not conflict.</p>
    376 <p class="tent">The following table summarizes the rules for precedence and associativity of all operators. Operators on the same
    377 line shall have the same precedence; rows are in order of decreasing precedence.</p>
    378 <p class="caption">Table: Operators in <i>bc</i></p>
    379 <center>
    380 <table border="1" cellpadding="3" align="center">
    381 <tr valign="top">
    382 <th align="center">
    383 <p class="tent"><b>Operator</b></p>
    384 </th>
    385 <th align="center">
    386 <p class="tent"><b>Associativity</b></p>
    387 </th>
    388 </tr>
    389 <tr valign="top">
    390 <td align="left">
    391 <p class="tent">++, --</p>
    392 </td>
    393 <td align="left">
    394 <p class="tent">N/A</p>
    395 </td>
    396 </tr>
    397 <tr valign="top">
    398 <td align="left">
    399 <p class="tent">unary -</p>
    400 </td>
    401 <td align="left">
    402 <p class="tent">N/A</p>
    403 </td>
    404 </tr>
    405 <tr valign="top">
    406 <td align="left">
    407 <p class="tent">^</p>
    408 </td>
    409 <td align="left">
    410 <p class="tent">Right to left</p>
    411 </td>
    412 </tr>
    413 <tr valign="top">
    414 <td align="left">
    415 <p class="tent">*, /, %</p>
    416 </td>
    417 <td align="left">
    418 <p class="tent">Left to right</p>
    419 </td>
    420 </tr>
    421 <tr valign="top">
    422 <td align="left">
    423 <p class="tent">+, binary -</p>
    424 </td>
    425 <td align="left">
    426 <p class="tent">Left to right</p>
    427 </td>
    428 </tr>
    429 <tr valign="top">
    430 <td align="left">
    431 <p class="tent">=, +=, -=, *=, /=, %=, ^=</p>
    432 </td>
    433 <td align="left">
    434 <p class="tent">Right to left</p>
    435 </td>
    436 </tr>
    437 <tr valign="top">
    438 <td align="left">
    439 <p class="tent">==, &lt;=, &gt;=, !=, &lt;, &gt;</p>
    440 </td>
    441 <td align="left">
    442 <p class="tent">None</p>
    443 </td>
    444 </tr>
    445 </table>
    446 </center>
    447 <p class="tent">Each expression or named expression has a <i>scale</i>, which is the number of decimal digits that shall be
    448 maintained as the fractional portion of the expression.</p>
    449 <p class="tent"><i>Named expressions</i> are places where values are stored. Named expressions shall be valid on the left side of
    450 an assignment. The value of a named expression shall be the value stored in the place named. Simple identifiers and array elements
    451 are named expressions; they have an initial value of zero and an initial scale of zero.</p>
    452 <p class="tent">The internal registers <b>scale</b>, <b>ibase</b>, and <b>obase</b> are all named expressions. The scale of an
    453 expression consisting of the name of one of these registers shall be zero; values assigned to any of these registers are truncated
    454 to integers. The <b>scale</b> register shall contain a global value used in computing the scale of expressions (as described
    455 below). The value of the register <b>scale</b> is limited to 0 &lt;= <b>scale</b> &lt;= {BC_SCALE_MAX} and shall have a default
    456 value of zero. The <b>ibase</b> and <b>obase</b> registers are the input and output number radix, respectively. The value of
    457 <b>ibase</b> shall be limited to:</p>
    458 <pre>
    459 <tt>2 &lt;= ibase &lt;= 16
    460 </tt></pre>
    461 <p class="tent">The value of <b>obase</b> shall be limited to:</p>
    462 <pre>
    463 <tt>2 &lt;= obase &lt;= {BC_BASE_MAX}
    464 </tt></pre>
    465 <p class="tent">When either <b>ibase</b> or <b>obase</b> is assigned a single <b>digit</b> value from the list in <a href=
    466 "#tag_20_09_13_02">Lexical Conventions in bc</a> , the value shall be assumed in hexadecimal. (For example, <b>ibase</b>=A sets to
    467 base ten, regardless of the current <b>ibase</b> value.) Otherwise, the behavior is undefined when digits greater than or equal to
    468 the value of <b>ibase</b> appear in the input. Both <b>ibase</b> and <b>obase</b> shall have initial values of 10.</p>
    469 <p class="tent">Internal computations shall be conducted as if in decimal, regardless of the input and output bases, to the
    470 specified number of decimal digits. When an exact result is not achieved (for example, <b>scale</b>=0;&nbsp;3.2/1)<b>,</b> the
    471 result shall be truncated.</p>
    472 <p class="tent">For all values of <b>obase</b> specified by this volume of POSIX.1-2024, <i>bc</i> shall output numeric values by
    473 performing each of the following steps in order:</p>
    474 <ol>
    475 <li class="tent">If the value is less than zero, a &lt;hyphen-minus&gt; (<tt>'-'</tt>) character shall be output.</li>
    476 <li class="tent">One of the following is output, depending on the numerical value:
    477 <ul>
    478 <li class="tent">If the absolute value of the numerical value is greater than or equal to one, the integer portion of the value
    479 shall be output as a series of digits appropriate to <b>obase</b> (as described below), most significant digit first. The most
    480 significant non-zero digit shall be output next, followed by each successively less significant digit.</li>
    481 <li class="tent">If the absolute value of the numerical value is less than one but greater than zero and the scale of the numerical
    482 value is greater than zero, it is unspecified whether the character 0 is output.</li>
    483 <li class="tent">If the numerical value is zero, the character 0 shall be output.</li>
    484 </ul>
    485 </li>
    486 <li class="tent">If the scale of the value is greater than zero and the numeric value is not zero, a &lt;period&gt; character shall
    487 be output, followed by a series of digits appropriate to <b>obase</b> (as described below) representing the most significant
    488 portion of the fractional part of the value. If <i>s</i> represents the scale of the value being output, the number of digits
    489 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
    490 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
    491 needed to represent a precision of 10<sup><small><i>s</i></small></sup>.</li>
    492 </ol>
    493 <p class="tent">For <b>obase</b> values from 2 to 16, valid digits are the first <b>obase</b> of the single characters:</p>
    494 <pre>
    495 <tt>0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
    496 </tt></pre>
    497 <p class="tent">which represent the values zero to 15, inclusive, respectively.</p>
    498 <p class="tent">For bases greater than 16, each digit shall be written as a separate multi-digit decimal number. Each digit except
    499 the most significant fractional digit shall be preceded by a single &lt;space&gt;. For bases from 17 to 100, <i>bc</i> shall write
    500 two-digit decimal numbers; for bases from 101 to 1000, three-digit decimal strings, and so on. For example, the decimal number 1024
    501 in base 25 would be written as:</p>
    502 <pre>
    503 <tt>Δ01Δ15Δ24
    504 </tt></pre>
    505 <p class="tent">and in base 125, as:</p>
    506 <pre>
    507 <tt>Δ008Δ024
    508 </tt></pre>
    509 <p class="tent">Very large numbers shall be split across lines with 70 characters per line in the POSIX locale; other locales may
    510 split at different character boundaries. Lines that are continued shall end with a &lt;backslash&gt;.</p>
    511 <p class="tent">A function call shall consist of a function name followed by parentheses containing a &lt;comma&gt;-separated list
    512 of expressions, which are the function arguments. A whole array passed as an argument shall be specified by the array name followed
    513 by empty square brackets. All function arguments shall be passed by value. As a result, changes made to the formal parameters shall
    514 have no effect on the actual arguments. If the function terminates by executing a <b>return</b> statement, the value of the
    515 function shall be the value of the expression in the parentheses of the <b>return</b> statement or shall be zero if no expression
    516 is provided or if there is no <b>return</b> statement.</p>
    517 <p class="tent">The result of <b>sqrt</b>(<i>expression</i>) shall be the square root of the expression. The result shall be
    518 truncated in the least significant decimal place. The scale of the result shall be the scale of the expression or the value of
    519 <b>scale</b>, whichever is larger.</p>
    520 <p class="tent">The result of <b>length</b>(<i>expression</i>) shall be the total number of significant decimal digits in the
    521 expression. The scale of the result shall be zero.</p>
    522 <p class="tent">The result of <b>scale</b>(<i>expression</i>) shall be the scale of the expression. The scale of the result shall
    523 be zero.</p>
    524 <p class="tent">A numeric constant shall be an expression. The scale shall be the number of digits that follow the radix point in
    525 the input representing the constant, or zero if no radix point appears.</p>
    526 <p class="tent">The sequence (&nbsp;<i>expression</i>&nbsp;) shall be an expression with the same value and scale as
    527 <i>expression</i>. The parentheses can be used to alter the normal precedence.</p>
    528 <p class="tent">The semantics of the unary and binary operators are as follows:</p>
    529 <dl compact>
    530 <dd></dd>
    531 <dt>-<i>expression</i></dt>
    532 <dd><br>
    533 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>
    534 </dl>
    535 <p class="tent">The unary increment and decrement operators shall not modify the scale of the named expression upon which they
    536 operate. The scale of the result shall be the scale of that named expression.</p>
    537 <dl compact>
    538 <dd></dd>
    539 <dt>++<i>named-expression</i></dt>
    540 <dd><br>
    541 The named expression shall be incremented by one. The result shall be the value of the named expression after incrementing.</dd>
    542 <dt>--<i>named-expression</i></dt>
    543 <dd><br>
    544 The named expression shall be decremented by one. The result shall be the value of the named expression after decrementing.</dd>
    545 <dt><i>named-expression</i>++</dt>
    546 <dd><br>
    547 The named expression shall be incremented by one. The result shall be the value of the named expression before incrementing.</dd>
    548 <dt><i>named-expression</i>--</dt>
    549 <dd><br>
    550 The named expression shall be decremented by one. The result shall be the value of the named expression before decrementing.</dd>
    551 </dl>
    552 <p class="tent">The exponentiation operator, &lt;circumflex&gt; (<tt>'^'</tt>), shall bind right to left.</p>
    553 <dl compact>
    554 <dd></dd>
    555 <dt><i>expression</i>^<i>expression</i></dt>
    556 <dd><br>
    557 The result shall be the first <i>expression</i> raised to the power of the second <i>expression</i>. If the second expression is
    558 not 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 of
    559 the right expression, the scale of the result shall be:
    560 <pre>
    561 <tt>if b &gt;= 0 min(a * b, max(scale, a)) if b &lt; 0 scale
    562 </tt></pre></dd>
    563 </dl>
    564 The multiplicative operators (<tt>'*'</tt>, <tt>'/'</tt>, <tt>'%'</tt>) shall bind left to right.
    565 <dl compact>
    566 <dd></dd>
    567 <dt><i>expression</i>*<i>expression</i></dt>
    568 <dd><br>
    569 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 the
    570 scale of the result shall be:
    571 <pre>
    572 <tt>min(a+b,max(scale,a,b))
    573 </tt></pre></dd>
    574 <dt><i>expression</i>/<i>expression</i></dt>
    575 <dd><br>
    576 The result shall be the quotient of the two expressions. The scale of the result shall be the value of <b>scale</b>.</dd>
    577 <dt><i>expression</i>%<i>expression</i></dt>
    578 <dd><br>
    579 For expressions <i>a</i> and <i>b</i>, <i>a</i>%<i>b</i> shall be evaluated equivalent to the steps:
    580 <ol>
    581 <li class="tent">Compute <i>a</i>/<i>b</i> to current scale.</li>
    582 <li class="tent">Use the result to compute:
    583 <pre>
    584 <tt>a - (a / b) * b
    585 </tt></pre>
    586 <p class="tent">to scale:</p>
    587 <pre>
    588 <tt>max(scale + scale(b), scale(a))
    589 </tt></pre></li>
    590 </ol>
    591 The scale of the result shall be:
    592 <pre>
    593 <tt>max(scale + scale(b), scale(a))
    594 </tt></pre>
    595 <p class="tent">When <b>scale</b> is zero, the <tt>'%'</tt> operator is the mathematical remainder operator.</p>
    596 </dd>
    597 </dl>
    598 <p class="tent">The additive operators (<tt>'+'</tt>, <tt>'-'</tt>) shall bind left to right.</p>
    599 <dl compact>
    600 <dd></dd>
    601 <dt><i>expression</i>+<i>expression</i></dt>
    602 <dd><br>
    603 The result shall be the sum of the two expressions. The scale of the result shall be the maximum of the scales of the
    604 expressions.</dd>
    605 <dt><i>expression</i>-<i>expression</i></dt>
    606 <dd><br>
    607 The result shall be the difference of the two expressions. The scale of the result shall be the maximum of the scales of the
    608 expressions.</dd>
    609 </dl>
    610 <p class="tent">The assignment operators (<tt>'='</tt>, <tt>"+="</tt>, <tt>"-="</tt>, <tt>"*="</tt>, <tt>"/="</tt>, <tt>"%="</tt>,
    611 <tt>"^="</tt>) shall bind right to left.</p>
    612 <dl compact>
    613 <dd></dd>
    614 <dt><i>named-expression</i>=<i>expression</i></dt>
    615 <dd><br>
    616 This expression shall result in assigning the value of the expression on the right to the named expression on the left. The scale
    617 of both the named expression and the result shall be the scale of <i>expression</i>.</dd>
    618 </dl>
    619 <p class="tent">The compound assignment forms:</p>
    620 <pre>
    621 <i>named-expression</i><tt> &lt;</tt><i>operator</i><tt>&gt;= </tt><i>expression</i><tt>
    622 </tt></pre>
    623 <p class="tent">shall be equivalent to:</p>
    624 <pre>
    625 <i>named-expression</i><tt>=</tt><i>named-expression</i><tt> &lt;</tt><i>operator</i><tt>&gt; </tt><i>expression</i><tt>
    626 </tt></pre>
    627 <p class="tent">except that the <i>named-expression</i> shall be evaluated only once.</p>
    628 <p class="tent">Unlike all other operators, the relational operators (<tt>'&lt;'</tt>, <tt>'&gt;'</tt>, <tt>"&lt;="</tt>,
    629 <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
    630 <b>for</b> statement.</p>
    631 <dl compact>
    632 <dd></dd>
    633 <dt><i>expression1</i>&lt;<i>expression2</i></dt>
    634 <dd><br>
    635 The relation shall be true if the value of <i>expression1</i> is strictly less than the value of <i>expression2</i>.</dd>
    636 <dt><i>expression1</i>&gt;<i>expression2</i></dt>
    637 <dd><br>
    638 The relation shall be true if the value of <i>expression1</i> is strictly greater than the value of <i>expression2</i>.</dd>
    639 <dt><i>expression1</i>&lt;=<i>expression2</i></dt>
    640 <dd><br>
    641 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>
    642 <dt><i>expression1</i>&gt;=<i>expression2</i></dt>
    643 <dd><br>
    644 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>
    645 <dt><i>expression1</i>==<i>expression2</i></dt>
    646 <dd><br>
    647 The relation shall be true if the values of <i>expression1</i> and <i>expression2</i> are equal.</dd>
    648 <dt><i>expression1</i>!=<i>expression2</i></dt>
    649 <dd><br>
    650 The relation shall be true if the values of <i>expression1</i> and <i>expression2</i> are unequal.</dd>
    651 </dl>
    652 <p class="tent">There are only two storage classes in <i>bc</i>: global and automatic (local). Only identifiers that are local to a
    653 function need be declared with the <b>auto</b> command. The arguments to a function shall be local to the function. All other
    654 identifiers are assumed to be global and available to all functions. All identifiers, global and local, have initial values of
    655 zero. Identifiers declared as auto shall be allocated on entry to the function and released on returning from the function. They
    656 therefore do not retain values between function calls. Auto arrays shall be specified by the array name followed by empty square
    657 brackets. On entry to a function, the old values of the names that appear as parameters and as automatic variables shall be pushed
    658 onto a stack. Until the function returns, reference to these names shall refer only to the new values.</p>
    659 <p class="tent">References to any of these names from other functions that are called from this function also refer to the new
    660 value until one of those functions uses the same name for a local variable.</p>
    661 <p class="tent">When a statement is an expression, unless the main operator is an assignment, execution of the statement shall
    662 write the value of the expression followed by a &lt;newline&gt;.</p>
    663 <p class="tent">When a statement is a string, execution of the statement shall write the value of the string.</p>
    664 <p class="tent">Statements separated by &lt;semicolon&gt; or &lt;newline&gt; characters shall be executed sequentially. In an
    665 interactive invocation of <i>bc</i>, each time a &lt;newline&gt; is read that satisfies the grammatical production:</p>
    666 <pre>
    667 <tt>input_item : semicolon_list NEWLINE
    668 </tt></pre>
    669 <p class="tent">the sequential list of statements making up the <b>semicolon_list</b> shall be executed immediately and any output
    670 produced by that execution shall be written without any delay due to buffering.</p>
    671 <p class="tent">In an <b>if</b> statement (<b>if</b>(<i>relation</i>) <i>statement</i>), the <i>statement</i> shall be executed if
    672 the relation is true.</p>
    673 <p class="tent">The <b>while</b> statement (<b>while</b>(<i>relation</i>) <i>statement</i>) implements a loop in which the
    674 <i>relation</i> is tested; each time the <i>relation</i> is true, the <i>statement</i> shall be executed and the <i>relation</i>
    675 retested. When the <i>relation</i> is false, execution shall resume after <i>statement</i>.</p>
    676 <p class="tent">A <b>for</b> statement(<b>for</b>(<i>expression</i>; <i>relation</i>; <i>expression</i>) <i>statement</i>) shall be
    677 the same as:</p>
    678 <pre>
    679 <i>first-expression</i><tt>
    680 while (</tt><i>relation</i><tt>) {
    681     </tt><i>statement</i><tt>
    682     </tt><i>last-expression</i><tt>
    683 }
    684 </tt></pre>
    685 The application shall ensure that all three expressions are present.
    686 <p class="tent">The <b>break</b> statement shall cause termination of a <b>for</b> or <b>while</b> statement.</p>
    687 <p class="tent">The <b>auto</b> statement (<b>auto</b> <i>identifier</i> <b>[</b>,<i>identifier</i><b>]</b> ...) shall cause the
    688 values of the identifiers to be pushed down. The identifiers can be ordinary identifiers or array identifiers. Array identifiers
    689 shall be specified by following the array name by empty square brackets. The application shall ensure that the <b>auto</b>
    690 statement is the first statement in a function definition.</p>
    691 <p class="tent">A <b>define</b> statement:</p>
    692 <pre>
    693 <tt>define </tt><i>LETTER</i><tt> ( </tt><i>opt_define_list</i><tt> ) {
    694     </tt><i>opt_auto_define_list</i><tt>
    695     </tt><i>statement_list</i><tt>
    696 }
    697 </tt></pre>
    698 <p class="tent">defines a function named <b>LETTER</b>. If a function named <b>LETTER</b> was previously defined, the <b>define</b>
    699 statement shall replace the previous definition. The expression:</p>
    700 <pre>
    701 <tt>LETTER ( </tt><i>opt_argument_list</i><tt> )
    702 </tt></pre>
    703 <p class="tent">shall invoke the function named <b>LETTER</b>. The behavior is undefined if the number of arguments in the
    704 invocation does not match the number of parameters in the definition. Functions shall be defined before they are invoked. A
    705 function shall be considered to be defined within its own body, so recursive calls are valid. The values of numeric constants
    706 within a function shall be interpreted in the base specified by the value of the <b>ibase</b> register when the function is
    707 invoked.</p>
    708 <p class="tent">The <b>return</b> statements (<b>return</b> and <b>return</b>(<i>expression</i>)) shall cause termination of a
    709 function, popping of its auto variables, and specification of the result of the function. The first form shall be equivalent to
    710 <b>return</b>(0). The value and scale of the result returned by the function shall be the value and scale of the expression
    711 returned.</p>
    712 <p class="tent">The <b>quit</b> statement (<b>quit</b>) shall stop execution of a <i>bc</i> program at the point where the
    713 statement occurs in the input, even if it occurs in a function definition, or in an <b>if</b>, <b>for</b>, or <b>while</b>
    714 statement.</p>
    715 <p class="tent">The following functions shall be defined when the <b>-l</b> option is specified:</p>
    716 <dl compact>
    717 <dd></dd>
    718 <dt><b>s</b>(&nbsp;<i>expression</i>&nbsp;)</dt>
    719 <dd><br>
    720 Sine of argument in radians.</dd>
    721 <dt><b>c</b>(&nbsp;<i>expression</i>&nbsp;)</dt>
    722 <dd><br>
    723 Cosine of argument in radians.</dd>
    724 <dt><b>a</b>(&nbsp;<i>expression</i>&nbsp;)</dt>
    725 <dd><br>
    726 Arctangent of argument.</dd>
    727 <dt><b>l</b>(&nbsp;<i>expression</i>&nbsp;)</dt>
    728 <dd><br>
    729 Natural logarithm of argument.</dd>
    730 <dt><b>e</b>(&nbsp;<i>expression</i>&nbsp;)</dt>
    731 <dd><br>
    732 Exponential function of argument.</dd>
    733 <dt><b>j</b>(&nbsp;<i>expression1</i>,&nbsp;<i>expression2</i>&nbsp;)</dt>
    734 <dd><br>
    735 Bessel function of <i>expression2</i> of the first kind of integer order <i>expression1</i>.</dd>
    736 </dl>
    737 <p class="tent">The scale of the result returned by these functions shall be the value of the <b>scale</b> register at the time the
    738 function is invoked. The value of the <b>scale</b> register after these functions have completed their execution shall be the same
    739 value it had upon invocation. The behavior is undefined if any of these functions is invoked with an argument outside the domain of
    740 the mathematical function.</p>
    741 </blockquote>
    742 <h4 class="mansect"><a name="tag_20_09_14" id="tag_20_09_14"></a>EXIT STATUS</h4>
    743 <blockquote>
    744 <p>The following exit values shall be returned:</p>
    745 <dl compact>
    746 <dd></dd>
    747 <dt>0</dt>
    748 <dd>All input files were processed successfully.</dd>
    749 <dt><i>unspecified</i></dt>
    750 <dd>An error occurred.</dd>
    751 </dl>
    752 </blockquote>
    753 <h4 class="mansect"><a name="tag_20_09_15" id="tag_20_09_15"></a>CONSEQUENCES OF ERRORS</h4>
    754 <blockquote>
    755 <p>If any <i>file</i> operand is specified and the named file cannot be accessed, <i>bc</i> shall write a diagnostic message to
    756 standard error and terminate without any further action.</p>
    757 <p class="tent">In an interactive invocation of <i>bc</i>, the utility should print an error message and recover following any
    758 error in the input. In a non-interactive invocation of <i>bc</i>, invalid input causes undefined behavior.</p>
    759 </blockquote>
    760 <hr>
    761 <div class="box"><em>The following sections are informative.</em></div>
    762 <h4 class="mansect"><a name="tag_20_09_16" id="tag_20_09_16"></a>APPLICATION USAGE</h4>
    763 <blockquote>
    764 <p>Automatic variables in <i>bc</i> do not work in exactly the same way as in either C or PL/1.</p>
    765 <p class="tent">For historical reasons, the exit status from <i>bc</i> cannot be relied upon to indicate that an error has
    766 occurred. Returning zero after an error is possible. Therefore, <i>bc</i> should be used primarily by interactive users (who can
    767 react to error messages) or by application programs that can somehow validate the answers returned as not including error
    768 messages.</p>
    769 <p class="tent">The <i>bc</i> utility always uses the &lt;period&gt; (<tt>'.'</tt>) character to represent a radix point,
    770 regardless of any decimal-point character specified as part of the current locale. In languages like C or <a href=
    771 "../utilities/awk.html"><i>awk</i></a>, the &lt;period&gt; character is used in program source, so it can be portable and
    772 unambiguous, while the locale-specific character is used in input and output. Because there is no distinction between source and
    773 input in <i>bc</i>, this arrangement would not be possible. Using the locale-specific character in <i>bc</i>'s input would
    774 introduce ambiguities into the language; consider the following example in a locale with a &lt;comma&gt; as the decimal-point
    775 character:</p>
    776 <pre>
    777 <tt>define f(a,b) {
    778     ...
    779 }
    780 ...
    781 <br class="tent">
    782 f(1,2,3)
    783 </tt></pre>
    784 <p class="tent">Because of such ambiguities, the &lt;period&gt; character is used in input. Having input follow different
    785 conventions from output would be confusing in either pipeline usage or interactive usage, so the &lt;period&gt; is also used in
    786 output.</p>
    787 </blockquote>
    788 <h4 class="mansect"><a name="tag_20_09_17" id="tag_20_09_17"></a>EXAMPLES</h4>
    789 <blockquote>
    790 <p>In the shell, the following assigns an approximation of the first ten digits of <tt>'ℼ'</tt> to the variable <i>x</i>:</p>
    791 <pre>
    792 <tt>x=$(printf "%s\n" 'scale = 10; 104348/33215' | bc)
    793 </tt></pre>
    794 <p class="tent">The following <i>bc</i> program prints the same approximation of <tt>'ℼ'</tt>, with a label, to standard
    795 output:</p>
    796 <pre>
    797 <tt>scale = 10
    798 "pi equals "
    799 104348 / 33215
    800 </tt></pre>
    801 <p class="tent">The following defines a function to compute an approximate value of the exponential function (note that such a
    802 function is predefined if the <b>-l</b> option is specified):</p>
    803 <pre>
    804 <tt>scale = 20
    805 define e(x){
    806     auto a, b, c, i, s
    807     a = 1
    808     b = 1
    809     s = 1
    810     for (i = 1; 1 == 1; i++){
    811         a = a*x
    812         b = b*i
    813         c = a/b
    814         if (c == 0) {
    815              return(s)
    816         }
    817         s = s+c
    818     }
    819 }
    820 </tt></pre>
    821 <p class="tent">The following prints approximate values of the exponential function of the first ten integers:</p>
    822 <pre>
    823 <tt>for (i = 1; i &lt;= 10; ++i) {
    824     e(i)
    825 }
    826 </tt></pre></blockquote>
    827 <h4 class="mansect"><a name="tag_20_09_18" id="tag_20_09_18"></a>RATIONALE</h4>
    828 <blockquote>
    829 <p>The <i>bc</i> utility is implemented historically as a front-end processor for <i>dc</i>; <i>dc</i> was not selected to be part
    830 of this volume of POSIX.1-2024 because <i>bc</i> was thought to have a more intuitive programmatic interface. Current
    831 implementations that implement <i>bc</i> using <i>dc</i> are expected to be compliant.</p>
    832 <p class="tent">The exit status for error conditions has been left unspecified for several reasons:</p>
    833 <ul>
    834 <li class="tent">The <i>bc</i> utility is used in both interactive and non-interactive situations. Different exit codes may be
    835 appropriate for the two uses.</li>
    836 <li class="tent">It is unclear when a non-zero exit should be given; divide-by-zero, undefined functions, and syntax errors are all
    837 possibilities.</li>
    838 <li class="tent">It is not clear what utility the exit status has.</li>
    839 <li class="tent">In the 4.3 BSD, System V, and Ninth Edition implementations, <i>bc</i> works in conjunction with <i>dc</i>. The
    840 <i>dc</i> utility is the parent, <i>bc</i> is the child. This was done to cleanly terminate <i>bc</i> if <i>dc</i> aborted.</li>
    841 </ul>
    842 <p class="tent">The decision to have <i>bc</i> exit upon encountering an inaccessible input file is based on the belief that
    843 <i>bc</i> <i>file1</i> <i>file2</i> is used most often when at least <i>file1</i> contains data/function
    844 declarations/initializations. Having <i>bc</i> continue with prerequisite files missing is probably not useful. There is no
    845 implication in the CONSEQUENCES OF ERRORS section that <i>bc</i> must check all its files for accessibility before opening any of
    846 them.</p>
    847 <p class="tent">There was considerable debate on the appropriateness of the language accepted by <i>bc</i>. Several reviewers
    848 preferred to see either a pure subset of the C language or some changes to make the language more compatible with C. While the
    849 <i>bc</i> language has some obvious similarities to C, it has never claimed to be compatible with any version of C. An interpreter
    850 for a subset of C might be a very worthwhile utility, and it could potentially make <i>bc</i> obsolete. However, no such utility is
    851 known in historical practice, and it was not within the scope of this volume of POSIX.1-2024 to define such a language and utility.
    852 If and when they are defined, it may be appropriate to include them in a future version of this standard. This left the following
    853 alternatives:</p>
    854 <ol>
    855 <li class="tent">Exclude any calculator language from this volume of POSIX.1-2024.
    856 <p class="tent">The consensus of the standard developers was that a simple programmatic calculator language is very useful for both
    857 applications and interactive users. The only arguments for excluding any calculator were that it would become obsolete if and when
    858 a C-compatible one emerged, or that the absence would encourage the development of such a C-compatible one. These arguments did not
    859 sufficiently address the needs of current application developers.</p>
    860 </li>
    861 <li class="tent">Standardize the historical <i>dc</i>, possibly with minor modifications.
    862 <p class="tent">The consensus of the standard developers was that <i>dc</i> is a fundamentally less usable language and that that
    863 would be far too severe a penalty for avoiding the issue of being similar to but incompatible with C.</p>
    864 </li>
    865 <li class="tent">Standardize the historical <i>bc</i>, possibly with minor modifications.
    866 <p class="tent">This was the approach taken. Most of the proponents of changing the language would not have been satisfied until
    867 most or all of the incompatibilities with C were resolved. Since most of the changes considered most desirable would break
    868 historical applications and require significant modification to historical implementations, almost no modifications were made. The
    869 one significant modification that was made was the replacement of the historical <i>bc</i> assignment operators <tt>"=+"</tt>, and
    870 so on, with the more modern <tt>"+="</tt>, and so on. The older versions are considered to be fundamentally flawed because of the
    871 lexical ambiguity in uses like <i>a</i>=-1.</p>
    872 <p class="tent">In order to permit implementations to deal with backwards-compatibility as they see fit, the behavior of this one
    873 ambiguous construct was made undefined. (At least three implementations have been known to support this change already, so the
    874 degree of change involved should not be great.)</p>
    875 </li>
    876 </ol>
    877 <p class="tent">The <tt>'%'</tt> operator is the mathematical remainder operator when <b>scale</b> is zero. The behavior of this
    878 operator for other values of <b>scale</b> is from historical implementations of <i>bc</i>, and has been maintained for the sake of
    879 historical applications despite its non-intuitive nature.</p>
    880 <p class="tent">Historical implementations permit setting <b>ibase</b> and <b>obase</b> to a broader range of values. This includes
    881 values less than 2, which were not seen as sufficiently useful to standardize. These implementations do not interpret input
    882 properly for values of <b>ibase</b> that are greater than 16. This is because numeric constants are recognized syntactically,
    883 rather than lexically, as described in this volume of POSIX.1-2024. They are built from lexical tokens of single hexadecimal digits
    884 and &lt;period&gt; characters. Since &lt;blank&gt; characters between tokens are not visible at the syntactic level, it is not
    885 possible to recognize the multi-digit &quot;digits&quot; used in the higher bases properly. The ability to recognize input in these bases
    886 was not considered useful enough to require modifying these implementations. Note that the recognition of numeric constants at the
    887 syntactic level is not a problem with conformance to this volume of POSIX.1-2024, as it does not impact the behavior of conforming
    888 applications (and correct <i>bc</i> programs). Historical implementations also accept input with all of the digits
    889 <tt>'0'</tt>-<tt>'9'</tt> and <tt>'A'</tt>-<tt>'F'</tt> regardless of the value of <b>ibase</b>; since digits with value greater
    890 than or equal to <b>ibase</b> are not really appropriate, the behavior when they appear is undefined, except for the common case
    891 of:</p>
    892 <pre>
    893 <tt>ibase=8;
    894     /* Process in octal base. */
    895 ...
    896 ibase=A
    897     /* Restore decimal base. */
    898 </tt></pre>
    899 <p class="tent">In some historical implementations, if the expression to be written is an uninitialized array element, a leading
    900 &lt;space&gt; and/or up to four leading 0 characters may be output before the character zero. This behavior is considered a bug; it
    901 is unlikely that any currently conforming application relies on:</p>
    902 <pre>
    903 <tt>echo 'b[3]' | bc
    904 </tt></pre>
    905 <p class="tent">returning 00000 rather than 0.</p>
    906 <p class="tent">Exact calculation of the number of fractional digits to output for a given value in a base other than 10 can be
    907 computationally expensive. Historical implementations use a faster approximation, and this is permitted. Note that the requirements
    908 apply only to values of <b>obase</b> that this volume of POSIX.1-2024 requires implementations to support (in particular, not to 1,
    909 0, or negative bases, if an implementation supports them as an extension).</p>
    910 <p class="tent">Historical implementations of <i>bc</i> did not allow array parameters to be passed as the last parameter to a
    911 function. When <i>bc</i> was first standardized in Issue 4, this restriction was allowed. To make <i>bc</i> more widely useful, and
    912 because there are implementations without this restriction, the allowance for the restriction has been removed.</p>
    913 </blockquote>
    914 <h4 class="mansect"><a name="tag_20_09_19" id="tag_20_09_19"></a>FUTURE DIRECTIONS</h4>
    915 <blockquote>
    916 <p>None.</p>
    917 </blockquote>
    918 <h4 class="mansect"><a name="tag_20_09_20" id="tag_20_09_20"></a>SEE ALSO</h4>
    919 <blockquote>
    920 <p><a href="../utilities/V3_chap01.html#tag_18_03"><i>1.3 Grammar Conventions</i></a> , <a href=
    921 "../utilities/awk.html#"><i>awk</i></a></p>
    922 <p class="tent">XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href=
    923 "../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax Guidelines</i></a></p>
    924 </blockquote>
    925 <h4 class="mansect"><a name="tag_20_09_21" id="tag_20_09_21"></a>CHANGE HISTORY</h4>
    926 <blockquote>
    927 <p>First released in Issue 4.</p>
    928 </blockquote>
    929 <h4 class="mansect"><a name="tag_20_09_22" id="tag_20_09_22"></a>Issue 5</h4>
    930 <blockquote>
    931 <p>The FUTURE DIRECTIONS section is added.</p>
    932 </blockquote>
    933 <h4 class="mansect"><a name="tag_20_09_23" id="tag_20_09_23"></a>Issue 6</h4>
    934 <blockquote>
    935 <p>Updated to align with the IEEE&nbsp;P1003.2b draft standard, which included resolution of several interpretations of the
    936 ISO&nbsp;POSIX-2:1993 standard.</p>
    937 <p class="tent">The normative text is reworded to avoid use of the term &quot;must&quot; for application requirements.</p>
    938 </blockquote>
    939 <h4 class="mansect"><a name="tag_20_09_24" id="tag_20_09_24"></a>Issue 7</h4>
    940 <blockquote>
    941 <p>SD5-XCU-ERN-97 is applied, updating the SYNOPSIS.</p>
    942 <p class="tent">POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0066 [584] and XCU/TC2-2008/0067 [679] are applied.</p>
    943 </blockquote>
    944 <h4 class="mansect"><a name="tag_20_09_25" id="tag_20_09_25"></a>Issue 8</h4>
    945 <blockquote>
    946 <p>Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p>
    947 <p class="tent">Austin Group Defect 1230 is applied, changing the EXTENDED DESCRIPTION section to specify that array parameters can
    948 be passed as the last parameter to a function.</p>
    949 <p class="tent">Austin Group Defect 1570 is applied, removing extra spacing in <tt>"=="</tt>.</p>
    950 </blockquote>
    951 <div class="box"><em>End of informative text.</em></div>
    952 <hr>
    953 <p>&nbsp;</p>
    954 <a href="#top"><span class="topOfPage">return to top of page</span></a><br>
    955 <hr size="2" noshade>
    956 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br>
    957 POSIX™ is a Trademark of The IEEE.<br>
    958 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br>
    959 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
    960 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a>
    961 ]</font></center>
    962 <hr size="2" noshade>
    963 <div class="NAVHEADER">
    964 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0">
    965 <tr class="nav">
    966 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/batch.html" accesskey="P">&lt;&lt;&lt;
    967 Previous</a></td>
    968 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td>
    969 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/bg.html" accesskey="N">Next &gt;&gt;&gt;</a></td>
    970 </tr>
    971 </table>
    972 <hr align="left" width="100%"></div>
    973 </body>
    974 </html>