我使用过的Linux命令之bc - 浮点计算器、进制转换
我使用过的Linux命令之bc - 浮点计算器、进制转换
本文链接:http://codingstandards.iteye.com/blog/793734?? (转载请注明出处)
用途说明Bash内置了对整数四则运算的支持,但是并不支持浮点运算,而bc命令可以很方便的进行浮点运算,当然整数运算也不再话下。手册页上说bc是An arbitrary precision calculator language,即
12
[root@localhost centos39]# echo "scale=7; 355/113" | bc
3.1415929
[root@localhost centos39]#
[root@rhel55 ~]# echo "ibase=16; FFFF" | bc
65535
[root@rhel55 ~]# echo "obase=16; 1000" | bc
3E8
[root@rhel55 ~]#
[root@rhel55 ~]# cat test.bc
123*321
123/321
scale=4;123/321
[root@rhel55 ~]# bc test.bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
39483
0
.3831
Ctrl+D
[root@rhel55 ~]#
[root@rhel55 ~]# cat test.bc | bc
39483
0
.3831
[root@rhel55 ~]#
先复习一下初中的知识:b表示三角形的底,h表示三角形的高,那么三角形的面积计算公式是b*h/2。
文件:area_of_triangle.sh
Runtime error (func=(main), adr=11): Function a not defined.
[root@web ~]# echo "scale=100; a(1)*4" | bc -l
3.141592653589793238462643383279502884197169399375105820974944592307\
8164062862089986280348253421170676
[root@web ~]#问题思考相关资料【1】乡下猫 LINUX技术博客? linux中的bc命令(简单好用的计算器)
【2】想象力的专栏 Linux下的计算器(bc、expr、dc、echo、awk)知多少?
【3】我是网管 Liunx学习笔记19--bc计算器
【4】LAMP China linux bc命令使用
?
返回 我使用过的Linux命令系列总目录
?