Linux calculator BC

Source: Internet
Author: User
Tags ibase mathematical functions posix

The BC Calculator is a calculator that comes with Linux and is easy to use.

OPTIONS
-H,--help
Print the usage and exit.

-I.,--interactive
Force interactive mode.

-L,--mathlib (commonly used, this entry will have some common mathematical functions can be used, trigonometric, log, E, etc.)
Define the standard math library.

-W,--warn
Give warnings for extensions to POSIX BC.

-S,--standard
Process exactly the POSIX BC language.

-Q,--quiet (after this entry, no that write welcome message)
Do not print the normal GNU BC welcome.

-V,--version
Print the version number and the copyright and quit.

1. BC

The operations that can be performed include:

+         -          *          /             %                   ^

Subtraction to find the remainder (modulus) of the second square


Note: In the floating point operation, or when the result has a floating point number, the decimal point should be set scale=2 to take two decimal places


2, Bc-l

In this way the calculator, you can use the inside of a lot of library of functions,

For example:

L (x): logarithm of base x on E

E (x): E x Time Square

L (2.71828)
.99999932734728200315
E (1)
2.71828182845904523536
E (2)
7.38905609893065022723


3. Using the BC Calculator via pipeline command

3.1 Usage 1

echo "2*3" | Bc
6

3.2 Usage 2

echo "2/3" |BC

0

echo "SCALE=2;2/3" |BC

.66

3.3 Usage 3 (binary conversion)

If Obase is not specified, the default conversion is 10 binary.

echo "Obase=2;ibase=10;3" |BC #10进制转化为2进制

11

echo "obase=10; ibase=16; F "|BC # Note 16 binary letters must be capitalized

Note: The obase option is placed before the IBase option, and the order cannot be reversed.

4. BC Execution File

Example: A statement that is an operation in a TEST.BC file

Cat TEST.BC #输出以下内容
scale=2
1+2
3*5
4/3
5%2
2^4


Cat TEST.BC | BC can execute the above statement

or BC TEST.BC

Execution Result:

3
15
1.33
0
16



Linux calculator BC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.