s_calc 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +259 -0
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b8924787e8063de71591ef8d27a80409c83501541f3655579c0a8f752413591
4
- data.tar.gz: d5c519b8a89625d79373d4ad746a32948a67d3b39371fa1e971b9e329fd5c9a9
3
+ metadata.gz: 71bbe1e1641fd9021338663ad0132482fcb95420895e9188faafb9de9cf612b3
4
+ data.tar.gz: 506bd735892ca62beb09a554488318c2142f831d84fdce3013b5c3591a3d6dd8
5
5
  SHA512:
6
- metadata.gz: fe76534909fec3399535543882dd60b3cdb6125aa726be62d4cf514be0aaa34a10e2dbc0fa1b9949ab8efc98869b4612cf671a6cefef3cd4ffc15d41113f98a6
7
- data.tar.gz: d4af52b54d205cc25611d8d49cb7bf893df18033c2b04d0a5e992c37a5de3753f8a0467903723f86c37ab009fd6f26a1e36dd069a86c0faf7828a94cb90744de
6
+ metadata.gz: 2ebefdecfa7fd99ce1a3726ebe89dda31f1eadf27c72180fc182baad1f109029382d63faedcd422d630e8e7d8aff4714faea63451beae9d652822642f57e9f8e
7
+ data.tar.gz: 53bd32713d1c421847f28e47ae883ad650f6a301910c174b624a03017002a79f9fcffe45c7a9e33f8731b151d729c0dcc58fe9467d83a2ea5714264dc48bc39a
data/README.md ADDED
@@ -0,0 +1,259 @@
1
+ 日本語の解説が後半にあります。
2
+
3
+ ### What is this program?
4
+
5
+ The program 'calc' is a scientific calculator written in Ruby programming language.
6
+ It is run from the command line like this.
7
+
8
+ ```
9
+ $ calc 2*3+4*5
10
+ 26
11
+ $ calc
12
+ calc > 0.1-0.2
13
+ -0.1
14
+ calc > sin(PI/6)
15
+ 0.49999999999999994 # Float always includes error.
16
+ calc > quit
17
+ $
18
+ ```
19
+
20
+ ### Prerequisites
21
+
22
+ - Linux OS
23
+ - Ruby 3.1.2 or later (maybe older version is also OK)
24
+
25
+ ### installation
26
+
27
+ There are two ways.
28
+
29
+ 1. Click the 'Code' button, then click 'Download ZIP' in the small dialog.
30
+ 2. Unzip the downloaded Zip file, then a new directory 'calc' will be created.
31
+ 3. Type `gem build s_calc` under the directory 'calc', then the gem file `s_calc-X.X.X.gem` is created.
32
+ The part `X.X.X` is a version number like `0.1.4`.
33
+ 4. Type `gem install s_calc-X.X.X.gem`.
34
+
35
+ Another way is simpler.
36
+ This gem is published to RubyGems.org.
37
+ You can install it from RubyGems.
38
+ Just type:
39
+
40
+ ```
41
+ $ gem install s_calc
42
+ ```
43
+
44
+ Be careful.
45
+ The command name and GitHub repository name is `calc` but the gem name is `s_calc`.
46
+ This is because the name `calc` has already existed in RubyGems.org.
47
+
48
+ ### How to use the program.
49
+
50
+ 1. Start the terminal and type `calc`.
51
+ 2. Then the prompt appears `calc > `
52
+ 3. Type an expression like `2+3` and push Enter key, then the answer `5` appears.
53
+ 4. Type `quit`, `q` or `exit`, then the program will finish.
54
+ 5. You can also use it as a one line calculator like `$ calc "10*20+30"`.
55
+
56
+ ### feature
57
+
58
+ - Operatores: `+`, `-`, `*`, `/`, `**`(power), `-`(unary minus), `(` and `)`
59
+ - Functions: `sqrt`, `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `exp`, `ln`, `log`, `abs`, `fact`, `floor`, `ceil` and `round`.
60
+ - The special variable `v` keeps the result of the previous calculation.
61
+ - Variable can be used.
62
+ It is a string of alphabets without the keywords above.
63
+ It can be used in any place in the expression.
64
+ `variable_name = expression` is the syntax to define the variable.
65
+ A defined variable can be used in an expression.
66
+
67
+ ### Functions
68
+
69
+ - `sqrt`: Square root. `sqrt(4) => 2`
70
+ - `sin`: `sin(PI) => 1.2246467991473532e-16` It is well known that sin(PI) is zero. But Float always includes error.
71
+ - `cos`: `cos(PI) => -1`
72
+ - `tan`: `tan(PI/4) => 0.9999999999999999` The answer includes error. The exact value is 1.
73
+ - `asin`: Inverse of the sine function. `asin(1) => 1.5707963267948966` This is PI/2
74
+ - `acos`: Inverse of the cosine function. `acos(1) => 0`
75
+ - `atan`: Inverse of the tangent function. `atan(1) => 0.7853981633974483` This is PI/4
76
+ - `exp`: Exponential function. `exp(n)` means `e` raised to the power of n. `exp(1) => 2.718281828459045` It is E.
77
+ - `ln`: Natural logarithm. `ln(E) => 1`
78
+ - `log`: Common logarithm or decimal logarithm. The base is 10. `log(10) => 1`
79
+ - `abs`: Absolute value. `abs(-10) =>10`
80
+ - `fact`: Factorial. `fact(10) => 3628800` The argument must be non-negative. If it isn't an integer, it will be rounded down to an integer. It must be less than 171 because of the limitation of Float.
81
+ - `floor`: Floor function. `floor(3.45) => 3`
82
+ - `ceil`: Ceiling function. `ceil(3.45) => 4`
83
+ - `round`: Rounding function. `round(3.45,1) => 3.5, round(-3.45,1) => -3.5` The rounding is done away from zero if the argument is at the middle of two candidates.
84
+
85
+ ### Racc library
86
+
87
+ Racc is a Ruby standard library.
88
+ It is a parser generator like Yacc, which is a famous parser generator made for the Unix Operating system.
89
+ Calc uses Racc.
90
+ It makes the library file `lib/calc/calc.rb` with Racc.
91
+ The source file is `racc/calc.y`.
92
+ You can compile it by typing:
93
+
94
+ ```
95
+ $ rake
96
+ ```
97
+
98
+ See `racc/doc.md` for details.
99
+
100
+ ### Rakefile
101
+
102
+ You can do the following
103
+
104
+ - `rake`: Compile `racc/calc.y` and create/update `lib/calc/calc.rb`.
105
+ - `rake rdoc`: Create documents under `docs` directory.
106
+ - `rake test`: Run test programs under `test` directory.
107
+
108
+ ### Using Calc as a library
109
+
110
+ You can use Calc as a library in your Ruby program.
111
+
112
+ - First, require 'calc'.
113
+ - Create an instance of the class `Calc`. Let the instance name be 'c'.
114
+ - Call `c.run(s)` where `s` is a string of an expression. Then it returns the value of the expression.
115
+ For example, `c.run("1+2")` returns 3.0.
116
+
117
+ The following is a sample code.
118
+
119
+ ```ruby
120
+ require 'calc'
121
+
122
+ c = Calc.new
123
+ s = "1+2"
124
+ print "#{c.run(s)}\n" #=> 3.0
125
+ ```
126
+
127
+ ### License
128
+
129
+ GPL ver 3 or later.
130
+ See [License.md](License.md) for details.
131
+
132
+ ### これは何のプログラム?
133
+
134
+ Rubyプログラム`calc.rb`は関数電卓です。
135
+ コマンドラインから次のように起動できます。
136
+
137
+ ```
138
+ $ calc 2*3+4*5
139
+ 26
140
+ $ calc
141
+ calc > 0.1-0.2
142
+ -0.1
143
+ calc > sin(PI/6)
144
+ 0.49999999999999994 # 実数計算では誤差が発生します
145
+ calc > quit
146
+ $
147
+ ```
148
+
149
+ ### 動作条件
150
+
151
+ - Linux OS
152
+ - Ruby バージョン3.1.2以降(おそらく不利バージョンでも動作します)
153
+
154
+ ### インストール
155
+
156
+ 2通りのインストール方法があります。
157
+
158
+ 1. 'Code'ボタンをクリックし、現れた小さなダイアログの'Download ZIP'をクリックする
159
+ 2. ダウンロードしたZipファイルを解凍する。これにより新しく「calc」ディレクトリが作られ、その中にすべてのファイルが収められる
160
+ 3. 「gem build s_calc」を実行することにより、gemファイル「s_calc-X.X.X.gem」が作られる。「X.X.X」の部分はバージョン番号で、例えば「0.1.4」のような数字である
161
+ 4. 「gem install s_calc-X.X.X.gem」とタイプし、gemをインストールする
162
+
163
+ もっと簡単なインストール方法は、RubyGemsからインストールすることです。
164
+ 次のようにタイプするだけでgemをダウンロードしインストールします。
165
+
166
+ ```
167
+ $ gem install s_calc
168
+ ```
169
+
170
+ コマンド名とGitHubのレポジトリ名が`calc`であるのに対して、gem名は`s_calc`であることに注意してください。
171
+ これは、RubyGemsには既に`calc`という名前のgemが存在しており、異なるgem名が必要だったためです。
172
+
173
+ ### 使い方
174
+
175
+ 1. 解凍したフォルダで端末(コマンドライン)を起動し、「calc」と入力する
176
+ 2. プロンプト「calc >」が現れる
177
+ 3. 式(例えば2+3)と入力し、エンターキーを押すと、答え「5」が表示される
178
+ 4. 「quit」または「q」または「exit」とタイプするとプログラムは終了する
179
+ 5. 引数を付けて一行計算アプリとしても使える。(例)`$ calc "10*20+30"`
180
+
181
+ ### 特長
182
+
183
+ - 次の演算記号が使える。`+`, `-`, `*`, `/`, `**`(累乗), `-`(単項マイナス), `(`, `)`
184
+ - 関数: `sqrt`, `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `exp`, `ln`, `log`, `abs`, `fact`, `floor`, `ceil` and `round`.
185
+ - 変数が使える
186
+ - calcは直前の計算結果を記憶しており、変数`v` でその値を参照できる
187
+ - 変数はアルファベットからなる文字列で、上記のキーワードを除く。
188
+ `変数名 = 式` により、変数に値を代入することができる。
189
+ 定義された変数は、式の中で使うことができる
190
+
191
+ ### 関数
192
+
193
+ - `sqrt`: 平方根。 `sqrt(4) => 2`
194
+ - `sin`: `sin(PI) => 1.2246467991473532e-16` sin(PI)はゼロですが、浮動小数点の計算は常に誤差が生じます
195
+ - `cos`: `cos(PI) => -1`
196
+ - `tan`: `tan(PI/4) => 0.9999999999999999` 答えは誤差を含んでいます。正確には1になります
197
+ - `asin`: サインの逆三角関数。`asin(1) => 1.5707963267948966` これはPI/2です
198
+ - `acos`: コサインの逆三角関数。`acos(1) => 0`
199
+ - `atan`: タンジェントの逆三角関数。`atan(1) => 0.7853981633974483` これはPI/4です
200
+ - `exp`: 指数関数。 `exp(n)`は`e`のn乗。`exp(1) => 2.718281828459045` これはEです
201
+ - `ln`: 自然対数。底がeの対数。`ln(E) => 1`
202
+ - `log`: 常用対数。底が10の対数。`log(10) => 1`
203
+ - `abs`: 絶対値。`abs(-10) =>10`
204
+ - `fact`: 階乗。`fact(10) => 3628800` 引数はゼロ以上。引数が整数でなければ、切り捨てて整数に直す。引数は171より小さくなければならない。答えがFloatの最大値を越えないように制限するため。
205
+ - `floor`: フロアー関数。小数点以下を切り捨て。`floor(3.45) => 3`
206
+ - `ceil`: シーリング関数。小数点以下を切り上げ。`ceil(3.45) => 4`
207
+ - `round`: 四捨五入関数。`round(3.45,1) => 3.5, round(-3.45,1) => -3.5` 丸める桁が5である場合は、ゼロから遠い方に丸める。
208
+
209
+ ### Racc
210
+
211
+ RaccはRubyの標準ライブラリーです。
212
+ パーサー・ジェネレーターと呼ばれ、Unixオペレーティングシステム上の有名なYaccに似ています。
213
+ CalcはRaccを使って`lib/calc/calc.rb`を生成しています。
214
+ そのソース・ファイルは`racc/calc.y`です。
215
+ コンパイルは次のようにタイプするだけでできます。
216
+
217
+ ```
218
+ $ rake
219
+ ```
220
+
221
+ ドキュメント `racc/doc.md`を参照してください。
222
+
223
+ ### Rakefile
224
+
225
+ 次のことができます。
226
+
227
+ - `rake`: `racc/calc.y`をコンパイルして`lib/calc/calc.rb`を生成する
228
+ - `rake rdoc`: `docs`ディレクトリ以下にドキュメントを生成する
229
+ - `rake test`: `test`ディレクトリの下にあるテストプログラムを実行する
230
+
231
+ ### Calcをライブラリとして使う
232
+
233
+ CalcをライブラリとしてRubyプログラムの中で使うことができます。
234
+
235
+ - まず、'calc'をrequireする
236
+ - `Calc`クラスのインスタンスを生成する。仮にその名前を`c`とする
237
+ - 数式を表す文字列を`s`とすると、`c.run(s)`はその数式を計算した値を返す
238
+ 例えば、`c.run("1+2")`は3.0を返す。
239
+
240
+ 以下に簡単なサンプルコードを示します。
241
+
242
+ ```ruby
243
+ require 'calc'
244
+
245
+ c = Calc.new
246
+ s = "1+2"
247
+ print "#{c.run(s)}\n" #=> 3.0
248
+ ```
249
+
250
+ ### ライセンス
251
+
252
+ Copyright (C) 2022,2023 ToshioCP (関谷 敏雄)
253
+
254
+ このプログラムは、フリーソフトウェア財団によって発行された「GNU一般公衆利用許諾書」(バージョン3か、希望によってはそれ以降のバージョンのうちどれか)の定める条件の下で再頒布または改変することができる。
255
+
256
+ このプログラムは有用であることを願って頒布されますが、*全くの無保証* です。商業可能性の保証や特定の目的への適合性は、言外に示されたものも含め全く存在しません。
257
+ 詳しくは[GNU 一般公衆利用許諾書(英語)](https://www.gnu.org/licenses/gpl-3.0.en.html)、またはその日本語訳[GNU 一般公衆利用許諾書の日本語訳](https://gpl.mhatta.org/gpl.ja.html)をご覧ください。
258
+
259
+ なお、ライセンスを英語で記した[License.md](License.md)もあります。
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s_calc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshio Sekiya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-17 00:00:00.000000000 Z
11
+ date: 2023-10-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: CUI Scientific calculator
14
14
  email: lxboyjp@gmail.com
@@ -17,6 +17,7 @@ executables:
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - README.md
20
21
  - bin/calc
21
22
  - lib/calc.rb
22
23
  - lib/calc/calc.rb