ser*_*nni 11 command-line calculator bc
我刚刚找到了一个很好的命令行计算器程序bc并且对它很满意,直到我发现它对小数值进行四舍五入,从而导致精度损失。
根据其man页面:
所有数字在内部均以十进制表示,所有计算均以十进制完成。(此版本截断了除法和乘法运算的结果。)
您能否为 Ubuntu Maverick推荐一个等效的bc?我需要使用变量进行高级命令行计算。
Lek*_*eyn 13
您可以使用 设置小数部分的长度scale=n。
该命令echo 'scale=20;752/447' | bc产生:
1.68232662192393736017
Run Code Online (Sandbox Code Playgroud)
请注意,即使数字符合比例,也可能会附加额外的零:
scale=20
1/2
.50000000000000000000
Run Code Online (Sandbox Code Playgroud)
不幸的是,总是有一个舍入问题:
scale=50
1/3*3
.99999999999999999999999999999999999999999999999999
Run Code Online (Sandbox Code Playgroud)
calc(我相信来自 package apcalc)的作用与 相同bc,但不圆。它的显示类似于bc,但与 不同bc,它理解科学记数法。例子:
> calc
C-style arbitrary precision calculator (version 2.12.3.3)
Calc is open software. For license details type: help copyright
[Type "exit" to exit, or "help" for help.]
; a=234
; b=a/7
; b
~33.42857142857142857143
; c=b/1e20
; c
~0.00000000000000000033
; c*1e10
~0.00000000334285714286
;
Run Code Online (Sandbox Code Playgroud)
比较bc:
> bc -l
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
a=234
b=a/7
b
33.42857142857142857142
c=b/10^20
c
.00000000000000000033
c*1e10
(standard_in) 6: syntax error
c*10^10
.00000000330000000000
Run Code Online (Sandbox Code Playgroud)
稍微搜索一下就会出现很多结果,并非所有结果都是相关的,但我相信一些试验会得到你想要的结果(例如 wcalc):
aptitude search calc
i apcalc - Arbitrary precision calculator (original name: calc)
i A apcalc-common - Arbitrary precision calculator (common files)
p apcalc-dev - Library for arbitrary precision arithmetic
p bandwidthcalc - file transfer time calculator written in GTK+
p calcoo - Scientific calculator (GTK+)
p calcurse - text-based calendar and todo manager
p concalc - console calculator
p extcalc - multifunctional scientific graphic calculator
p gcalcli - Google Calendar Command Line Interface
i gcalctool - GNOME desktop calculator
p ipcalc - parameter calculator for IPv4 addresses
p ipv6calc - small utility for manipulating IPv6 addresses
p kcalc - calculator for KDE 4
p keurocalc - universal currency converter and calculator - binary package
p keurocalc-data - universal currency converter and calculator - data package
p lcalc - a program for calculating with L-functions
p libcolor-calc-perl - Perl module for simple calculations with RGB colors
p libdate-calc-perl - Perl library for accessing dates
p libdate-pcalc-perl - Perl module for Gregorian calendar date calculations
p libmath-basecalc-perl - Convert numbers between various bases
p libmath-calc-units-perl - Human-readable unit-aware calculator
p libmath-calculus-differentiate-perl - Algebraic Differentiation Engine
p libmath-calculus-expression-perl - Algebraic Calculus Tools Expression Class
p libmath-calculus-newtonraphson-perl - Algebraic Newton Raphson Implementation
p libticalcs-dev - Texas Instruments calculator communication library [development files]
p libticalcs2-7 - Texas Instruments calculator communication library
p libwww-google-calculator-perl - Perl interface for Google calculator
p octave-physicalconstants - provide physical constants values in Octave
i openoffice.org-calc - office productivity suite -- spreadsheet
v openoffice.org2-calc -
p python-ipcalc - perform IP subnet calculations
v python2.6-ipcalc -
p r-cran-epicalc - GNU R Epidemiological calculator
p rpncalc - RPN calculator trying to emulate an HP28S
p science-numericalcomputation - Debian Science Numerical Computation packages
p sipcalc - Advanced console-based ip subnet calculator
p subnetcalc - IPv4/IPv6 Subnet Calculator
p sugar-calculate-activity - calculate activity for the Sugar graphical shell
p tapecalc - a full-screen tape editor that lets the user edit a calculation
p transcalc - microwave and RF transmission line calculator
p wcalc - A flexible command-line scientific calculator
p wmcalclock - A dock.app which simply tells time and date
p xsmc-calc - Smith Chart calculator for X
Run Code Online (Sandbox Code Playgroud)
我建议使用 Python 作为命令行计算器:
$ python
>>> from math import *
>>> help(sin)
sin(x)
Return the sine of x (measured in radians).
Run Code Online (Sandbox Code Playgroud)
我也推荐 IPython 或 IDLE。两者都极大地提高了标准外壳的可用性。
更新:使用 python3 避免截断意外:
$ python2.7
>>> 10/3
3
$ python3
>>> 10/3
3.3333333333333335
Run Code Online (Sandbox Code Playgroud)
在这个意义上你失去了精度:如果将精度设置为 10 位十进制数字,则除法将被截断为 10 位十进制数字,这是一个连贯的选择。
如果您要寻找精确的计算器,则需要一个符号系统,如maxima.
顺便说一下,bc支持变量。
小智 5
“genius”是最先进的计算器,提供命令行和 GUI 选项。查看手册了解详细信息,并查看http://www.jirka.org/genius.html。
要安装,只需键入:
sudo apt-get install genius gnome-genius
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5517 次 |
| 最近记录: |