Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
コマンドライン電卓bcコマンド
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Osumi, Yusuke
July 19, 2020
Technology
840
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
コマンドライン電卓bcコマンド
「新しいLinuxの教科書」を読む会 オンライン #3
での発表資料です。
https://linuxbook.connpass.com/event/180887/
Osumi, Yusuke
July 19, 2020
More Decks by Osumi, Yusuke
See All by Osumi, Yusuke
本の紹介の補足
ozuma
1
430
gitサービス3兄弟
ozuma
0
430
簡体字は楽
ozuma
0
520
ソフトウェアは固定資産
ozuma
0
460
ASCIIコードの小話
ozuma
0
480
今いるディレクトリを消すとどうなる
ozuma
1
450
名前付きパイプ FIFO
ozuma
0
600
文章、作文技法 リモートワーク
ozuma
1
960
CentOSの今後のリリース(簡易説明)
ozuma
0
440
Other Decks in Technology
See All in Technology
IBC 2026 動画技術関連レポート / IBC 2026 Report
cyberagentdevelopers
PRO
2
440
Sinatra on PicoRuby ローカルでセルフホスト
bash0c7
0
110
Copilot Coworkで「みのるん式」やってみた
minorun365
PRO
2
1.6k
お客様の「やりたい」の先を見通す合意形成プロセス ~裏にある課題と不安を解きほぐすコツ~
yukakoseki
0
110
企画からFlutter実装まで、1つの機能を一貫して開発したプロセスと成果物
khiroyuki1003
1
160
内製アプリとClaudeスキルのセキュリティチェック、 Backlogの課題で回しています。
ayaka_egaaa
0
140
AI時代のエンジニアの情報発信〜個人の発信を組織の力に変える〜
ryo_kawamata
1
7.4k
新米を「売り越さない」、Aurora DSQLで作る在庫ゼロ死守の限定ドロップEC
yama3133
0
190
AI AgentによるEmbedded SREの取り組み
tgidgd
1
360
AIがGISを代替する日:〜すべてをAIが創る時代に、私たちがFOSS4Gに関わる意味〜
lehupa
1
210
レガシーコードに対する loop engineering的なAI開発プロセス導入について
kubell_hr
0
280
SSFの現在地 ― CAEP/RISCからAI Identityへ
oidfj
0
170
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Embracing the Ebb and Flow
colly
88
5.2k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.4k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
470
First, design no harm
axbom
PRO
2
1.4k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
930
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3.1k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
520
The Cost Of JavaScript in 2023
addyosmani
56
10k
Transcript
コマンドライン電卓 bc コマンド @ozuma5119 1 「新しいLinuxの教科書」を読む会 オンライン #3 2020/07/19
Linuxのコマンドラインで計算したい 2 3 + 7 = ? sin(π/2) = ?
(4.3)3 = ?
Linuxのコマンドラインで計算したい 3 • exprコマンド : expr 1 + 1 •
bashの算術式展開 $((1+1))) • bcコマンド : echo "1 + 1" | bc
基本的な四則演算:もちろんできる 4 $ bc bc 1.06.95 ..(略)... 1+1 2 1-1
0 2*3 6 赤文字が入力、黒文字が出力
基本的な四則演算:もちろんできる 5 $ bc bc 1.06.95 ..(略)... 1+1 2 1-1
0 2*3 6 ※割り算は注意 デフォルトでは小数点切り捨て なので、scaleでケタ数を指定する 2/3 0 scale=5 2/3 .66666 ↑ 小数点の最初の0は省略される (他のプログラミング言語でも 一般的) 赤文字が入力、黒文字が出力
シェルスクリプトで使うとき 6 $ echo "1 + 1" | bc 2
$ 計算式をechoなどでパイプで渡してあげれば良いだけ もうちょっとちゃんと言うと…… → bcコマンドは標準入力を算術式として評価し、計算結果を標準出力へ出力 する
数式をファイルに書いてもOK 7 $ cat math.txt (1+3+5+90)*3 $ bc < math.txt
297 ※標準入力に数式を与えている
for などあるのでプログラムも書けます 8 $ cat math2 for (i=1; i <
10; i++) { i^2 } $ bc < math2 1 4 9 16 25 36 49 64 81 i=1から9までの、 iの2乗を出力
ここからおまけ:高度な計算 9 bc -l オプションを付けて起動すると、数学ライブラリがロードされる。 これにより以下の関数が使える • s(x) : sin(x)
[正弦関数] • c(x) : cos(x) [余弦関数] • a(x) : arctan(x) (または tan-1(x)) [逆正接関数] • l(x) : log e (x) = ln(x) [自然対数] • e(x) : ex (eは自然対数の底) [自然指数関数] • j(n,x) : [n次ベッセル関数]
タンジェント tan(x) なんて軟弱なものはない 10 自分で作れるでしょ!! • tan(x) = sin(x)/cos(x) なので……
◦ t(x) = s(x)/c(x) ※ 三角関数・自然対数・指数関数exp・べき乗があれば、 世の中の関数はだいたい作れる
例題:急にコマンドラインで円周率が20ケタ必要になった!!!!! 11 どうする!
例題:急にコマンドラインで円周率が20ケタ必要になった!!!!! 12 1. tan(π/4) = 1 である 2. よって、tanの逆関数を4倍すれば円周率πが出てくる 45度
= π/4 tan(π/4) = b/a = 1 tan-1(1) = arctan(1) = π/4 よって、 4 * arctan(1) = π $ bc -l scale=20 4 * a(1) 3.14159265358979323844 a b