Bc (programming language): Difference between revisions

Content deleted Content added
there is a language, but's primarily a program, a tool, software
 
(10 intermediate revisions by 9 users not shown)
Line 1:
{{Short description|UNIXArbitrary-precision utilitycalculator whichsupporting implementsinteractive an arbitrary-precisionand arithmeticscripted languageuse}}{{Not to be confused with|B programming language|C programming language}}{{more footnotes|date=June 2013}}
{{lowercase|title=bc programming language}}
{{Infobox software
Line 17:
| website =
}}
'''bc''', for ''basic calculator'', is "an [[Arbitrary-precision arithmetic|arbitrary-precision]] [[math]]ematical [[calculator]] language"[[computer program|program]] with syntaxan input language similar to the [[C (programming language)|C programming language]]. bcIt issupports typicallyboth usedinteractive, as[[command-line eitherinterface|command-line]] a mathematical scripting language[[user-interface]] or as an interactiveand mathematicalscript shellprocessing.
 
==Overview==
Line 25:
bc first appeared in [[Version 6 Unix]] in 1975. It was written by [[Lorinda Cherry]] of [[Bell Labs]] as a front end to [[dc (computer program)|dc]], an arbitrary-precision calculator written by [[Robert Morris (cryptographer)|Robert Morris]] and Cherry. dc performed arbitrary-precision computations specified in [[reverse Polish notation]]. bc provided a conventional programming-language interface to the same capability via a simple [[compiler]] (a single [[yacc]] source file comprising a few hundred lines of code), which converted a [[C (programming language)|C]]-like syntax into dc notation and [[Pipeline (Unix)|piped]] the results through dc.
 
In 1991, [[POSIX]] rigorously defined and standardized bc. ThreeFour implementations of this standard survive today: The first is the traditional Unix implementation, a front-end to dc, which survives in Unix and [[Plan 9 from Bell Labs|Plan 9]] systems. The second is the [[free software]] [[GNU]] bc, first released in 1991 by Philip A. Nelson. The GNU implementation has numerous extensions beyond the POSIX standard and is no longer a front-end to dc (it is a [[bytecode interpreter]]). The third is a re-implementation by [[OpenBSD]] in 2003. The fourth is an independent implementation by Gavin Howard<ref name=":1">[https://git.gavinhoward.com/gavin/bc An implementation of Unix dc and POSIX bc with GNU and BSD extensions]</ref> that is included in [[Android (operating system)]],<ref name=":2">{{Cite web|url=https://android.googlesource.com/platform/system/core/+/master/shell_and_utilities/README.md|title=Android's shell and utilities|website=android.googlesource.com}}</ref><ref name=":3">{{cite web | url=https://android.googlesource.com/platform/external/bc/ | title=Platform/External/Bc - Git at Google }}</ref> [[FreeBSD]] as of 13.3-RELEASE,<ref name=":4">{{Cite web|url=https://forums.freebsd.org/threads/freebsd-13-3-whats-new-and-how-did-we-get-here.92596/|title=FreeBSD 13.3: What's new, and how did we get here?|date=March 5, 2024|website=The FreeBSD Forums}}</ref><ref name=":5">{{Cite web|url=https://man.freebsd.org/cgi/man.cgi?query=bc&apropos=0&sektion=1&manpath=FreeBSD+14.1-RELEASE&arch=default&format=html|title=bc(1)|website=man.freebsd.org}}</ref><ref name=":6">{{Cite web|url=https://cgit.freebsd.org/src/tree/contrib/bc|title=bc « contrib - src - FreeBSD source tree|website=cgit.freebsd.org}}</ref> and [[macOS]] as of 13.0.<ref name=":7">{{Cite web|url=https://opensource.apple.com/releases/|title=Apple Open Source|website=opensource.apple.com}}</ref><ref name=":8">{{Cite web|url=https://github.com/apple-oss-distributions/bc/tree/main/bc|title=bc/bc at main · apple-oss-distributions/bc|website=GitHub}}</ref><ref name=":9">{{cite web | url=https://gavinhoward.com/2023/02/my-code-conquered-another-os/ | title=My Code Conquered Another OS! &#124; Gavin D. Howard }}</ref>
 
==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 [[base (exponentiation)radix|numeric base]] of input (in interactive mode), output and program constants may be specified by setting the reserved '''<code>ibase</code>''' (input base) and '''<code>obase</code>''' (output base) variables.
 
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|booleanBoolean]] and [[conditional (programming)|conditional]] operators:
 
& | ^ && ||
Line 134:
 
===GNU bc===
GNU bc derives from the POSIX standard and includes many enhancementsextensions. It is entirely separate from dc-based implementations of the POSIX standard and is instead written in C. Nevertheless, it is fully backwards compatible as all POSIX bc programs will run unmodified as GNU bc programs.
 
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 258:
* [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://git.yzenagithub.com/gavingavinhoward/bc Gavin Howard bc] - another open source implementation of bc by Gavin Howard with GNU and BSD extensions
* [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