日期:2014-05-16 浏览次数:20733 次
原文:http://www.basicallytech.com/blog/index.php?/archives/23-command-line-calculations-using-bc.html
bc是一个在命令行使用的强大计算器,本文作者通过实例来介绍bc命令的使用,是你瞬间掌握bc的基本应用。
文末,作者还给出了通过bc计算5000位PI的命令来测定你的cpu性能
--------------------------
?
If like me, you do most of your work from the command-line, using vim to edit files, mutt for e-mails, cd/ls/mv/find/etc instead of a file manager, then you may get annoyed by having to fire up a GUI calculator to make (what may sometimes be) a single calculation.
One useful feature of calculating on the command-line is that you can see what you've typed. For instance, sometimes when I'm entering a long, complex calculation on a calculator (either the GUI or the solid, hold-in-your-hand type), I sometimes forget if I've actually typed in?all?those numbers or made the calculations in the right order. Maybe it's just me ...?
This article shows how to quickly perform standard calculations on the command line including addition, subtraction, multiplication, division, square root, powers, conversion from decimal to hex, decimal to binary, hex to decimal, and binary to decimal. It also briefly introduces using?bc
?in interactive mode and how to write files for use with?bc
?for frequently repeated operations. There is a mention of using Google for performing calulations. It finishes with a little challenge to test the power of your CPU.
Other advantages of using?bc
?include:
bc
?is included with (almost?) all Linux distros as standard, as well as (again, almost?) all Unices.bc
have up to 99 decimal digits before and after the decimal point. This limit has been greatly surpassed in GNU?bc
. I don't know what that limit is, but it's at least many, many tens of thousands. Certainly it's more than any GUI-based calculators (I've used) could accomodate.bc
?is a preprocessor for?
免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。