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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux bc 命令简单学习

發布時間:2023/12/9 linux 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux bc 命令简单学习 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. bash里面能夠實現比較簡單的四則運算

echo $((10*20))

注意是 雙括號+ $ 地址符號.?

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

3. 所以這里面需要使用 bc 命令來執行相關的操作.?

man 內容:

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. 實現簡單的 測試:

使用 bc -l 進入 計算界面:

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

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

還可以計算 自然對數

比如:

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

5. 但是這樣計算可能不太方便 也可以使用 管道命令執行相應的操作:

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

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

?

6. 或者是可以實現 進制的轉換:

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

?

?7. 總結語法注意點:

每個參數 使用 分號 分隔 可以使用 管道 也可以不使用管道.?

?

8. 數學函數

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

顯示自然對數的公式

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

?

轉載于:https://www.cnblogs.com/jinanxiaolaohu/p/10637702.html

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。