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