BC is an advanced tool for mathematical operations and contains a number of options for performing floating-point arithmetic and applying some advanced functions:
[Email protected] ~]# echo 3*2.12 | Bc6.36[[email protected] ~]# n=54[[email protected] ~]# m= ' echo ' $n *1.5 ' | BC ' [[email protected] ~]# echo $m 81.0[[email protected] ~]#
The other second-generation parameters can be placed in front of the specific operation to be performed, with a semicolon as the delimiter, passed to the BC by a pipe character.
Set Decimal precision:
Scale can set the number of digits after the decimal point. scale=2 is two digits after the decimal point is reserved.
[Email protected] ~]# echo "SCALE=2;17/8" | bc2.12
Binary conversions:
IBase is the number of inputs, and obase is the number of outputs. ( you can omit ibase when the input is decimal)
[[email protected] ~]# echo "obase=2; $no" |bc1010[[email protected] ~]# no=100[[email protected] ~]# echo "obase=2; $no" |b C1100100[[email protected] ~]# no=1100100[[email protected] ~]# echo "obase=10;ibase=2; $no" | bc100
Calculate squared and square roots:
[Email protected] ~]# echo "sqrt (9)" | BC//square root (square root) 3[[email protected] ~]# echo "4^2" | BC//square (SQ) 16
Advanced math Tools BC: decimal precision, binary conversion, square and square root calculation