Shell floating point arithmetic tool BC

Source: Internet
Author: User
Tags arithmetic ibase logical operators

Shell floating point arithmetic tool BC

BC supports floating-point numbers, which is an advanced tool for mathematical operations.

[[Email protected] Desktop]# BC

BC 1.06

Copyright 1991-1994, 1997, 1998, Free Software Foundation, Inc.

This is the free software with absolutely NO WARRANTY.

For details type ' warranty '.

2+3

5

3.5*2.3

8.0

Ctrl+d exit

Of course, BC also supports many operators, such as/*-+. also supports variables, conditional comparison operators, logical operators, judgment statements, and loop statements.

A=1

while (a++<100)

Sum+=a

Sum

5049

1. Set the decimal precision, using the parameter scale.

[Email protected] Desktop]# echo "SCALE=5;3/21" | Bc

.14285

[Email protected] Desktop]# echo "SCALE=2;3/21" | Bc

.14

2. Binary conversion, using parameter Obase,ibase (indicating output, input using what binary)

[[Email protected] Desktop]# william=100;echo "obase=2; $william" | Bc

1100100

[[Email protected] Desktop]# william=100;echo "obase=10;ibase=2; $william" | Bc

4

[[Email protected] Desktop]# william=100;echo "obase=10;ibase=5; $william" | Bc

25

3. Calculate the square and root of the peace

[Email protected] Desktop]# echo "sqrt (100)" | Bc

10

[Email protected] Desktop]# echo "10^10" | Bc

10000000000

    • This article is from: Linux Learning Network

Shell floating point arithmetic tool BC

Related Article

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.