Content deleted Content added
Danallen46 (talk | contribs) m →External links: added description |
Stevebroshar (talk | contribs) there is a language, but's primarily a program, a tool, software |
||
(26 intermediate revisions by 21 users not shown) | |||
Line 1:
{{Short description|Arbitrary-precision calculator supporting interactive and scripted use}}{{Not to be confused with|B programming language|C programming language}}{{more footnotes|date=June 2013}}
{{lowercase|title=bc programming language}}
{{Infobox software
Line 7:
| screenshot size =
| caption =
| developer = [[Robert Morris (cryptographer)|Robert Morris]] and [[Lorinda Cherry]] of [[Bell Labs]]
| released = {{Release year|df=yes|1975}}
| latest release version =
Line 17:
| website =
}}
'''bc''', for ''basic calculator''
==Overview==
A typical interactive usage is typing the command <code>bc</code> on a [[Unix]] [[Command-line interface#Command prompt|command prompt]] and entering a mathematical expression, such as {{code|(1 + 3) * 2}}, whereupon {{samp|8}} will be output. While bc can work with arbitrary precision, it actually defaults to zero digits after the decimal point, so the expression {{code|2/3}} yields {{samp|0}} (results are truncated, not rounded). This can surprise new bc users unaware of this fact. The {{code|-l}} option to bc sets the default ''scale'' (digits after the decimal point) to 20 and adds several additional mathematical functions to the language.
==History==
bc first appeared in [[Version 6 Unix]] in 1975.
In 1991, [[POSIX]] rigorously defined and standardized bc.
==Implementations==
Line 37:
All numbers and variable contents are [[arbitrary-precision]] numbers whose precision (in decimal places) is determined by the global '''<code>scale</code>''' variable.
The [[
Output is generated by deliberately not assigning the result of a calculation to a variable.
Line 80:
====="Missing" operators relative to C=====
The [[bitwise operation|bitwise]], [[Boolean logic|
& | ^ && ||
Line 98:
bc's standard math library (defined with the '''-l''' option) contains functions for calculating [[sine]], [[cosine]], [[arctangent]], [[natural logarithm]], the [[exponential function]] and the two parameter [[Bessel function]] ''J''. Most standard mathematical functions (including the other inverse trigonometric functions) can be constructed using these. See external links for implementations of many other functions.
{| class="wikitable"
|+The bc standard library<ref name=":0">{{
!bc command
!Function
Line 134:
===GNU bc===
GNU bc derives from the POSIX standard and includes many
GNU bc variables, arrays and function names may contain more than one character, some more operators have been included from C, and notably, an '''<code>if</code>''' clause may be followed by an '''<code>else</code>'''.
Line 202:
</syntaxhighlight>
With some necessary changes to accommodate bc's different syntax, and
<syntaxhighlight lang="bc">
Line 246:
* [https://web.archive.org/web/20090501204511/http://manpages.ubuntu.com/manpages/jaunty/en/man1/bc.1posix.html POSIX bc manual page]
* {{man|1|bc|Plan 9}}
* [http://plan9.bell-labs.com/7thEdMan/vol2/bc 7th Edition Unix bc manual page] {{Webarchive|url=https://web.archive.org/web/20061008193920/http://plan9.bell-labs.com/7thEdMan/vol2/bc |date=2006-10-08 }}
* [http://compilers.iecc.com/comparch/article/95-09-015 A comp.compilers article on the design and implementation of C-bc]
* [http://minnie.tuhs.org/cgi-bin/utree.pl?file=V6/usr/source/s1/bc.y 6th Edition Unix bc source code], the first release of bc, from May 1975, compiling bc syntax into dc syntax
* [http://ftp.gnu.org/gnu/bc/ GNU bc source code]
{{Refend}}
Line 255:
{{Wikibooks|Guide to Unix|Commands}}
* [https://doi.acm.org/10.1145/152923.152925 Dittmer, I. 1993. Error in Unix commands dc and bc for multiple-precision-arithmetic. SIGNUM Newsl. 28, 2 (Apr. 1993), 8–11.]
* [
* [https://www.gnu.org/software/bc/ GNU bc] (and an [http://alpha.gnu.org/gnu/bc/ alpha version]) from the Free Software Foundation
* [https://web.archive.org/web/20160222234922/http://gnuwin32.sourceforge.net/packages/bc.htm bc for Windows] from [[GnuWin32]]
* [https://
* [https://web.archive.org/web/20160304084708/http://x-bc.sourceforge.net/ X-bc] - A Graphical User Interface to bc
** [https://web.archive.org/web/20160304092132/http://x-bc.sourceforge.net/extensions_bc.html extensions.bc] - contains functions of trigonometry, exponential functions, functions of number theory and some mathematical constants
Line 264:
{{Unix commands}}
{{Plan 9 commands}}
[[Category:Software calculators]]
|