QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2335|回复: 5

请教bc怎么用

[复制链接]
发表于 2005-4-1 14:10:37 | 显示全部楼层 |阅读模式
听说在控制台下有个计算器 bc
可是不太清楚怎么用,不知道哪儿有比较具体的讲解

$ bc
3+5
8
3.0/2.0
1

不知道为什么3.0/2.0等于1, 而不是双精度?
发表于 2005-4-1 14:32:23 | 显示全部楼层
以前用过,不过今天刚网络重装了系统,居然发现bc命令没有了:(
回复

使用道具 举报

发表于 2005-4-2 11:12:01 | 显示全部楼层
设置精度
加入:
[code:1]scale=4[/code:1]
bc还可以简单的编程,自己还有诸如对数,平方之类的内建函数,其语法类似于C语言.具体的好象在info里面有.比如比较300的阶乘和100的300次方就可以通过bc的编程来完成.而在脚本里面,可以通过here文档的方式来使用bc命令.这个东西很强大的.
回复

使用道具 举报

发表于 2005-4-2 15:31:04 | 显示全部楼层
[quote:bc93f31219="watch_1394"]设置精度
加入:
[code:1]scale=4[/code:1]
bc还可以简单的编程,自己还有诸如对数,平方之类的内建函数,其语法类似于C语言.具体的好象在info里面有.比如比较300的阶乘和100的300次方就可以通过bc的编程来完成.而在脚本里面,可以通过here文档的方式来使用bc命令.这个东西很强大的.[/quote]
应该不错!
回复

使用道具 举报

 楼主| 发表于 2005-4-3 02:21:25 | 显示全部楼层
[quote:866d068cb0="watch_1394"]设置精度
加入:
[code:1]scale=4[/code:1]
bc还可以简单的编程,自己还有诸如对数,平方之类的内建函数,其语法类似于C语言.具体的好象在info里面有.比如比较300的阶乘和100的300次方就可以通过bc的编程来完成.而在脚本里面,可以通过here文档的方式来使用bc命令.这个东西很强大的.[/quote]

多谢!bc是可以编程的,a language,呵呵。有时候在字符模式下可以用来当计算器用。

NUMBERS
       The most basic element in bc is the number.  Numbers are arbitrary precision numbers.  This precision  is  both  in
       the integer part and the fractional part.  All numbers are represented internally in decimal and all computation is
       done in decimal.  (This version truncates results from divide and multiply operations.)  There are  two  attributes
       of numbers, the length and the scale.  The length is the total number of significant decimal digits in a number and
       the scale is the total number of decimal digits after the decimal point.  For example:
               .000001 has a length of 6 and scale of 6.
               1935.000 has a length of 7 and a scale of 3.

   VARIABLES
       Numbers are stored in two types of variables, simple variables and arrays.  Both simple variables and  array  vari-
       ables are named.  Names begin with a letter followed by any number of letters, digits and underscores.  All letters
       must be lower case.  (Full alpha-numeric names are an extension. In POSIX bc all names are a single lower case let-
       ter.)   The  type of variable is clear by the context because all array variable names will be followed by brackets
       ([]).

       There are four special variables, scale, ibase, obase, and last.  scale defines  how  some  operations  use  digits
       after the decimal point.  The default value of scale is 0. ibase and obase define the conversion base for input and
       output numbers.  The default for both input and output is base 10.  last (an extension) is a variable that has  the
       value of the last printed number.  These will be discussed in further detail where appropriate.  All of these vari-
       ables may have values assigned to them as well as used in expressions.
回复

使用道具 举报

发表于 2005-4-3 10:33:18 | 显示全部楼层
不错:)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-10-6 13:33 , Processed in 0.040141 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表