logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

bc.1p (41375B)


  1. '\" et
  2. .TH BC "1P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. bc
  12. \(em arbitrary-precision arithmetic language
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. bc \fB[\fR-l\fB] [\fIfile\fR...\fB]\fR
  17. .fi
  18. .SH DESCRIPTION
  19. The
  20. .IR bc
  21. utility shall implement an arbitrary precision calculator. It shall
  22. take input from any files given, then read from the standard input. If
  23. the standard input and standard output to
  24. .IR bc
  25. are attached to a terminal, the invocation of
  26. .IR bc
  27. shall be considered to be
  28. .IR interactive ,
  29. causing behavioral constraints described in the following sections.
  30. .SH OPTIONS
  31. The
  32. .IR bc
  33. utility shall conform to the Base Definitions volume of POSIX.1\(hy2017,
  34. .IR "Section 12.2" ", " "Utility Syntax Guidelines".
  35. .P
  36. The following option shall be supported:
  37. .IP "\fB\-l\fP" 10
  38. (The letter ell.) Define the math functions and initialize
  39. .IR scale
  40. to 20, instead of the default zero; see the EXTENDED DESCRIPTION
  41. section.
  42. .SH OPERANDS
  43. The following operand shall be supported:
  44. .IP "\fIfile\fR" 10
  45. A pathname of a text file containing
  46. .IR bc
  47. program statements. After all
  48. .IR file s
  49. have been read,
  50. .IR bc
  51. shall read the standard input.
  52. .SH STDIN
  53. See the INPUT FILES section.
  54. .SH "INPUT FILES"
  55. Input files shall be text files containing a sequence of comments,
  56. statements, and function definitions that shall be executed as they are
  57. read.
  58. .SH "ENVIRONMENT VARIABLES"
  59. The following environment variables shall affect the execution of
  60. .IR bc :
  61. .IP "\fILANG\fP" 10
  62. Provide a default value for the internationalization variables that are
  63. unset or null. (See the Base Definitions volume of POSIX.1\(hy2017,
  64. .IR "Section 8.2" ", " "Internationalization Variables"
  65. for the precedence of internationalization variables used to determine
  66. the values of locale categories.)
  67. .IP "\fILC_ALL\fP" 10
  68. If set to a non-empty string value, override the values of all the
  69. other internationalization variables.
  70. .IP "\fILC_CTYPE\fP" 10
  71. Determine the locale for the interpretation of sequences of bytes of
  72. text data as characters (for example, single-byte as opposed to
  73. multi-byte characters in arguments and input files).
  74. .IP "\fILC_MESSAGES\fP" 10
  75. .br
  76. Determine the locale that should be used to affect the format and
  77. contents of diagnostic messages written to standard error.
  78. .IP "\fINLSPATH\fP" 10
  79. Determine the location of message catalogs for the processing of
  80. .IR LC_MESSAGES .
  81. .SH "ASYNCHRONOUS EVENTS"
  82. Default.
  83. .SH STDOUT
  84. The output of the
  85. .IR bc
  86. utility shall be controlled by the program read, and consist of zero or
  87. more lines containing the value of all executed expressions without
  88. assignments. The radix and precision of the output shall be controlled
  89. by the values of the
  90. .BR obase
  91. and
  92. .BR scale
  93. variables; see the EXTENDED DESCRIPTION section.
  94. .SH STDERR
  95. The standard error shall be used only for diagnostic messages.
  96. .SH "OUTPUT FILES"
  97. None.
  98. .SH "EXTENDED DESCRIPTION"
  99. .SS "Grammar"
  100. .P
  101. The grammar in this section and the lexical conventions in the
  102. following section shall together describe the syntax for
  103. .IR bc
  104. programs. The general conventions for this style of grammar are
  105. described in
  106. .IR "Section 1.3" ", " "Grammar Conventions".
  107. A valid program can be represented as the non-terminal symbol
  108. .BR program
  109. in the grammar. This formal syntax shall take precedence over the
  110. text syntax description.
  111. .sp
  112. .RS 4
  113. .nf
  114. %token EOF NEWLINE STRING LETTER NUMBER
  115. .P
  116. %token MUL_OP
  117. /* \(aq*\(aq, \(aq/\(aq, \(aq%\(aq */
  118. .P
  119. %token ASSIGN_OP
  120. /* \(aq=\(aq, \(aq+=\(aq, \(aq-=\(aq, \(aq*=\(aq, \(aq/=\(aq, \(aq%=\(aq, \(aq\(ha=\(aq */
  121. .P
  122. %token REL_OP
  123. /* \(aq==\(aq, \(aq<=\(aq, \(aq>=\(aq, \(aq!=\(aq, \(aq<\(aq, \(aq>\(aq */
  124. .P
  125. %token INCR_DECR
  126. /* \(aq++\(aq, \(aq--\(aq */
  127. .P
  128. %token Define Break Quit Length
  129. /* \(aqdefine\(aq, \(aqbreak\(aq, \(aqquit\(aq, \(aqlength\(aq */
  130. .P
  131. %token Return For If While Sqrt
  132. /* \(aqreturn\(aq, \(aqfor\(aq, \(aqif\(aq, \(aqwhile\(aq, \(aqsqrt\(aq */
  133. .P
  134. %token Scale Ibase Obase Auto
  135. /* \(aqscale\(aq, \(aqibase\(aq, \(aqobase\(aq, \(aqauto\(aq */
  136. .P
  137. %start program
  138. .P
  139. %%
  140. .P
  141. program : EOF
  142. | input_item program
  143. ;
  144. .P
  145. input_item : semicolon_list NEWLINE
  146. | function
  147. ;
  148. .P
  149. semicolon_list : /* empty */
  150. | statement
  151. | semicolon_list \(aq;\(aq statement
  152. | semicolon_list \(aq;\(aq
  153. ;
  154. .P
  155. statement_list : /* empty */
  156. | statement
  157. | statement_list NEWLINE
  158. | statement_list NEWLINE statement
  159. | statement_list \(aq;\(aq
  160. | statement_list \(aq;\(aq statement
  161. ;
  162. .P
  163. statement : expression
  164. | STRING
  165. | Break
  166. | Quit
  167. | Return
  168. | Return \(aq(\(aq return_expression \(aq)\(aq
  169. | For \(aq(\(aq expression \(aq;\(aq
  170. relational_expression \(aq;\(aq
  171. expression \(aq)\(aq statement
  172. | If \(aq(\(aq relational_expression \(aq)\(aq statement
  173. | While \(aq(\(aq relational_expression \(aq)\(aq statement
  174. | \(aq{\(aq statement_list \(aq}\(aq
  175. ;
  176. .P
  177. function : Define LETTER \(aq(\(aq opt_parameter_list \(aq)\(aq
  178. \(aq{\(aq NEWLINE opt_auto_define_list
  179. statement_list \(aq}\(aq
  180. ;
  181. .P
  182. opt_parameter_list : /* empty */
  183. | parameter_list
  184. ;
  185. .P
  186. parameter_list : LETTER
  187. | define_list \(aq,\(aq LETTER
  188. ;
  189. .P
  190. opt_auto_define_list : /* empty */
  191. | Auto define_list NEWLINE
  192. | Auto define_list \(aq;\(aq
  193. ;
  194. .P
  195. define_list : LETTER
  196. | LETTER \(aq[\(aq \(aq]\(aq
  197. | define_list \(aq,\(aq LETTER
  198. | define_list \(aq,\(aq LETTER \(aq[\(aq \(aq]\(aq
  199. ;
  200. .P
  201. opt_argument_list : /* empty */
  202. | argument_list
  203. ;
  204. .P
  205. argument_list : expression
  206. | LETTER \(aq[\(aq \(aq]\(aq \(aq,\(aq argument_list
  207. ;
  208. .P
  209. relational_expression : expression
  210. | expression REL_OP expression
  211. ;
  212. .P
  213. return_expression : /* empty */
  214. | expression
  215. ;
  216. .P
  217. expression : named_expression
  218. | NUMBER
  219. | \(aq(\(aq expression \(aq)\(aq
  220. | LETTER \(aq(\(aq opt_argument_list \(aq)\(aq
  221. | \(aq-\(aq expression
  222. | expression \(aq+\(aq expression
  223. | expression \(aq-\(aq expression
  224. | expression MUL_OP expression
  225. | expression \(aq^\(aq expression
  226. | INCR_DECR named_expression
  227. | named_expression INCR_DECR
  228. | named_expression ASSIGN_OP expression
  229. | Length \(aq(\(aq expression \(aq)\(aq
  230. | Sqrt \(aq(\(aq expression \(aq)\(aq
  231. | Scale \(aq(\(aq expression \(aq)\(aq
  232. ;
  233. .P
  234. named_expression : LETTER
  235. | LETTER \(aq[\(aq expression \(aq]\(aq
  236. | Scale
  237. | Ibase
  238. | Obase
  239. ;
  240. .fi
  241. .P
  242. .RE
  243. .SS "Lexical Conventions in bc"
  244. .P
  245. The lexical conventions for
  246. .IR bc
  247. programs, with respect to the preceding grammar, shall be as follows:
  248. .IP " 1." 4
  249. Except as noted,
  250. .IR bc
  251. shall recognize the longest possible token or delimiter beginning at a
  252. given point.
  253. .IP " 2." 4
  254. A comment shall consist of any characters beginning with the two adjacent
  255. characters
  256. .BR \(dq/*\(dq
  257. and terminated by the next occurrence of the two adjacent characters
  258. .BR \(dq*/\(dq .
  259. Comments shall have no effect except to delimit lexical tokens.
  260. .IP " 3." 4
  261. The
  262. <newline>
  263. shall be recognized as the token
  264. .BR NEWLINE .
  265. .IP " 4." 4
  266. The token
  267. .BR STRING
  268. shall represent a string constant; it shall consist of any characters
  269. beginning with the double-quote character (\c
  270. .BR '\&"' )
  271. and terminated by another occurrence of the double-quote character. The
  272. value of the string is the sequence of all characters between, but not
  273. including, the two double-quote characters. All characters shall be
  274. taken literally from the input, and there is no way to specify a string
  275. containing a double-quote character. The length of the value of each
  276. string shall be limited to
  277. {BC_STRING_MAX}
  278. bytes.
  279. .IP " 5." 4
  280. A
  281. <blank>
  282. shall have no effect except as an ordinary character if it appears
  283. within a
  284. .BR STRING
  285. token, or to delimit a lexical token other than
  286. .BR STRING .
  287. .IP " 6." 4
  288. The combination of a
  289. <backslash>
  290. character immediately followed by a
  291. <newline>
  292. shall have no effect other than to delimit lexical tokens with the
  293. following exceptions:
  294. .RS 4
  295. .IP " *" 4
  296. It shall be interpreted as the character sequence
  297. .BR \(dq\e<newline>\(dq
  298. in
  299. .BR STRING
  300. tokens.
  301. .IP " *" 4
  302. It shall be ignored as part of a multi-line
  303. .BR NUMBER
  304. token.
  305. .RE
  306. .IP " 7." 4
  307. The token
  308. .BR NUMBER
  309. shall represent a numeric constant. It shall be recognized by the
  310. following grammar:
  311. .RS 4
  312. .sp
  313. .RS 4
  314. .nf
  315. NUMBER : integer
  316. | \(aq.\(aq integer
  317. | integer \(aq.\(aq
  318. | integer \(aq.\(aq integer
  319. ;
  320. .P
  321. integer : digit
  322. | integer digit
  323. ;
  324. .P
  325. digit : 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
  326. | 8 | 9 | A | B | C | D | E | F
  327. ;
  328. .fi
  329. .P
  330. .RE
  331. .RE
  332. .IP " 8." 4
  333. The value of a
  334. .BR NUMBER
  335. token shall be interpreted as a numeral in the base specified by the
  336. value of the internal register
  337. .BR ibase
  338. (described below). Each of the
  339. .BR digit
  340. characters shall have the value from 0 to 15 in the order listed here,
  341. and the
  342. <period>
  343. character shall represent the radix point. The behavior is undefined if
  344. digits greater than or equal to the value of
  345. .BR ibase
  346. appear in the token. However, note the exception for single-digit
  347. values being assigned to
  348. .BR ibase
  349. and
  350. .BR obase
  351. themselves, in
  352. .IR "Operations in bc".
  353. .IP " 9." 4
  354. The following keywords shall be recognized as tokens:
  355. .TS
  356. tab(@);
  357. lBw(0.6i)e lBe lBe lBe lBe.
  358. T{
  359. .nf
  360. auto
  361. break
  362. define
  363. T}@T{
  364. .nf
  365. ibase
  366. if
  367. for
  368. T}@T{
  369. .nf
  370. length
  371. obase
  372. quit
  373. T}@T{
  374. .nf
  375. return
  376. scale
  377. sqrt
  378. T}@T{
  379. .nf
  380. while
  381. .fi
  382. T}
  383. .TE
  384. .IP 10. 4
  385. Any of the following characters occurring anywhere except within a
  386. keyword shall be recognized as the token
  387. .BR LETTER :
  388. .RS 4
  389. .sp
  390. .RS 4
  391. .nf
  392. 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
  393. .fi
  394. .P
  395. .RE
  396. .RE
  397. .IP 11. 4
  398. The following single-character and two-character sequences shall be
  399. recognized as the token
  400. .BR ASSIGN_OP :
  401. .RS 4
  402. .sp
  403. .RS 4
  404. .nf
  405. = += -= *= /= %= \(ha=
  406. .fi
  407. .P
  408. .RE
  409. .RE
  410. .IP 12. 4
  411. If an
  412. .BR '='
  413. character, as the beginning of a token, is followed by a
  414. .BR '\-'
  415. character with no intervening delimiter, the behavior is undefined.
  416. .IP 13. 4
  417. The following single-characters shall be recognized as the token
  418. .BR MUL_OP :
  419. .RS 4
  420. .sp
  421. .RS 4
  422. .nf
  423. * / %
  424. .fi
  425. .P
  426. .RE
  427. .RE
  428. .IP 14. 4
  429. The following single-character and two-character sequences shall be
  430. recognized as the token
  431. .BR REL_OP :
  432. .RS 4
  433. .sp
  434. .RS 4
  435. .nf
  436. == <= >= != < >
  437. .fi
  438. .P
  439. .RE
  440. .RE
  441. .IP 15. 4
  442. The following two-character sequences shall be recognized as the token
  443. .BR INCR_DECR :
  444. .RS 4
  445. .sp
  446. .RS 4
  447. .nf
  448. ++ --
  449. .fi
  450. .P
  451. .RE
  452. .RE
  453. .IP 16. 4
  454. The following single characters shall be recognized as tokens whose
  455. names are the character:
  456. .RS 4
  457. .sp
  458. .RS 4
  459. .nf
  460. <newline> ( ) , + - ; [ ] \(ha { }
  461. .fi
  462. .P
  463. .RE
  464. .RE
  465. .IP 17. 4
  466. The token
  467. .BR EOF
  468. is returned when the end of input is reached.
  469. .SS "Operations in bc"
  470. .P
  471. There are three kinds of identifiers: ordinary identifiers, array
  472. identifiers, and function identifiers.
  473. All three types consist of single lowercase letters. Array identifiers
  474. shall be followed by square brackets (\c
  475. .BR \(dq[]\(dq ).
  476. An array subscript is required except in an argument or auto list.
  477. Arrays are singly dimensioned and can contain up to
  478. {BC_DIM_MAX}
  479. elements. Indexing shall begin at zero so an array is indexed from 0 to
  480. {BC_DIM_MAX}\-1.
  481. Subscripts shall be truncated to integers. The application shall ensure
  482. that function identifiers are followed by parentheses, possibly
  483. enclosing arguments. The three types of identifiers do not conflict.
  484. .P
  485. The following table summarizes the rules for precedence and
  486. associativity of all operators. Operators on the same line shall have
  487. the same precedence; rows are in order of decreasing precedence.
  488. .sp
  489. .ce 1
  490. \fBTable: Operators in \fIbc\fP\fR
  491. .TS
  492. center tab(@) box;
  493. cB | cB
  494. lf5 | l.
  495. Operator@Associativity
  496. _
  497. ++, \-\|\-@N/A
  498. unary \-@N/A
  499. \&^@Right to left
  500. *, /, %@Left to right
  501. +, binary \-@Left to right
  502. =, +=, \-=, *=, /=, %=, ^=@Right to left
  503. ==, <=, >=, !=, <, >@None
  504. .TE
  505. .P
  506. Each expression or named expression has a
  507. .IR scale ,
  508. which is the number of decimal digits that shall be maintained as the
  509. fractional portion of the expression.
  510. .P
  511. .IR "Named expressions"
  512. are places where values are stored. Named expressions shall be valid on
  513. the left side of an assignment. The value of a named expression shall
  514. be the value stored in the place named. Simple identifiers and array
  515. elements are named expressions; they have an initial value of zero and
  516. an initial scale of zero.
  517. .P
  518. The internal registers
  519. .BR scale ,
  520. .BR ibase ,
  521. and
  522. .BR obase
  523. are all named expressions. The scale of an expression consisting of the
  524. name of one of these registers shall be zero; values assigned to any of
  525. these registers are truncated to integers. The
  526. .BR scale
  527. register shall contain a global value used in computing the scale of
  528. expressions (as described below). The value of the register
  529. .BR scale
  530. is limited to 0 \(<=
  531. .BR scale
  532. \(<=
  533. {BC_SCALE_MAX}
  534. and shall have a default value of zero. The
  535. .BR ibase
  536. and
  537. .BR obase
  538. registers are the input and output number radix, respectively. The
  539. value of
  540. .BR ibase
  541. shall be limited to:
  542. .sp
  543. .RS 4
  544. .nf
  545. 2 \(<= ibase \(<= 16
  546. .fi
  547. .P
  548. .RE
  549. .P
  550. The value of
  551. .BR obase
  552. shall be limited to:
  553. .sp
  554. .RS 4
  555. .nf
  556. 2 \(<= obase \(<= {BC_BASE_MAX}
  557. .fi
  558. .P
  559. .RE
  560. .P
  561. When either
  562. .BR ibase
  563. or
  564. .BR obase
  565. is assigned a single
  566. .BR digit
  567. value from the list in
  568. .IR "Lexical Conventions in bc",
  569. the value shall be assumed in hexadecimal. (For example,
  570. .BR ibase =A
  571. sets to base ten, regardless of the current
  572. .BR ibase
  573. value.) Otherwise, the behavior is undefined when digits greater than
  574. or equal to the value of
  575. .BR ibase
  576. appear in the input. Both
  577. .BR ibase
  578. and
  579. .BR obase
  580. shall have initial values of 10.
  581. .P
  582. Internal computations shall be conducted as if in decimal, regardless
  583. of the input and output bases, to the specified number of decimal
  584. digits. When an exact result is not achieved (for example,
  585. .BR scale "=0;\ 3.2/1)",
  586. the result shall be truncated.
  587. .P
  588. For all values of
  589. .BR obase
  590. specified by this volume of POSIX.1\(hy2017,
  591. .IR bc
  592. shall output numeric values by performing each of the following steps
  593. in order:
  594. .IP " 1." 4
  595. If the value is less than zero, a
  596. <hyphen-minus>
  597. (\c
  598. .BR '\-' )
  599. character shall be output.
  600. .IP " 2." 4
  601. One of the following is output, depending on the numerical value:
  602. .RS 4
  603. .IP " *" 4
  604. If the absolute value of the numerical value is greater than or equal
  605. to one, the integer portion of the value shall be output as a series of
  606. digits appropriate to
  607. .BR obase
  608. (as described below), most significant digit first. The most significant
  609. non-zero digit shall be output next, followed by each successively
  610. less significant digit.
  611. .IP " *" 4
  612. If the absolute value of the numerical value is less than one but
  613. greater than zero and the scale of the numerical value is greater than
  614. zero, it is unspecified whether the character 0 is output.
  615. .IP " *" 4
  616. If the numerical value is zero, the character 0 shall be output.
  617. .RE
  618. .IP " 3." 4
  619. If the scale of the value is greater than zero and the numeric value
  620. is not zero, a
  621. <period>
  622. character shall be output, followed by a series of digits appropriate to
  623. .BR obase
  624. (as described below) representing the most significant portion of the
  625. fractional part of the value. If
  626. .IR s
  627. represents the scale of the value being output, the number of digits
  628. output shall be
  629. .IR s
  630. if
  631. .BR obase
  632. is 10, less than or equal to
  633. .IR s
  634. if
  635. .BR obase
  636. is greater than 10, or greater than or equal to
  637. .IR s
  638. if
  639. .BR obase
  640. is less than 10. For
  641. .BR obase
  642. values other than 10, this should be the number of digits needed to
  643. represent a precision of 10\u\s-3\fIs\fP\s+3\d.
  644. .P
  645. For
  646. .BR obase
  647. values from 2 to 16, valid digits are the first
  648. .BR obase
  649. of the single characters:
  650. .sp
  651. .RS 4
  652. .nf
  653. 0 1 2 3 4 5 6 7 8 9 A B C D E F
  654. .fi
  655. .P
  656. .RE
  657. .P
  658. which represent the values zero to 15, inclusive, respectively.
  659. .P
  660. For bases greater than 16, each digit shall be written as a separate
  661. multi-digit decimal number. Each digit except the most significant
  662. fractional digit shall be preceded by a single
  663. <space>.
  664. For bases from 17 to 100,
  665. .IR bc
  666. shall write two-digit decimal numbers; for bases from 101 to 1\|000,
  667. three-digit decimal strings, and so on. For example, the decimal number
  668. 1\|024 in base 25 would be written as:
  669. .sp
  670. .RS 4
  671. .nf
  672. 01 15 24
  673. .fi
  674. .P
  675. .RE
  676. .P
  677. and in base 125, as:
  678. .sp
  679. .RS 4
  680. .nf
  681. 008 024
  682. .fi
  683. .P
  684. .RE
  685. .P
  686. Very large numbers shall be split across lines with 70 characters per
  687. line in the POSIX locale; other locales may split at different
  688. character boundaries. Lines that are continued shall end with a
  689. <backslash>.
  690. .P
  691. A function call shall consist of a function name followed by
  692. parentheses containing a
  693. <comma>-separated
  694. list of expressions, which are the function arguments. A whole array
  695. passed as an argument shall be specified by the array name followed
  696. by empty square brackets. All function arguments shall be passed by
  697. value. As a result, changes made to the formal parameters shall have no
  698. effect on the actual arguments. If the function terminates by executing a
  699. .BR return
  700. statement, the value of the function shall be the value of the
  701. expression in the parentheses of the
  702. .BR return
  703. statement or shall be zero if no expression is provided or if there is
  704. no
  705. .BR return
  706. statement.
  707. .P
  708. The result of
  709. .BR sqrt (\c
  710. .IR expression )
  711. shall be the square root of the expression. The result shall be
  712. truncated in the least significant decimal place. The scale of the
  713. result shall be the scale of the expression or the value of
  714. .BR scale ,
  715. whichever is larger.
  716. .P
  717. The result of
  718. .BR length (\c
  719. .IR expression )
  720. shall be the total number of significant decimal digits in the
  721. expression. The scale of the result shall be zero.
  722. .P
  723. The result of
  724. .BR scale (\c
  725. .IR expression )
  726. shall be the scale of the expression. The scale of the result shall be
  727. zero.
  728. .P
  729. A numeric constant shall be an expression. The scale shall be the
  730. number of digits that follow the radix point in the input representing
  731. the constant, or zero if no radix point appears.
  732. .P
  733. The sequence (\ \fIexpression\fP\ ) shall be an expression with the
  734. same value and scale as
  735. .IR expression .
  736. The parentheses can be used to alter the normal precedence.
  737. .P
  738. The semantics of the unary and binary operators are as follows:
  739. .IP "\-\fIexpression\fP" 6
  740. .br
  741. The result shall be the negative of the
  742. .IR expression .
  743. The scale of the result shall be the scale of
  744. .IR expression .
  745. .P
  746. The unary increment and decrement operators shall not modify the scale
  747. of the named expression upon which they operate. The scale of the
  748. result shall be the scale of that named expression.
  749. .IP "++\fInamed-expression\fP" 6
  750. .br
  751. The named expression shall be incremented by one. The result shall be
  752. the value of the named expression after incrementing.
  753. .IP "\-\|\-\fInamed-expression\fP" 6
  754. .br
  755. The named expression shall be decremented by one. The result shall be
  756. the value of the named expression after decrementing.
  757. .IP "\fInamed-expression\fP++" 6
  758. .br
  759. The named expression shall be incremented by one. The result shall be
  760. the value of the named expression before incrementing.
  761. .IP "\fInamed-expression\fP\-\|\-" 6
  762. .br
  763. The named expression shall be decremented by one. The result shall be
  764. the value of the named expression before decrementing.
  765. .P
  766. The exponentiation operator,
  767. <circumflex>
  768. (\c
  769. .BR '\(ha' ),
  770. shall bind right to left.
  771. .IP "\fIexpression\fP^\fIexpression\fP" 6
  772. .br
  773. The result shall be the first
  774. .IR expression
  775. raised to the power of the second
  776. .IR expression .
  777. If the second expression is not an integer, the behavior is undefined.
  778. If
  779. .IR a
  780. is the scale of the left expression and
  781. .IR b
  782. is the absolute value of the right expression, the scale of the result
  783. shall be:
  784. .RS 6
  785. .sp
  786. .RS 4
  787. .nf
  788. if b >= 0 min(a * b, max(scale, a)) if b < 0 scale
  789. .fi
  790. .P
  791. .RE
  792. .RE
  793. The multiplicative operators (\c
  794. .BR '*' ,
  795. .BR '/' ,
  796. .BR '%' )
  797. shall bind left to right.
  798. .IP "\fIexpression\fP*\fIexpression\fP" 6
  799. .br
  800. The result shall be the product of the two expressions. If
  801. .IR a
  802. and
  803. .IR b
  804. are the scales of the two expressions, then the scale of the result
  805. shall be:
  806. .RS 6
  807. .sp
  808. .RS 4
  809. .nf
  810. min(a+b,max(scale,a,b))
  811. .fi
  812. .P
  813. .RE
  814. .RE
  815. .IP "\fIexpression\fP/\fIexpression\fP" 6
  816. .br
  817. The result shall be the quotient of the two expressions. The scale of the
  818. result shall be the value of
  819. .BR scale .
  820. .IP "\fIexpression\fP%\fIexpression\fP" 6
  821. .br
  822. For expressions
  823. .IR a
  824. and
  825. .IR b ,
  826. .IR a %\c
  827. .IR b
  828. shall be evaluated equivalent to the steps:
  829. .RS 6
  830. .IP " 1." 4
  831. Compute
  832. .IR a /\c
  833. .IR b
  834. to current scale.
  835. .IP " 2." 4
  836. Use the result to compute:
  837. .RS 4
  838. .sp
  839. .RS 4
  840. .nf
  841. a - (a / b) * b
  842. .fi
  843. .P
  844. .RE
  845. .P
  846. to scale:
  847. .sp
  848. .RS 4
  849. .nf
  850. max(scale + scale(b), scale(a))
  851. .fi
  852. .P
  853. .RE
  854. .RE
  855. The scale of the result shall be:
  856. .sp
  857. .RS 4
  858. .nf
  859. max(scale + scale(b), scale(a))
  860. .fi
  861. .P
  862. .RE
  863. .P
  864. When
  865. .BR scale
  866. is zero, the
  867. .BR '%'
  868. operator is the mathematical remainder operator.
  869. .RE
  870. .P
  871. The additive operators (\c
  872. .BR '\(pl' ,
  873. .BR '\-' )
  874. shall bind left to right.
  875. .IP "\fIexpression\fP+\fIexpression\fP" 6
  876. .br
  877. The result shall be the sum of the two expressions. The scale of the
  878. result shall be the maximum of the scales of the expressions.
  879. .IP "\fIexpression\fP\-\fIexpression\fP" 6
  880. .br
  881. The result shall be the difference of the two expressions. The scale of
  882. the result shall be the maximum of the scales of the expressions.
  883. .P
  884. The assignment operators (\c
  885. .BR '=' ,
  886. .BR \(dq+=\(dq ,
  887. .BR \(dq-=\(dq ,
  888. .BR \(dq*=\(dq ,
  889. .BR \(dq/=\(dq ,
  890. .BR \(dq%=\(dq ,
  891. .BR \(dq\(ha=\(dq )
  892. shall bind right to left.
  893. .IP "\fInamed-expression\fP=\fIexpression\fP" 6
  894. .br
  895. This expression shall result in assigning the value of the expression
  896. on the right to the named expression on the left. The scale of both the
  897. named expression and the result shall be the scale of
  898. .IR expression .
  899. .P
  900. The compound assignment forms:
  901. .sp
  902. .RS 4
  903. .nf
  904. \fInamed-expression\fR <\fIoperator\fR>= \fIexpression\fR
  905. .fi
  906. .P
  907. .RE
  908. .P
  909. shall be equivalent to:
  910. .sp
  911. .RS 4
  912. .nf
  913. \fInamed-expression\fR=\fInamed-expression\fR <\fIoperator\fR> \fIexpression\fR
  914. .fi
  915. .P
  916. .RE
  917. .P
  918. except that the
  919. .IR named-expression
  920. shall be evaluated only once.
  921. .P
  922. Unlike all other operators, the relational operators (\c
  923. .BR '<' ,
  924. .BR '>' ,
  925. .BR \(dq<=\(dq ,
  926. .BR \(dq>=\(dq ,
  927. .BR \(dq==\(dq ,
  928. .BR \(dq!=\(dq )
  929. shall be only valid as the object of an
  930. .BR if ,
  931. .BR while ,
  932. or inside a
  933. .BR for
  934. statement.
  935. .IP "\fIexpression1\fP<\fIexpression2\fR" 6
  936. .br
  937. The relation shall be true if the value of
  938. .IR expression1
  939. is strictly less than the value of
  940. .IR expression2 .
  941. .IP "\fIexpression1\fP>\fIexpression2\fP" 6
  942. .br
  943. The relation shall be true if the value of
  944. .IR expression1
  945. is strictly greater than the value of
  946. .IR expression2 .
  947. .IP "\fIexpression1\fP<=\fIexpression2\fR" 6
  948. .br
  949. The relation shall be true if the value of
  950. .IR expression1
  951. is less than or equal to the value of
  952. .IR expression2 .
  953. .IP "\fIexpression1\fP>=\fIexpression2\fR" 6
  954. .br
  955. The relation shall be true if the value of
  956. .IR expression1
  957. is greater than or equal to the value of
  958. .IR expression2 .
  959. .IP "\fIexpression1\fP=\|=\fIexpression2\fR" 6
  960. .br
  961. The relation shall be true if the values of
  962. .IR expression1
  963. and
  964. .IR expression2
  965. are equal.
  966. .IP "\fIexpression1\fP!=\fIexpression2\fR" 6
  967. .br
  968. The relation shall be true if the values of
  969. .IR expression1
  970. and
  971. .IR expression2
  972. are unequal.
  973. .P
  974. There are only two storage classes in
  975. .IR bc :
  976. global and automatic (local).
  977. Only identifiers that are local to a function need be declared
  978. with the
  979. .BR auto
  980. command. The arguments to a function shall be local to the function.
  981. All other identifiers are assumed to be global and available to all
  982. functions. All identifiers, global and local, have initial values of
  983. zero. Identifiers declared as auto shall be allocated on entry to the
  984. function and released on returning from the function. They therefore do
  985. not retain values between function calls. Auto arrays shall be
  986. specified by the array name followed by empty square brackets. On entry
  987. to a function, the old values of the names that appear as parameters
  988. and as automatic variables shall be pushed onto a stack. Until the
  989. function returns, reference to these names shall refer only to the new
  990. values.
  991. .P
  992. References to any of these names from other functions that are called
  993. from this function also refer to the new value until one of those
  994. functions uses the same name for a local variable.
  995. .P
  996. When a statement is an expression, unless the main operator is an
  997. assignment, execution of the statement shall write the value of the
  998. expression followed by a
  999. <newline>.
  1000. .P
  1001. When a statement is a string, execution of the statement shall write
  1002. the value of the string.
  1003. .P
  1004. Statements separated by
  1005. <semicolon>
  1006. or
  1007. <newline>
  1008. characters shall be executed sequentially. In an interactive invocation of
  1009. .IR bc ,
  1010. each time a
  1011. <newline>
  1012. is read that satisfies the grammatical production:
  1013. .sp
  1014. .RS 4
  1015. .nf
  1016. input_item : semicolon_list NEWLINE
  1017. .fi
  1018. .P
  1019. .RE
  1020. .P
  1021. the sequential list of statements making up the
  1022. .BR semicolon_list
  1023. shall be executed immediately and any output produced by that execution
  1024. shall be written without any delay due to buffering.
  1025. .P
  1026. In an
  1027. .BR if
  1028. statement (\c
  1029. .BR if (\c
  1030. .IR relation )
  1031. .IR statement ),
  1032. the
  1033. .IR statement
  1034. shall be executed if the relation is true.
  1035. .P
  1036. The
  1037. .BR while
  1038. statement (\c
  1039. .BR while (\c
  1040. .IR relation )
  1041. .IR statement )
  1042. implements a loop in which the
  1043. .IR relation
  1044. is tested; each time the
  1045. .IR relation
  1046. is true, the
  1047. .IR statement
  1048. shall be executed and the
  1049. .IR relation
  1050. retested. When the
  1051. .IR relation
  1052. is false, execution shall resume after
  1053. .IR statement .
  1054. .P
  1055. A
  1056. .BR for
  1057. statement(\c
  1058. .BR for (\c
  1059. .IR expression ;
  1060. .IR relation ;
  1061. .IR expression )
  1062. .IR statement )
  1063. shall be the same as:
  1064. .sp
  1065. .RS 4
  1066. .nf
  1067. \fIfirst-expression\fP
  1068. while (\fIrelation\fP) {
  1069. \fIstatement\fP
  1070. \fIlast-expression\fR
  1071. }
  1072. .fi
  1073. .P
  1074. .RE
  1075. The application shall ensure that all three expressions are present.
  1076. .P
  1077. The
  1078. .BR break
  1079. statement shall cause termination of a
  1080. .BR for
  1081. or
  1082. .BR while
  1083. statement.
  1084. .P
  1085. The
  1086. .BR auto
  1087. statement (\c
  1088. .BR auto
  1089. .IR identifier
  1090. .BR [ ,\c
  1091. .IR identifier \c
  1092. .BR ]
  1093. \&.\|.\|.) shall cause the values of the identifiers to be pushed down.
  1094. The identifiers can be ordinary identifiers or array identifiers. Array
  1095. identifiers shall be specified by following the array name by empty
  1096. square brackets. The application shall ensure that the
  1097. .BR auto
  1098. statement is the first statement in a function definition.
  1099. .P
  1100. A
  1101. .BR define
  1102. statement:
  1103. .sp
  1104. .RS 4
  1105. .nf
  1106. define \fILETTER\fP ( \fIopt_parameter_list\fP ) {
  1107. \fIopt_auto_define_list\fP
  1108. \fIstatement_list\fR
  1109. }
  1110. .fi
  1111. .P
  1112. .RE
  1113. .P
  1114. defines a function named
  1115. .BR LETTER .
  1116. If a function named
  1117. .BR LETTER
  1118. was previously defined, the
  1119. .BR define
  1120. statement shall replace the previous definition. The expression:
  1121. .sp
  1122. .RS 4
  1123. .nf
  1124. LETTER ( \fIopt_argument_list\fR )
  1125. .fi
  1126. .P
  1127. .RE
  1128. .P
  1129. shall invoke the function named
  1130. .BR LETTER .
  1131. The behavior is undefined if the number of arguments in the invocation
  1132. does not match the number of parameters in the definition. Functions
  1133. shall be defined before they are invoked. A function shall be
  1134. considered to be defined within its own body, so recursive calls are
  1135. valid. The values of numeric constants within a function shall be
  1136. interpreted in the base specified by the value of the
  1137. .BR ibase
  1138. register when the function is invoked.
  1139. .P
  1140. The
  1141. .BR return
  1142. statements (\c
  1143. .BR return
  1144. and
  1145. .BR return (\c
  1146. .IR expression ))
  1147. shall cause termination of a function, popping of its auto variables,
  1148. and specification of the result of the function. The first form shall
  1149. be equivalent to
  1150. .BR return (0).
  1151. The value and scale of the result returned by the function shall be the
  1152. value and scale of the expression returned.
  1153. .P
  1154. The
  1155. .BR quit
  1156. statement (\c
  1157. .BR quit )
  1158. shall stop execution of a
  1159. .IR bc
  1160. program at the point where the statement occurs in the input, even if
  1161. it occurs in a function definition, or in an
  1162. .BR if ,
  1163. .BR for ,
  1164. or
  1165. .BR while
  1166. statement.
  1167. .P
  1168. The following functions shall be defined when the
  1169. .BR \-l
  1170. option is specified:
  1171. .IP "\fBs\fR(\ \fIexpression\fR\ )" 6
  1172. .br
  1173. Sine of argument in radians.
  1174. .IP "\fBc\fR(\ \fIexpression\fR\ )" 6
  1175. .br
  1176. Cosine of argument in radians.
  1177. .IP "\fBa\fR(\ \fIexpression\fR\ )" 6
  1178. .br
  1179. Arctangent of argument.
  1180. .IP "\fBl\fR(\ \fIexpression\fR\ )" 6
  1181. .br
  1182. Natural logarithm of argument.
  1183. .IP "\fBe\fR(\ \fIexpression\fR\ )" 6
  1184. .br
  1185. Exponential function of argument.
  1186. .IP "\fBj\fR(\ \fIexpression1\fR,\ \fIexpression2\fR\ )" 6
  1187. .br
  1188. Bessel function of
  1189. .IR expression2
  1190. of the first kind of integer order
  1191. .IR expression1 .
  1192. .P
  1193. The scale of the result returned by these functions shall be the value
  1194. of the
  1195. .BR scale
  1196. register at the time the function is invoked. The value of the
  1197. .BR scale
  1198. register after these functions have completed their execution shall be
  1199. the same value it had upon invocation. The behavior is undefined if
  1200. any of these functions is invoked with an argument outside the domain
  1201. of the mathematical function.
  1202. .SH "EXIT STATUS"
  1203. The following exit values shall be returned:
  1204. .IP 0 10
  1205. All input files were processed successfully.
  1206. .IP "\fIunspecified\fR" 10
  1207. An error occurred.
  1208. .SH "CONSEQUENCES OF ERRORS"
  1209. If any
  1210. .IR file
  1211. operand is specified and the named file cannot be accessed,
  1212. .IR bc
  1213. shall write a diagnostic message to standard error and terminate
  1214. without any further action.
  1215. .P
  1216. In an interactive invocation of
  1217. .IR bc ,
  1218. the utility should print an error message and recover following any
  1219. error in the input. In a non-interactive invocation of
  1220. .IR bc ,
  1221. invalid input causes undefined behavior.
  1222. .LP
  1223. .IR "The following sections are informative."
  1224. .SH "APPLICATION USAGE"
  1225. Automatic variables in
  1226. .IR bc
  1227. do not work in exactly the same way as in either C or PL/1.
  1228. .P
  1229. For historical reasons, the exit status from
  1230. .IR bc
  1231. cannot be relied upon to indicate that an error has occurred.
  1232. Returning zero after an error is possible. Therefore,
  1233. .IR bc
  1234. should be used primarily by interactive users (who can react to error
  1235. messages) or by application programs that can somehow validate the
  1236. answers returned as not including error messages.
  1237. .P
  1238. The
  1239. .IR bc
  1240. utility always uses the
  1241. <period>
  1242. (\c
  1243. .BR '.' )
  1244. character to represent a radix point, regardless of any decimal-point
  1245. character specified as part of the current locale. In languages like C or
  1246. .IR awk ,
  1247. the
  1248. <period>
  1249. character is used in program source, so it can be portable and
  1250. unambiguous, while the locale-specific character is used in input and
  1251. output. Because there is no distinction between source and input in
  1252. .IR bc ,
  1253. this arrangement would not be possible. Using the locale-specific
  1254. character in
  1255. .IR bc 's
  1256. input would introduce ambiguities into the language; consider the
  1257. following example in a locale with a
  1258. <comma>
  1259. as the decimal-point character:
  1260. .sp
  1261. .RS 4
  1262. .nf
  1263. define f(a,b) {
  1264. ...
  1265. }
  1266. \&...
  1267. .P
  1268. f(1,2,3)
  1269. .fi
  1270. .P
  1271. .RE
  1272. .P
  1273. Because of such ambiguities, the
  1274. <period>
  1275. character is used in input. Having input follow different conventions
  1276. from output would be confusing in either pipeline usage or interactive
  1277. usage, so the
  1278. <period>
  1279. is also used in output.
  1280. .SH EXAMPLES
  1281. In the shell, the following assigns an approximation of the first ten
  1282. digits of
  1283. .BR '\(*p'
  1284. to the variable
  1285. .IR x :
  1286. .sp
  1287. .RS 4
  1288. .nf
  1289. x=$(printf "%s\en" \(aqscale = 10; 104348/33215\(aq | bc)
  1290. .fi
  1291. .P
  1292. .RE
  1293. .P
  1294. The following
  1295. .IR bc
  1296. program prints the same approximation of
  1297. .BR '\(*p' ,
  1298. with a label, to standard output:
  1299. .sp
  1300. .RS 4
  1301. .nf
  1302. scale = 10
  1303. "pi equals "
  1304. 104348 / 33215
  1305. .fi
  1306. .P
  1307. .RE
  1308. .P
  1309. The following defines a function to compute an approximate value of the
  1310. exponential function (note that such a function is predefined if the
  1311. .BR \-l
  1312. option is specified):
  1313. .sp
  1314. .RS 4
  1315. .nf
  1316. scale = 20
  1317. define e(x){
  1318. auto a, b, c, i, s
  1319. a = 1
  1320. b = 1
  1321. s = 1
  1322. for (i = 1; 1 == 1; i++){
  1323. a = a*x
  1324. b = b*i
  1325. c = a/b
  1326. if (c == 0) {
  1327. return(s)
  1328. }
  1329. s = s+c
  1330. }
  1331. }
  1332. .fi
  1333. .P
  1334. .RE
  1335. .P
  1336. The following prints approximate values of the exponential function of
  1337. the first ten integers:
  1338. .sp
  1339. .RS 4
  1340. .nf
  1341. for (i = 1; i <= 10; ++i) {
  1342. e(i)
  1343. }
  1344. .fi
  1345. .P
  1346. .RE
  1347. .SH RATIONALE
  1348. The
  1349. .IR bc
  1350. utility is implemented historically as a front-end processor for
  1351. .IR dc ;
  1352. .IR dc
  1353. was not selected to be part of this volume of POSIX.1\(hy2017 because
  1354. .IR bc
  1355. was thought to have a more intuitive programmatic interface. Current
  1356. implementations that implement
  1357. .IR bc
  1358. using
  1359. .IR dc
  1360. are expected to be compliant.
  1361. .P
  1362. The exit status for error conditions has been left unspecified for
  1363. several reasons:
  1364. .IP " *" 4
  1365. The
  1366. .IR bc
  1367. utility is used in both interactive and non-interactive situations.
  1368. Different exit codes may be appropriate for the two uses.
  1369. .IP " *" 4
  1370. It is unclear when a non-zero exit should be given; divide-by-zero,
  1371. undefined functions, and syntax errors are all possibilities.
  1372. .IP " *" 4
  1373. It is not clear what utility the exit status has.
  1374. .IP " *" 4
  1375. In the 4.3 BSD, System V, and Ninth Edition implementations,
  1376. .IR bc
  1377. works in conjunction with
  1378. .IR dc .
  1379. The
  1380. .IR dc
  1381. utility is the parent,
  1382. .IR bc
  1383. is the child. This was done to cleanly terminate
  1384. .IR bc
  1385. if
  1386. .IR dc
  1387. aborted.
  1388. .P
  1389. The decision to have
  1390. .IR bc
  1391. exit upon encountering an inaccessible input file is based on the
  1392. belief that
  1393. .IR bc
  1394. .IR file1
  1395. .IR file2
  1396. is used most often when at least
  1397. .IR file1
  1398. contains data/function declarations/initializations. Having
  1399. .IR bc
  1400. continue with prerequisite files missing is probably not useful. There
  1401. is no implication in the CONSEQUENCES OF ERRORS section that
  1402. .IR bc
  1403. must check all its files for accessibility before opening any of them.
  1404. .P
  1405. There was considerable debate on the appropriateness of the language
  1406. accepted by
  1407. .IR bc .
  1408. Several reviewers preferred to see either a pure subset of the C
  1409. language or some changes to make the language more compatible with C.
  1410. While the
  1411. .IR bc
  1412. language has some obvious similarities to C, it has never claimed to be
  1413. compatible with any version of C. An interpreter for a subset of C
  1414. might be a very worthwhile utility, and it could potentially make
  1415. .IR bc
  1416. obsolete. However, no such utility is known in historical practice, and
  1417. it was not within the scope of this volume of POSIX.1\(hy2017 to define such a language and
  1418. utility. If and when they are defined, it may be appropriate to include
  1419. them in a future version of this standard. This left the following
  1420. alternatives:
  1421. .IP " 1." 4
  1422. Exclude any calculator language from this volume of POSIX.1\(hy2017.
  1423. .RS 4
  1424. .P
  1425. The consensus of the standard developers was that a simple programmatic
  1426. calculator language is very useful for both applications and
  1427. interactive users. The only arguments for excluding any calculator were
  1428. that it would become obsolete if and when a C-compatible one emerged,
  1429. or that the absence would encourage the development of such a
  1430. C-compatible one. These arguments did not sufficiently address the
  1431. needs of current application developers.
  1432. .RE
  1433. .IP " 2." 4
  1434. Standardize the historical
  1435. .IR dc ,
  1436. possibly with minor modifications.
  1437. .RS 4
  1438. .P
  1439. The consensus of the standard developers was that
  1440. .IR dc
  1441. is a fundamentally less usable language and that that would be far too
  1442. severe a penalty for avoiding the issue of being similar to but
  1443. incompatible with C.
  1444. .RE
  1445. .IP " 3." 4
  1446. Standardize the historical
  1447. .IR bc ,
  1448. possibly with minor modifications.
  1449. .RS 4
  1450. .P
  1451. This was the approach taken. Most of the proponents of changing the
  1452. language would not have been satisfied until most or all of the
  1453. incompatibilities with C were resolved. Since most of the changes
  1454. considered most desirable would break historical applications and
  1455. require significant modification to historical implementations, almost
  1456. no modifications were made. The one significant modification that was
  1457. made was the replacement of the historical
  1458. .IR bc
  1459. assignment operators
  1460. .BR \(dq=+\(dq ,
  1461. and so on, with the more modern
  1462. .BR \(dq+=\(dq ,
  1463. and so on. The older versions are considered to be fundamentally flawed
  1464. because of the lexical ambiguity in uses like
  1465. .IR a =\-1.
  1466. .P
  1467. In order to permit implementations to deal with backwards-compatibility
  1468. as they see fit, the behavior of this one ambiguous construct was made
  1469. undefined. (At least three implementations have been known to support
  1470. this change already, so the degree of change involved should not be
  1471. great.)
  1472. .RE
  1473. .P
  1474. The
  1475. .BR '%'
  1476. operator is the mathematical remainder operator when
  1477. .BR scale
  1478. is zero. The behavior of this operator for other values of
  1479. .BR scale
  1480. is from historical implementations of
  1481. .IR bc ,
  1482. and has been maintained for the sake of historical applications despite
  1483. its non-intuitive nature.
  1484. .P
  1485. Historical implementations permit setting
  1486. .BR ibase
  1487. and
  1488. .BR obase
  1489. to a broader range of values. This includes values less than 2, which
  1490. were not seen as sufficiently useful to standardize. These
  1491. implementations do not interpret input properly for values of
  1492. .BR ibase
  1493. that are greater than 16. This is because numeric constants are
  1494. recognized syntactically, rather than lexically, as described in
  1495. \&this volume of POSIX.1\(hy2017. They are built from lexical tokens of single hexadecimal digits
  1496. and
  1497. <period>
  1498. characters. Since
  1499. <blank>
  1500. characters between tokens are not visible at the syntactic level, it is
  1501. not possible to recognize the multi-digit ``digits'' used in the higher
  1502. bases properly. The ability to recognize input in these bases was not
  1503. considered useful enough to require modifying these implementations.
  1504. Note that the recognition of numeric constants at the syntactic level
  1505. is not a problem with conformance to this volume of POSIX.1\(hy2017, as it does not impact the
  1506. behavior of conforming applications (and correct
  1507. .IR bc
  1508. programs). Historical implementations also accept input with all of the
  1509. digits
  1510. .BR '0' \-\c
  1511. .BR '9'
  1512. and
  1513. .BR 'A' \-\c
  1514. .BR 'F'
  1515. regardless of the value of
  1516. .BR ibase ;
  1517. since digits with value greater than or equal to
  1518. .BR ibase
  1519. are not really appropriate, the behavior when they appear is undefined,
  1520. except for the common case of:
  1521. .sp
  1522. .RS 4
  1523. .nf
  1524. ibase=8;
  1525. /* Process in octal base. */
  1526. \&...
  1527. ibase=A
  1528. /* Restore decimal base. */
  1529. .fi
  1530. .P
  1531. .RE
  1532. .P
  1533. In some historical implementations, if the expression to be written is
  1534. an uninitialized array element, a leading
  1535. <space>
  1536. and/or up to four leading 0 characters may be output before the
  1537. character zero. This behavior is considered a bug; it is unlikely that
  1538. any currently conforming application relies on:
  1539. .sp
  1540. .RS 4
  1541. .nf
  1542. echo \(aqb[3]\(aq | bc
  1543. .fi
  1544. .P
  1545. .RE
  1546. .P
  1547. returning 00000 rather than 0.
  1548. .P
  1549. Exact calculation of the number of fractional digits to output for a
  1550. given value in a base other than 10 can be computationally expensive.
  1551. Historical implementations use a faster approximation, and this is
  1552. permitted. Note that the requirements apply only to values of
  1553. .BR obase
  1554. that this volume of POSIX.1\(hy2017 requires implementations to support (in particular, not to
  1555. 1, 0, or negative bases, if an implementation supports them as an
  1556. extension).
  1557. .P
  1558. Historical implementations of
  1559. .IR bc
  1560. did not allow array parameters to be passed as the last parameter to a
  1561. function. New implementations are encouraged to remove this restriction
  1562. even though it is not required by the grammar.
  1563. .SH "FUTURE DIRECTIONS"
  1564. None.
  1565. .SH "SEE ALSO"
  1566. .IR "Section 1.3" ", " "Grammar Conventions",
  1567. .IR "\fIawk\fR\^"
  1568. .P
  1569. The Base Definitions volume of POSIX.1\(hy2017,
  1570. .IR "Chapter 8" ", " "Environment Variables",
  1571. .IR "Section 12.2" ", " "Utility Syntax Guidelines"
  1572. .\"
  1573. .SH COPYRIGHT
  1574. Portions of this text are reprinted and reproduced in electronic form
  1575. from IEEE Std 1003.1-2017, Standard for Information Technology
  1576. -- Portable Operating System Interface (POSIX), The Open Group Base
  1577. Specifications Issue 7, 2018 Edition,
  1578. Copyright (C) 2018 by the Institute of
  1579. Electrical and Electronics Engineers, Inc and The Open Group.
  1580. In the event of any discrepancy between this version and the original IEEE and
  1581. The Open Group Standard, the original IEEE and The Open Group Standard
  1582. is the referee document. The original Standard can be obtained online at
  1583. http://www.opengroup.org/unix/online.html .
  1584. .PP
  1585. Any typographical or formatting errors that appear
  1586. in this page are most likely
  1587. to have been introduced during the conversion of the source files to
  1588. man page format. To report such errors, see
  1589. https://www.kernel.org/doc/man-pages/reporting_bugs.html .