Bc
'''bc''' ("basic calculator") is the standard calculator for Unix systems.
bc boasts unlimited precision, to handle numbers with very many digits.
With the bc language, you can write programs that perform numeric calculations and print the results.
;See also :
- Bc programming language on Wikipedia
- dc - the unix '''d'''esktop '''c'''alculator.
bc has an interactive mode, which is convenient for brief calculations:
$ '''bc''' '''2 + 3''' 5 '''2 ^ 200''' 1606938044258990275541962092341162602522202993782792835301376 '''i = -5''' '''3 - i * 4''' 23 '''obase = 2''' '''i''' -101 '''ibase = 16''' '''FE80''' 1111111010000000
Division and sqrt will not give an infinite number of digits.
The special variable scale controls when to stop.
$ '''bc''' '''65.9 / 3''' 21 '''scale = 6''' '''65.9 / 3''' 21.966666 '''sqrt(2)''' 1.414213 '''scale = 60''' '''sqrt(2)''' 1.414213562373095048801688724209698078569671875376948073176679
bc language resembles C language: bc has most of the same operators and control structures ('if', 'while', 'for').
Expressions print themselves, unless they are assignments.
The newline is a statement separator, like the semicolon.
bc has excellent numeric operations, but is a poor language. The original bc, the "Bell Calculator" of Unix V7, translated the program to dc and inherited the limitations of dc.
- Names of variables, and custom functions, may have only one letter.
- There is no 'else' branch of an 'if' statement.
- Relational operators (== <= => != < >) only work in the condition of an 'if', 'while' or 'for' statement.
- There are no boolean operators (! && ||).
Some newer implementations, like GNU bc and OpenBSD bc, discard these silly limitations, but users can still feel their effects.
OpenBSD says, "a = b < c is interpreted as "(a = b) < c, which is probably not what the programmer intended," and "!a < b is interpreted as !(a < b)".
bc can only print a string, and has no other string operations, so bc cannot do tasks like reverse a string.
bc has no way to read user input, except to go to interactive mode after loading a program.
Category:Mathematical programming languages Category:Utility
Tasks
- 100 doors
- A+B
- Ackermann function
- Arbitrary-precision integers (included)
- Arithmetic-geometric mean
- Arithmetic/Integer
- Arrays
- Averages/Arithmetic mean
- Binary digits
- Boolean values
- Case-sensitivity of identifiers
- Collections
- Comments
- Count in octal
- Day of the week
- Decimal floating point number to binary
- Dot product
- Empty program
- Even or odd
- Extreme floating point values
- Factorial
- Factors of an integer
- Fibonacci sequence
- FizzBuzz
- Formatted numeric output
- Function definition
- Gray code
- Greatest common divisor
- Greatest element of a list
- Hamming numbers
- Hello world!
- Hello world/Newline omission
- Hello world/Text
- Holidays related to Easter
- Integer comparison
- Integer sequence
- Interactive programming
- Langton's ant
- Least common multiple
- Linear congruential generator
- Literals/Floating point
- Literals/Integer
- Literals/String
- Logical operations
- Loops/Break
- Loops/Continue
- Loops/Do-while
- Loops/Downward for
- Loops/For
- Loops/For with a specified step
- Loops/Foreach
- Loops/Infinite
- Loops/N plus one half
- Loops/Nested
- Loops/While
- Luhn test of credit card numbers
- Magic squares of odd order
- Map range
- Miller–Rabin primality test
- Mutual recursion
- Non-decimal radices/Output
- Nth root
- Operator precedence
- Pi
- Primality by trial division
- Real constants and functions
- Sailors, coconuts and a monkey problem
- Scope modifiers
- Scope/Function names and labels
- Sequence of non-squares
- Shell one-liner
- Special characters
- Special variables
- Sum and product of an array
- Sum digits of an integer
- Sum multiples of 3 and 5
- Sum of a series
- Sum of squares
- Terminal control/Display an extended character
- Terminal control/Ringing the terminal bell
- Trigonometric functions
- Van der Corput sequence
- Variadic function
- Zero to the zero power