Bc (programming language): Difference between revisions

Content deleted Content added
No edit summary
Tags: Reverted Visual edit
m Reverted edits by 46.121.148.242 (talk) to last version by Ghettoblaster
Line 17:
| website =
}}
'''bc''', for ''basic calculator'' (often referred to as ''bench calculator''), is "''an [[Arbitrary-precision arithmetic|arbitrary-precision]] calculator language''" with syntax similar to the [[C (programming language)|C programming language]]. bc is typically used as either a mathematical scripting language or as an interactive mathematical shell.
because
 
==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.
'''Bc''' stands for "because" or "before count"
 
==History==
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.
bc t might seem crazy what I am 'bout to say
 
In 1991, [[POSIX]] rigorously defined and standardized bc. Three 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.
Sunshine she's here, you can take a break
 
==Implementations==
I'm a hot air balloon that could go to space
===POSIX bc===
The POSIX standardized bc language is traditionally written as a program in the [[dc (computer program)|dc]] programming language to provide a higher level of access to the features of the dc language without the complexities of dc's terse syntax.
 
In this form, the bc language contains single-letter [[variable (programming)|variable]], [[array data structure|array]] and [[function (programming)|function]] names and most standard arithmetic operators, as well as the familiar [[control-flow]] constructs (<code>'''if('''cond''')'''...</code>, <code>'''while('''cond''')'''...</code> and <code>'''for('''init''';'''cond''';'''inc''')'''...</code>) from C. Unlike C, an '''<code>if</code>''' clause may not be followed by an '''<code>else</code>'''.
With the air, like I don't care, baby by the way
 
Functions are defined using a '''<code>define</code>''' keyword, and values are returned from them using a '''<code>return</code>''' followed by the return value in parentheses. The '''<code>auto</code>''' keyword (optional in C) is used to declare a variable as local to a function.
Huh ('''BC''' I'm happy)
 
All numbers and variable contents are [[arbitrary-precision]] numbers whose precision (in decimal places) is determined by the global '''<code>scale</code>''' variable.
Clap along if you feel like a room without a roof
 
The [[base (exponentiation)|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.
('''BC''' I'm happy)
 
Output is generated by deliberately not assigning the result of a calculation to a variable.
Clap along if you feel like happiness is the truth
 
Comments may be added to bc code by use of the C '''<code>/*</code>''' and '''<code>*/</code>''' (start and end comment) symbols.
('''BC''' I'm happy)
 
Clap along if you know what happiness is to you
 
('''BC''' I'm happy)
 
Clap along if you feel like that's what you wanna do
 
Here come bad news talking this and that (Yeah)
 
Well give me all you got, don't hold back (Yeah)
 
Well I should probably warn you I'll be just fine (Yeah)
 
No offence to you don't waste your time
 
Here's why
 
Clap along if you feel like a room without a roof
 
('''BC''' I'm happy)
 
Clap along if you feel like happiness is the truth
 
('''BC''' I'm happy)
 
Clap along if you know what happiness is to you
 
('''BC''' I'm happy)
 
Clap along if you feel like that's what you wanna do
 
Uh, bring me down
 
Can't nothing, bring me down
 
My level's too high to bring me down
 
Can't nothing, bring me down, I said
 
Bring me down, can't nothing
 
Bring me down
 
My level's too high to bring me down
 
Can't nothing, bring me down, I said
 
Clap along if you feel like a room without a roof
 
('''BC''' I'm happy)
 
Clap along if you feel like happiness is the truth
 
(BCI 'm happy)
 
Clap along if you know what happiness is to you
 
(BC I'm happy)
 
Clap along if you feel like that's what you wanna do
 
Clap along if you feel like a room without a roof
 
(Because I'm happy)
 
Clap along if you feel like happiness is the truth
 
(Because I'm happy)
 
Clap along if you know what happiness is to you
 
(Because I'm happy)
 
Clap along if you feel like that's what you wanna do
 
Uh, bring me down (Happy, happy, happy, happy)
 
Can't nothing (Happy, happy, happy, happy)
 
Bring me down, my level's too high
 
To bring me down (Happy, happy, happy, happy)
 
Can't nothing (Happy, happy, happy, happy)
 
Bring me down, I said
 
Clap along if you feel like a room without a roof
 
(Because I'm happy)
 
Clap along if you feel like happiness is the truth
 
(Because I'm happy)
 
Clap along if you know what happiness is to you (ayy, ayy, ayy)
 
(Because I'm happy)
 
Clap along if you feel like that's what you wanna do
 
Clap along if you feel like a room without a roof
 
(Because I'm happy)
 
Clap along if you feel like happiness is the truth
 
(Because I'm happy)
 
Clap along if you know what happiness is to you (hey)
 
(Because I'm happy)
 
Clap along if you feel like that's what you wanna do
 
Come on
 
In 1991, [[POSIX]] rigorously defined and standardized bc. Three 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.
 
==Implementations==
'''"bc''' i asked you to"
 
====Mathematical operators====