日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux bc 命令简单学习

發(fā)布時(shí)間:2023/12/9 linux 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux bc 命令简单学习 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1. bash里面能夠?qū)崿F(xiàn)比較簡單的四則運(yùn)算

echo $((10*20))

注意是 雙括號(hào)+ $ 地址符號(hào).?

2. 但是比較復(fù)雜的 可能就難以為繼了 比如不支持精度?

3. 所以這里面需要使用 bc 命令來執(zhí)行相關(guān)的操作.?

man 內(nèi)容:

usage: bc [options] [file ...]
-h --help print this usage and exit
-i --interactive force interactive mode
-l --mathlib use the predefined math routines
-q --quiet don't print initial banner
-s --standard non-standard bc constructs are errors
-w --warn warn about non-standard bc constructs
-v --version print version information and exit

4. 實(shí)現(xiàn)簡單的 測試:

使用 bc -l 進(jìn)入 計(jì)算界面:

比如我輸入的 sqrt(100) 就是計(jì)算100 的平方根了

但是我沒找到怎么去立方根

還可以計(jì)算 自然對數(shù)

比如:

l(10) 表示 以 e為底 10 的對數(shù) e(10) 表示 e 的10次方...

5. 但是這樣計(jì)算可能不太方便 也可以使用 管道命令執(zhí)行相應(yīng)的操作:

求直接三角形的 第三條邊的長度.

echo "ibase=10,obase=2,254" |bc -l -q

?

6. 或者是可以實(shí)現(xiàn) 進(jìn)制的轉(zhuǎn)換:

echo "ibase=10;obase=2;254" |bc -l -q

?

?7. 總結(jié)語法注意點(diǎn):

每個(gè)參數(shù) 使用 分號(hào) 分隔 可以使用 管道 也可以不使用管道.?

?

8. 數(shù)學(xué)函數(shù)

MATH LIBRARYIf bc is invoked with the -l option, a math library is preloaded and the default scale is set to 20. The math functions will calculate their results to the scale set at the time of their call. The math library defines the following functions:s (x) The sine of x, x is in radians.c (x) The cosine of x, x is in radians.a (x) The arctangent of x, arctangent returns radians.l (x) The natural logarithm of x.e (x) The exponential function of raising e to the value x.j (n,x)The Bessel function of integer order n of x.

so 可以顯示圓周率的 公式是?

echo "scale=10;a(1)*4" |bc -l -q

顯示自然對數(shù)的公式

echo "scale=10;e(1)" |bc -l -q

?

轉(zhuǎn)載于:https://www.cnblogs.com/jinanxiaolaohu/p/10637702.html

總結(jié)

以上是生活随笔為你收集整理的Linux bc 命令简单学习的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。